@@ -7,7 +7,9 @@ var expect = require('chai').expect,
7
7
VALID_OPENAPI_PATH = '../data/valid_openapi' ,
8
8
INVALID_OPENAPI_PATH = '../data/invalid_openapi' ,
9
9
SWAGGER_20_FOLDER_YAML = '../data/valid_swagger/yaml/' ,
10
- SWAGGER_20_FOLDER_JSON = '../data/valid_swagger/json/' ;
10
+ SWAGGER_20_FOLDER_JSON = '../data/valid_swagger/json/' ,
11
+ VALID_OPENAPI_3_1_FOLDER_JSON = '../data/valid_openapi31X/json' ,
12
+ VALID_OPENAPI_3_1_FOLDER_YAML = '../data/valid_openapi31X/yaml' ;
11
13
12
14
describe ( 'CONVERT FUNCTION TESTS ' , function ( ) {
13
15
// these two covers remaining part of util.js
@@ -2011,6 +2013,109 @@ describe('INTERFACE FUNCTION TESTS ', function () {
2011
2013
} ) ;
2012
2014
} ) ;
2013
2015
} ) ;
2016
+
2017
+ describe ( 'The converter must identify valid OA3 specification' , function ( ) {
2018
+ var pathPrefix = VALID_OPENAPI_PATH ,
2019
+ sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ,
2020
+ oa31Files = [ 'issue#479_2.yaml' , 'issue#10229.json' , 'query_param_with_enum_resolve_as_example.json' ] ;
2021
+
2022
+ sampleSpecs . map ( ( sample ) => {
2023
+ if ( ! oa31Files . includes ( sample ) ) {
2024
+ var specPath = path . join ( __dirname , pathPrefix , sample ) ;
2025
+
2026
+ it ( specPath + ' is valid ' , function ( done ) {
2027
+ var openapi = fs . readFileSync ( specPath , 'utf8' ) ,
2028
+ validationResult = Converter . validate ( { type : 'string' , data : openapi } ) ;
2029
+
2030
+ expect ( validationResult . result ) . to . equal ( true ) ;
2031
+ expect ( validationResult . specificationVersion ) . to . equal ( '3.0.x' ) ;
2032
+ done ( ) ;
2033
+ } ) ;
2034
+ }
2035
+ } ) ;
2036
+ } ) ;
2037
+
2038
+ describe ( 'The converter must identify valid OA2 specifications - JSON' , function ( ) {
2039
+ var pathPrefix = SWAGGER_20_FOLDER_JSON ,
2040
+ sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ;
2041
+
2042
+ sampleSpecs . map ( ( sample ) => {
2043
+ var specPath = path . join ( __dirname , pathPrefix , sample ) ;
2044
+
2045
+ it ( specPath + ' is valid ' , function ( done ) {
2046
+ var openapi = fs . readFileSync ( specPath , 'utf8' ) ,
2047
+ validationResult = Converter . validate ( { type : 'string' , data : openapi } ) ;
2048
+
2049
+ expect ( validationResult . result ) . to . equal ( true ) ;
2050
+ expect ( validationResult . specificationVersion ) . to . equal ( '2.0' ) ;
2051
+ done ( ) ;
2052
+ } ) ;
2053
+ } ) ;
2054
+ } ) ;
2055
+
2056
+ describe ( 'The converter must identify valid OA3.1 specifications - JSON' , function ( ) {
2057
+ var pathPrefix = VALID_OPENAPI_3_1_FOLDER_JSON ,
2058
+ sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ,
2059
+ oa30Files = [ 'deprecated_property.json' ] ,
2060
+ incorrectOA31Files = [ 'webhooks.json' ] ,
2061
+ filesToIgnore = oa30Files + incorrectOA31Files ;
2062
+
2063
+
2064
+ sampleSpecs . map ( ( sample ) => {
2065
+ if ( ! filesToIgnore . includes ( sample ) ) {
2066
+ var specPath = path . join ( __dirname , pathPrefix , sample ) ;
2067
+
2068
+ it ( specPath + ' is valid ' , function ( done ) {
2069
+ var openapi = fs . readFileSync ( specPath , 'utf8' ) ,
2070
+ validationResult = Converter . validate ( { type : 'string' , data : openapi } ) ;
2071
+
2072
+ expect ( validationResult . result ) . to . equal ( true ) ;
2073
+ expect ( validationResult . specificationVersion ) . to . equal ( '3.1.x' ) ;
2074
+ done ( ) ;
2075
+ } ) ;
2076
+ }
2077
+ } ) ;
2078
+ } ) ;
2079
+
2080
+ describe ( 'The converter must identify valid OA3.1 specifications - YAML' , function ( ) {
2081
+ var pathPrefix = VALID_OPENAPI_3_1_FOLDER_YAML ,
2082
+ sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ,
2083
+ invalidOA31Files = [ 'marketPayNotificationService4.yaml' ] ;
2084
+
2085
+ sampleSpecs . map ( ( sample ) => {
2086
+ if ( ! invalidOA31Files . includes ( sample ) ) {
2087
+ var specPath = path . join ( __dirname , pathPrefix , sample ) ;
2088
+
2089
+ it ( specPath + ' is valid ' , function ( done ) {
2090
+ var openapi = fs . readFileSync ( specPath , 'utf8' ) ,
2091
+ validationResult = Converter . validate ( { type : 'string' , data : openapi } ) ;
2092
+
2093
+ expect ( validationResult . result ) . to . equal ( true ) ;
2094
+ expect ( validationResult . specificationVersion ) . to . equal ( '3.1.x' ) ;
2095
+ done ( ) ;
2096
+ } ) ;
2097
+ }
2098
+ } ) ;
2099
+ } ) ;
2100
+
2101
+ describe ( 'The converter must identify valid OA2 specifications - YAML' , function ( ) {
2102
+ var pathPrefix = SWAGGER_20_FOLDER_YAML ,
2103
+ sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ;
2104
+
2105
+ sampleSpecs . map ( ( sample ) => {
2106
+ var specPath = path . join ( __dirname , pathPrefix , sample ) ;
2107
+
2108
+ it ( specPath + ' is valid ' , function ( done ) {
2109
+ var openapi = fs . readFileSync ( specPath , 'utf8' ) ,
2110
+ validationResult = Converter . validate ( { type : 'string' , data : openapi } ) ;
2111
+
2112
+ expect ( validationResult . result ) . to . equal ( true ) ;
2113
+ expect ( validationResult . specificationVersion ) . to . equal ( '2.0' ) ;
2114
+ done ( ) ;
2115
+ } ) ;
2116
+ } ) ;
2117
+ } ) ;
2118
+
2014
2119
describe ( 'The converter must identify invalid specifications' , function ( ) {
2015
2120
var pathPrefix = INVALID_OPENAPI_PATH ,
2016
2121
sampleSpecs = fs . readdirSync ( path . join ( __dirname , pathPrefix ) ) ;
0 commit comments