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

Fixes to work with swagger in node.js. No null schema reference and remove required field if empty #36

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
37 changes: 29 additions & 8 deletions lib/apidocToSwagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,28 @@ function createPostPushPutOutput(verbs, definitions, pathKeys) {
});

params = params.concat(pathParams);
var required = verbs.parameter && verbs.parameter.fields &&
verbs.parameter.fields.Parameter && verbs.parameter.fields.Parameter.length > 0;
var required = verbs.parameter && verbs.parameter.fields && verbs.parameter.fields.Parameter.length > 0;

params.push({

let alldata = {
"in": "body",
"name": "body",
"description": removeTags(verbs.description),
"required": required,
"schema": {
};

if( verbDefinitionResult.topLevelParametersRef == null )
{
alldata['schema'] = {
}
}
else
{
alldata['schema'] = {
"$ref": "#/definitions/" + verbDefinitionResult.topLevelParametersRef
}
});
}
params.push(alldata);

pathItemObject[verbs.type] = {
tags: [verbs.group],
Expand All @@ -102,7 +112,12 @@ function createPostPushPutOutput(verbs, definitions, pathKeys) {
produces: [
"application/json"
],
parameters: params
parameters: params,
responses: { "200" :
{
"description": "successful operation"
}
}
}

if (verbDefinitionResult.topLevelSuccessRef) {
Expand Down Expand Up @@ -178,7 +193,7 @@ function createFieldArrayDefinitions(fieldArray, definitions, topLevelRef, defau
};

definitions[objectName] = definitions[objectName] ||
{ properties : {}, required : [] };
{ properties : {} };

if (nestedName.propertyName) {
var prop = { type: (parameter.type || "").toLowerCase(), description: removeTags(parameter.description) };
Expand All @@ -197,6 +212,12 @@ function createFieldArrayDefinitions(fieldArray, definitions, topLevelRef, defau
definitions[objectName]['properties'][nestedName.propertyName] = prop;
if (!parameter.optional) {
var arr = definitions[objectName]['required'];
// Make required only exist when there are required elements
if( arr == null )
{
definitions[objectName]['required'] = [];
arr = definitions[objectName]['required'];
}
if(arr.indexOf(nestedName.propertyName) === -1) {
arr.push(nestedName.propertyName);
}
Expand Down Expand Up @@ -271,7 +292,7 @@ function createPathParameters(verbs, pathKeys) {
pathKeys = pathKeys || [];

var pathItemObject = [];
if (verbs.parameter && verbs.parameter.fields.Parameter) {
if (verbs.parameter) {

for (var i = 0; i < verbs.parameter.fields.Parameter.length; i++) {
var param = verbs.parameter.fields.Parameter[i];
Expand Down