swagger2openapi
Advanced tools
Comparing version 1.1.14 to 1.1.15
@@ -39,2 +39,6 @@ 'use strict'; | ||
function getVersion() { | ||
return require('./package.json').version; | ||
} | ||
module.exports = { | ||
@@ -46,4 +50,5 @@ | ||
sha256 : sha256, | ||
forceFailure : forceFailure | ||
forceFailure : forceFailure, | ||
getVersion : getVersion | ||
}; |
{ | ||
"name": "swagger2openapi", | ||
"version": "1.1.14", | ||
"version": "1.1.15", | ||
"description": "Convert Swagger 2.0 specifications to OpenApi 3.0", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -24,10 +24,10 @@ # swagger2openapi | ||
```` | ||
````javascript | ||
var converter = require('swagger2openapi'); | ||
var options = {}; | ||
//options.debug = true; // sets various x-s2o- properties for debugging | ||
//options.debug = true; // sets various x-s2o- debugging properties | ||
var openapi = converter.convert(swagger, options); | ||
```` | ||
```` | ||
````javascript | ||
var validator = require('swagger2openapi/validate.js'); | ||
@@ -63,3 +63,3 @@ var options = {}; | ||
```` | ||
````shell | ||
node testRunner {path-to-APIs|single-file} | ||
@@ -66,0 +66,0 @@ ```` |
@@ -62,3 +62,3 @@ 'use strict'; | ||
validator.validate(result); | ||
validator.validate(result,options); | ||
@@ -69,3 +69,3 @@ resultStr = yaml.safeDump(result); // should be representable safely in yaml | ||
console.log(green+' %s %s',src.info.title,src.info.version); | ||
console.log(' %s',src.swagger ? src.host : src.servers[0].url); | ||
console.log(' %s',src.swagger ? src.host : (src.servers && src.servers.length ? src.servers[0].url : '')); | ||
result = true; | ||
@@ -72,0 +72,0 @@ } |
@@ -29,3 +29,3 @@ var url = require('url'); | ||
function checkParam(param,openapi){ | ||
function checkParam(param,openapi,options){ | ||
if (param.$ref) { | ||
@@ -36,15 +36,16 @@ param = jptr.jptr(openapi,param.$ref); | ||
param.should.have.property('in'); | ||
if (options.verbose) console.log('p:'+param.name+' '+param.in); | ||
if (param.in == 'path') { | ||
param.should.have.property('required'); | ||
param.required.should.be.exactly(true); | ||
param.required.should.be.exactly(true,'Path parameters must have an explicit required:true'); | ||
} | ||
param.should.not.have.property('items'); | ||
param.should.not.have.property('collectionFormat'); | ||
if (param.type) param.type.should.not.be.exactly('file'); | ||
param.in.should.not.be.exactly('body'); | ||
param.in.should.not.be.exactly('formData'); | ||
if (param.type) param.type.should.not.be.exactly('file','Parameter type file is no-longer valid'); | ||
param.in.should.not.be.exactly('body','Parameter type body is no-longer valid'); | ||
param.in.should.not.be.exactly('formData','Parameter type formData is no-longer valid'); | ||
return true; | ||
} | ||
function checkPathItem(pathItem,openapi) { | ||
function checkPathItem(pathItem,openapi,options) { | ||
for (var o in pathItem) { | ||
@@ -54,3 +55,3 @@ var op = pathItem[o]; | ||
for (var param of pathItem.parameters) { | ||
checkParam(param,openapi); | ||
checkParam(param,openapi,options); | ||
} | ||
@@ -70,3 +71,4 @@ } | ||
} | ||
else { | ||
else { | ||
if (options.verbose) console.log('o:'+o); | ||
op.should.have.property('responses'); | ||
@@ -76,2 +78,7 @@ op.responses.should.not.be.empty(); | ||
op.should.not.have.property('produces'); | ||
if (op.parameters) { | ||
for (var param of op.parameters) { | ||
checkParam(param,openapi,options); | ||
} | ||
} | ||
if (op.externalDocs) { | ||
@@ -126,3 +133,3 @@ op.externalDocs.should.have.key('url'); | ||
scheme.should.have.property('type'); | ||
scheme.type.should.not.be.exactly('basic'); | ||
scheme.type.should.not.be.exactly('basic','Security scheme basic should be http with scheme basic'); | ||
if (scheme.type == 'http') { | ||
@@ -188,3 +195,3 @@ scheme.should.have.property('scheme'); | ||
if ((key === '$ref') && (typeof obj[key] === 'string')) { | ||
should(obj[key].indexOf('#/definitions/')).be.exactly(-1); | ||
should(obj[key].indexOf('#/definitions/')).be.exactly(-1,'Reference to #/definitions'); | ||
} | ||
@@ -195,11 +202,13 @@ }); | ||
for (var p in openapi.components.parameters) { | ||
checkParam(openapi.components.parameters[p],openapi); | ||
checkParam(openapi.components.parameters[p],openapi,options); | ||
} | ||
} | ||
for (var p in openapi.paths) { | ||
checkPathItem(openapi.paths[p],openapi); | ||
if (options.verbose) console.log(p); | ||
checkPathItem(openapi.paths[p],openapi,options); | ||
} | ||
if (openapi["x-ms-paths"]) { | ||
for (var p in openapi["x-ms-paths"]) { | ||
checkPathItem(openapi["x-ms-paths"][p],openapi); | ||
if (options.verbose) console.log(p); | ||
checkPathItem(openapi["x-ms-paths"][p],openapi,options); | ||
} | ||
@@ -206,0 +215,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78866
949