Bug Report Checklist
Description
If an API spec compliant with OAS 3.1 contains multiple examples for a property (using the examples keyword), the examples parameter is not generated for the corresponding @Schema annotation in Java.
openapi-generator version
v7.24.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Multiple object examples.
version: 0.0.1
paths:
/api/example:
get:
responses:
"200":
description: Response schema with multiple examples.
content:
application/json:
schema:
$ref: '#/components/schemas/ExampleResponse'
components:
schemas:
ExampleResponse:
properties:
test:
type: string
examples: [ 'test string 1', 'test string 2' ]
Generation Details
java -jar openapi-generator-cli-7.24.0.jar generate \
--generator-name spring \
--model-package example \
--input-spec openapi.yaml
Steps to reproduce
Generated src/main/java/example/ExampleResponse.java file contains @schema annotation for getTest() getter method without examples parameter:
@Schema(name = "test", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("test")
public @Nullable String getTest() {
return test;
}
while it should be:
@Schema(name = "test", examples = { "test string 1", "test string 2" }, requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("test")
public @Nullable String getTest() {
return test;
}
Related issues/PRs
Suggest a fix
Add public List<String> examples; to CodegenProperty class and implement related handling, such as parsing examples array.
Update pojo.mustache with generation of examples for @Schema annotation with values from CodegenProperty.examples.
Bug Report Checklist
Description
If an API spec compliant with OAS 3.1 contains multiple examples for a property (using the
exampleskeyword), theexamplesparameter is not generated for the corresponding@Schemaannotation in Java.openapi-generator version
v7.24.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Generated
src/main/java/example/ExampleResponse.javafile contains@schemaannotation forgetTest()getter method withoutexamplesparameter:while it should be:
Related issues/PRs
Suggest a fix
Add
public List<String> examples;toCodegenPropertyclass and implement related handling, such as parsingexamplesarray.Update
pojo.mustachewith generation ofexamplesfor@Schemaannotation with values fromCodegenProperty.examples.