Bug Report Checklist
Description
When defining multiple named examples on a requestBody following the OAS3 specification for adding examples, the examples variable on bodyParam is empty in the Mustache template context. This means it is impossible to generate proper @RequestBody Swagger annotations with examples using the JavaSpring generator, even when the spec is fully valid OAS3.
The data is clearly being parsed (it appears in {{jsonSchema}} as an HTML-encoded string), but it is never mapped into the examples field.
Openapi-generator version
7.21.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Example API
version: 1.0.0
paths:
/users:
post:
summary: Adds a new user
tags:
- User
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
examples:
Jessica:
value:
id: 10
name: Jessica Smith
Ron:
value:
id: 11
name: Ron Stewart
responses:
"200":
description: OK
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
Generation Details
generatorName: spring
dateLibrary: java8,
hideGenerationTimestamp: true
useBeanValidation: true
useTags: true
delegatePattern: true
requestMappingMode: none
useJakartaEe: true
Steps to reproduce
- Use the spec above with the
spring generator
- Create a custom
api.mustache with the following debug block added inside the method:
{{#bodyParam}}
/*
DEBUG bodyParam dump:
example: {{example}}
examples: {{examples}}
jsonSchema: {{jsonSchema}}
*/
{{/bodyParam}}
- Generate and inspect the output
Actual output:
example: new User()
examples: <-- empty
jsonSchema: { "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" },
"examples" : { "Jessica" : { "value" : { "id" : 10, "name" : "Jessica Smith" } },
"Ron" : { "value" : { "id" : 11, "name" : "Ron Stewart" } } } } } }
Expected output:
{{examples}} should be populated and iterable, allowing the template to generate:
@io.swagger.v3.oas.annotations.parameters.RequestBody(
content = @io.swagger.v3.oas.annotations.media.Content(
mediaType = "application/json",
schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = User.class),
examples = {
@io.swagger.v3.oas.annotations.media.ExampleObject(
name = "Jessica",
value = "{\"id\": 10, \"name\": \"Jessica Smith\"}"
),
@io.swagger.v3.oas.annotations.media.ExampleObject(
name = "Ron",
value = "{\"id\": 11, \"name\": \"Ron Stewart\"}"
)
}
)
)
Related issues/PRs
Suggest a fix
Bug Report Checklist
Description
When defining multiple named examples on a
requestBodyfollowing the OAS3 specification for adding examples, theexamplesvariable onbodyParamis empty in the Mustache template context. This means it is impossible to generate proper@RequestBodySwagger annotations with examples using theJavaSpringgenerator, even when the spec is fully valid OAS3.The data is clearly being parsed (it appears in
{{jsonSchema}}as an HTML-encoded string), but it is never mapped into theexamplesfield.Openapi-generator version
7.21.0OpenAPI declaration file content or url
Generation Details
Steps to reproduce
springgeneratorapi.mustachewith the following debug block added inside the method:Actual output:
Expected output:
{{examples}}should be populated and iterable, allowing the template to generate:Related issues/PRs
Suggest a fix