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

Fix error when response does not have a content-type header #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 11 additions & 9 deletions lib/execute/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,20 @@ var getApiRuntimeInfo = function (swaggerSpec, urlObj, options, update, callback
if (swaggerSpec.paths[apiPath][pathMethod] == null) {
swaggerSpec.paths[apiPath][pathMethod] = {};
}
swaggerSpec.paths[apiPath][pathMethod]["produces"] = new Array();
swaggerSpec.paths[apiPath][pathMethod]["produces"].push(response.headers['content-type']);
swaggerSpec.paths[apiPath][pathMethod]["responses"] = {};
swaggerSpec.paths[apiPath][pathMethod]["responses"][response.statusCode] = {};
swaggerSpec.paths[apiPath][pathMethod]["responses"][response.statusCode].description = HTTPStatus[response.statusCode];
if (response.headers['content-type'].indexOf('application/json') > -1 && body != '') {
var schemaObj = jsonSchemaGenerator(JSON.parse(body));
delete schemaObj.$schema;
// bug with json scheme generator - work around
// For more details, https://github.com/krg7880/json-schema-generator/issues/13
scan(schemaObj);
swaggerSpec.paths[apiPath][pathMethod]["responses"][response.statusCode].schema = schemaObj;
swaggerSpec.paths[apiPath][pathMethod]["produces"] = new Array();
if (response.headers['content-type']) {
swaggerSpec.paths[apiPath][pathMethod]["produces"].push(response.headers['content-type']);
if (response.headers['content-type'].indexOf('application/json') > -1 && body != '') {
var schemaObj = jsonSchemaGenerator(JSON.parse(body));
delete schemaObj.$schema;
// bug with json scheme generator - work around
// For more details, https://github.com/krg7880/json-schema-generator/issues/13
scan(schemaObj);
swaggerSpec.paths[apiPath][pathMethod]["responses"][response.statusCode].schema = schemaObj;
}
}
swaggerSpec.paths[apiPath][pathMethod].security = new Array();
if (response.request.headers.authorization && response.request.headers.authorization.startsWith('Basic')) {
Expand Down