diff --git a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java index e9f1f58d49..3854d5911f 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -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; @@ -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 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); } diff --git a/src/main/resources/handlebars/htmlDocs/bodyParam.mustache b/src/main/resources/handlebars/htmlDocs/bodyParam.mustache index d511dcbb7e..4873e06ed2 100644 --- a/src/main/resources/handlebars/htmlDocs/bodyParam.mustache +++ b/src/main/resources/handlebars/htmlDocs/bodyParam.mustache @@ -1,3 +1,4 @@ {{#is this 'body-param'}}
{{baseName}} {{#baseType}}{{baseType}}{{/baseType}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}
Body Parameter — {{unescapedDescription}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}
{{/is}} + {{#example}}
example: {{example}}
{{/example}} \ No newline at end of file