Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Fix: body parameter - empty schema to be set to empty object #4

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
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,22 @@ function parseBody(ramlBody, srMethod) {
if (_.isUndefined(srMethod.parameters))
srMethod.parameters = [];

srMethod.parameters.push({
//Fix for the body parameter - empty schema to be set to empty object
//Schema is mandatory for body parameter
var bodyRequest = {
//FIXME: check if name is used;
name: 'body',
in: 'body',
required: true,
//TODO: copy example
schema: convertSchema(_.get(ramlBody[jsonMIME], 'schema'))
});
};

if (!bodyRequest.schema) {
bodyRequest.schema = {type: "object"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tehcyx You workaround not work for non-object body, for example array.
In Swagger/JSON Schema empty schema mean anyting.
Can I replace {type: 'object'} with {}?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ style issue I use ' for JS code and " in JSON and JSONPath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't know from the top of my head if that works. But if the output will be valid Swagger we're totally fine with it.

}

srMethod.parameters.push(bodyRequest);
}

function convertSchema(schema) {
Expand Down