Skip to content

[BUG][Java][Spring] Missing examples parameter in @Schema annotation for OAS 3.1 spec #24755

Description

@marek-g8i

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions