Skip to content

Commit

Permalink
Merge pull request #357 from swagger-api/html-body-fix
Browse files Browse the repository at this point in the history
resolves request body example and adds to htmlDocs template
  • Loading branch information
frantuma authored Apr 9, 2019
2 parents b489a40 + ae70c1b commit c2cedc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.swagger.v3.core.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.BinarySchema;
Expand Down Expand Up @@ -2494,6 +2495,19 @@ public CodegenParameter fromRequestBody(RequestBody body, String name, Schema sc

codegenParameter.jsonSchema = Json.pretty(body);

if (body.getContent() != null && !body.getContent().isEmpty()) {
Object example = new ArrayList<>(body.getContent().values()).get(0).getExample();
if (example != null) {
codegenParameter.example = Json.pretty(example);
} else {
Map<String, Example> examples = new ArrayList<>(body.getContent().values()).get(0).getExamples();
if (examples != null && !examples.isEmpty()) {
// get the first.. or concat all as json?
codegenParameter.example = Json.pretty(new ArrayList<>(examples.values()).get(0));
}
}
}

if (schema == null) {
schema = getSchemaFromBody(body);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/handlebars/htmlDocs/bodyParam.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{#is this 'body-param'}}<div class="param">{{baseName}} {{#baseType}}<a href="#{{baseType}}">{{baseType}}</a>{{/baseType}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>

<div class="param-desc"><span class="param-type">Body Parameter</span> &mdash; {{unescapedDescription}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/is}}
{{#example}}<div class="param-desc"><span class="param-type">example: <code>{{example}}</code></span></div>{{/example}}

0 comments on commit c2cedc7

Please # to comment.