Skip to content

Commit

Permalink
feat(swagger): use response body as sample for definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nazieb committed Apr 21, 2018
1 parent 51a6a3b commit 1b5296b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/formatters/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Regex from "re.js"
import moment from "moment"

let securityDefinitions = {};
let structureExamples = {};

/**
* @param blueprint
Expand Down Expand Up @@ -100,6 +101,17 @@ function getActions(actions) {
pathResponse.schema["type"] = "string";
} else {
pathResponse.schema = getResponseSchema(response.content);

if (pathResponse.schema.hasOwnProperty("$ref")) {
const structureName = pathResponse.schema["$ref"].replace("#/definitions/", "");

try {
const responseBody = response.body.replace("\\n", "");
structureExamples[structureName] = JSON.parse(responseBody);
} catch (e) {
// do nothing
}
}
}

path.responses[response.name] = pathResponse;
Expand Down Expand Up @@ -429,6 +441,10 @@ function getDefinitions(dataStructures) {
definition["properties"] = properties;
}

if (structureExamples.hasOwnProperty(definitionName)) {
definition["example"] = structureExamples[definitionName];
}

result[definitionName] = definition;
}

Expand Down

0 comments on commit 1b5296b

Please sign in to comment.