swagger2openapi
Advanced tools
Comparing version 1.1.12 to 1.1.13
41
index.js
@@ -63,2 +63,5 @@ 'use strict'; | ||
var consumes = ((op && op.consumes)||[]).concat(openapi.consumes||[]); | ||
consumes = consumes.filter(common.uniqueOnly); | ||
if (param["$ref"]) { | ||
@@ -126,10 +129,17 @@ param["$ref"] = param["$ref"].replace('#/parameters/','#/components/parameters/'); | ||
result.content = {}; | ||
result.content["application/x-www-form-urlencoded"] = {}; | ||
var contentType = 'application/x-www-form-urlencoded'; | ||
if ((consumes.length) && (consumes[0] == 'multipart/form-data')) { | ||
contentType = 'multipart/form-data'; | ||
} | ||
result.content[contentType] = {}; | ||
if (param.schema) { | ||
result.content["application/x-www-form-urlencoded"].schema = param.schema; | ||
result.content[contentType].schema = param.schema; | ||
} | ||
else { | ||
result.content["application/x-www-form-urlencoded"].properties = {}; | ||
result.content["application/x-www-form-urlencoded"].properties[param.name] = {}; | ||
var target = result.content["application/x-www-form-urlencoded"].properties[param.name]; | ||
result.content[contentType].schema = {}; | ||
result.content[contentType].schema.type = 'object'; | ||
result.content[contentType].schema.properties = {}; | ||
result.content[contentType].schema.properties[param.name] = {}; | ||
var target = result.content[contentType].schema.properties[param.name]; | ||
if (param.description) target.description = param.description; | ||
@@ -172,4 +182,2 @@ if (param.type) target.type = param.type; | ||
result.content = {}; | ||
var consumes = ((op && op.consumes)||[]).concat(openapi.consumes||[]); | ||
consumes = consumes.filter(common.uniqueOnly); | ||
@@ -187,4 +195,2 @@ if (!consumes.length) { | ||
// TODO multipart/formData etc | ||
if (Object.keys(result).length > 0) { | ||
@@ -200,6 +206,11 @@ param["x-s2o-delete"] = true; | ||
op.requestBody = Object.assign({},op.requestBody); | ||
if ((op.requestBody.content && op.requestBody.content["application/x-www-form-urlencoded"]) | ||
if ((op.requestBody.content && op.requestBody.content["multipart/form-data"]) | ||
&& (result.content["multipart/form-data"])) { | ||
op.requestBody.content["multipart/form-data"].schema.properties = | ||
Object.assign(op.requestBody.content["multipart/form-data"].schema.properties,result.content["multipart/form-data"].schema.properties); | ||
} | ||
else if ((op.requestBody.content && op.requestBody.content["application/x-www-form-urlencoded"]) | ||
&& (result.content["application/x-www-form-urlencoded"])) { | ||
op.requestBody.content["application/x-www-form-urlencoded"].properties = | ||
Object.assign(op.requestBody.content["application/x-www-form-urlencoded"].properties,result.content["application/x-www-form-urlencoded"].properties); | ||
op.requestBody.content["application/x-www-form-urlencoded"].schema.properties = | ||
Object.assign(op.requestBody.content["application/x-www-form-urlencoded"].schema.properties,result.content["application/x-www-form-urlencoded"].schema.properties); | ||
} | ||
@@ -265,3 +276,2 @@ else { | ||
op.responses = {default: defaultResp}; | ||
} | ||
@@ -274,3 +284,3 @@ for (var r in op.responses) { | ||
var produces = (op.produces||[]).concat(openapi.produces||[]).filter(common.uniqueOnly); | ||
if (!produces.length) produces.push('*'); | ||
if (!produces.length) produces.push('*/*'); // TODO verify default | ||
response.content = {}; | ||
@@ -280,2 +290,5 @@ for (var mimetype of produces) { | ||
response.content[mimetype].schema = common.clone(response.schema); | ||
if (response.content[mimetype].schema.type == 'file') { | ||
delete response.content[mimetype].schema; | ||
} | ||
} | ||
@@ -282,0 +295,0 @@ delete response.schema; |
{ | ||
"name": "swagger2openapi", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "Convert Swagger 2.0 specifications to OpenApi 3.0", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# swagger2openapi | ||
![logo](https://github.com/Mermade/swagger2openapi/blob/master/docs/logo.png?raw=true) | ||
![Build](https://img.shields.io/travis/Mermade/swagger2openapi.svg) [![Tested on APIs.guru](https://api.apis.guru/badges/tested_on.svg)](https://APIs.guru) [![Tested on Mermade OpenAPIs](https://mermade.github.io/openapi_optimise/tested.svg)](https://github.com/mermade/openapi_specifications) | ||
@@ -46,3 +48,3 @@ [![Known Vulnerabilities](https://snyk.io/test/npm/swagger2openapi/badge.svg)](https://snyk.io/test/npm/swagger2openapi) | ||
x-ms-odata|[Microsoft](https://github.com/Azure/autorest/tree/master/docs/extensions)|References to `#/definitions/` are updated to `#/components/schemas` | ||
x-ms-parameterized-host|[Microsoft](https://github.com/Azure/autorest/tree/master/docs/extensions)|**TODO** | ||
x-ms-parameterized-host|[Microsoft](https://github.com/Azure/autorest/tree/master/docs/extensions)|**TODO** Not seen in the wild | ||
x-anyOf|[Open Nitro Project](https://github.com/mermade/bbcparse)|Within schemas, converted to `anyOf` | ||
@@ -49,0 +51,0 @@ x-oneOf|[Open Nitro Project](https://github.com/mermade/bbcparse)|Within schemas, converted to `oneOf` |
@@ -16,2 +16,15 @@ var url = require('url'); | ||
function checkServers(servers) { | ||
for (var server of servers) { | ||
if (server.url) { // TODO may change to REQUIRED in RC1 | ||
validateUrl(server.url).should.not.throw(); | ||
} | ||
if (server.variables) { | ||
for (var v in server.variables) { | ||
server.variables[v].should.have.key('default'); | ||
} | ||
} | ||
} | ||
} | ||
function checkParam(param,openapi){ | ||
@@ -42,4 +55,12 @@ if (param.$ref) { | ||
} | ||
else if (o == 'summary') { | ||
// nop | ||
} | ||
else if (o == 'description') { | ||
// nop | ||
} | ||
else if (o == 'servers') { | ||
checkServers(op); // won't be here in converted specs | ||
} | ||
else { | ||
// check for description etc or that we are in get,put,post etc | ||
op.should.have.property('responses'); | ||
@@ -53,2 +74,5 @@ op.responses.should.not.be.empty(); | ||
} | ||
if (op.servers) { | ||
checkServers(op.servers); | ||
} | ||
} | ||
@@ -68,12 +92,3 @@ } | ||
if (openapi.servers) { | ||
for (var server of openapi.servers) { | ||
if (server.url) { // TODO may change to REQUIRED in RC1 | ||
validateUrl(server.url).should.not.throw(); | ||
} | ||
if (server.variables) { | ||
for (var v in server.variables) { | ||
server.variables[v].should.have.key('default'); | ||
} | ||
} | ||
} | ||
checkServers(openapi.servers); | ||
} | ||
@@ -115,3 +130,3 @@ openapi.should.have.key('paths'); | ||
if (scheme.type == 'oauth2') { | ||
scheme.should.have.property('flow'); | ||
scheme.should.have.property('flow'); // TODO may change to flows in RC1 | ||
for (var f in scheme.flow) { | ||
@@ -138,3 +153,3 @@ var flow = scheme.flow[f]; | ||
openapi.openapi.startsWith('3.0.').should.be.ok(); | ||
should.ok(openapi.openapi.startsWith('3.0.'),'Must be an OpenAPI 3.0.x document'); | ||
@@ -141,0 +156,0 @@ common.recurse(openapi,{},function(obj,key,parent){ |
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
77219
13
906
77