Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add transitive conversion to Open API 3.0 via Swagger 2.0 #139

Merged
merged 3 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,741 changes: 10,781 additions & 2,960 deletions dist/api-spec-converter.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions lib/base_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,13 @@ BaseFormat.prototype.convertTo = function(format, callback) {
});
}).asCallback(callback);
}

BaseFormat.prototype.convertTransitive = function(intermediaries) {
let prom = Promise.resolve(this);
intermediaries.forEach(intermediary => {
prom = prom.then(spec => {
return spec.convertTo(intermediary);
})
});
return prom.then(spec => spec.spec);
}
3 changes: 3 additions & 0 deletions lib/formats/api_blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var APIBlueprint = module.exports = function() {
this.converters.swagger_2 = Promise.method(apibp => {
return BPToSwagger.convertParsed(apibp.spec);
});

this.converters.openapi_3 =
Promise.method(apibp => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(APIBlueprint, BaseFormat);
Expand Down
3 changes: 3 additions & 0 deletions lib/formats/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var Google = module.exports = function() {

this.converters.swagger_2 =
Promise.method(google => Google2Swagger.convert(google.spec));

this.converters.openapi_3 =
Promise.method(google => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(Google, BaseFormat);
Expand Down
3 changes: 3 additions & 0 deletions lib/formats/io_docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var IODocs = module.exports = function() {
this.type = 'io_docs';
this.converters.swagger_2 =
Promise.method(iodocs => convertToSwagger(iodocs.spec));

this.converters.openapi_3 =
Promise.method(iodocs => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(IODocs, BaseFormat);
Expand Down
3 changes: 3 additions & 0 deletions lib/formats/raml.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var Raml = module.exports = function() {

this.converters.swagger_2 =
Promise.method(raml => Raml2Swagger.convert(raml.spec));

this.converters.openapi_3 =
Promise.method(raml => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(Raml, BaseFormat);
Expand Down
3 changes: 3 additions & 0 deletions lib/formats/swagger_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var Swagger1 = module.exports = function() {
swagger2.info.title = swagger2.host;
return swagger2;
});

this.converters.openapi_3 =
Promise.method(swagger1 => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(Swagger1, BaseFormat);
Expand Down
3 changes: 3 additions & 0 deletions lib/formats/wadl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ var WADL = module.exports = function() {

this.converters.swagger_2 =
Promise.method(wadl => convertToSwagger(wadl.spec));

this.converters.openapi_3 =
Promise.method(swagger1 => this.convertTransitive(['swagger_2', 'openapi_3']));
}

Inherits(WADL, BaseFormat);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]
},
"dependencies": {
"apib2swagger": "^0.6.2",
"apib2swagger": "^1.0.0",
"bluebird": "^3.5.0",
"commander": "^2.9.0",
"composite-error": "^0.1.1",
Expand All @@ -69,7 +69,7 @@
"raml-to-swagger": "^1.1.0",
"request": "^2.81.0",
"swagger-converter": "^1.4.1",
"swagger2openapi": "^2.9.2",
"swagger2openapi": "2.9.2",
"sway": "^1.0.0",
"traverse": "^0.6.6",
"urijs": "^1.18.10",
Expand Down
115 changes: 115 additions & 0 deletions test/output/openapi_3/OpenStack_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"info": {
"title": "",
"version": ""
},
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"operationId": "listVersions-v2",
"responses": {
"200": {
"description": "Successful Response"
}
}
},
"parameters": []
},
"/v2.0": {
"get": {
"operationId": "showVersionInfo-v2.0",
"responses": {
"200": {
"description": "Successful Response"
}
}
},
"parameters": []
},
"/v2.0/extensions": {
"get": {
"operationId": "listExtensions-v2",
"responses": {
"200": {
"description": "Successful Response"
}
}
},
"parameters": []
},
"/v2.0/extensions/{alias}": {
"get": {
"operationId": "showExtension-v2",
"responses": {
"200": {
"description": "Successful Response"
}
}
},
"parameters": [
{
"in": "path",
"name": "alias",
"required": true,
"schema": {
"type": "string"
}
}
]
},
"/v2.0/tenants": {
"get": {
"operationId": "listTenants",
"responses": {
"200": {
"description": "Successful Response"
}
}
},
"parameters": [
{
"in": "header",
"name": "X-Auth-Token",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "limit",
"required": false,
"schema": {
"format": "int32",
"type": "integer"
}
},
{
"in": "query",
"name": "marker",
"required": false,
"schema": {
"type": "string"
}
}
]
},
"/v2.0/tokens": {
"parameters": [],
"post": {
"operationId": "authenticate-v2.0",
"responses": {
"200": {
"description": "Successful Response"
}
}
}
}
},
"servers": [
{
"url": "http://localhost:35357/"
}
]
}
100 changes: 100 additions & 0 deletions test/output/openapi_3/XKCD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"components": {
"schemas": {
"comic": {
"properties": {
"alt": {
"type": "string"
},
"day": {
"type": "string"
},
"img": {
"type": "string"
},
"link": {
"type": "string"
},
"month": {
"type": "string"
},
"news": {
"type": "string"
},
"num": {
"type": "number"
},
"safe_title": {
"type": "string"
},
"title": {
"type": "string"
},
"transcript": {
"type": "string"
},
"year": {
"type": "string"
}
},
"type": "object"
}
}
},
"info": {
"title": "XKCD",
"version": ""
},
"openapi": "3.0.0",
"paths": {
"/info.0.json": {
"get": {
"description": "Fetch current comic and metadata.\n",
"responses": {
"200": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/comic"
}
}
},
"description": "OK"
}
}
}
},
"/{comicId}/info.0.json": {
"get": {
"description": "Fetch comics and metadata by comic id.\n",
"parameters": [
{
"in": "path",
"name": "comicId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/comic"
}
}
},
"description": "OK"
}
}
}
}
},
"servers": [
{
"url": "http://xkcd.com/"
}
]
}
Loading