Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA][SPRING] Openapi generator does not work properly with array example when use 3.1.1 specification format #20786

Open
4 of 6 tasks
SashaVolushkova opened this issue Mar 4, 2025 · 0 comments

Comments

@SashaVolushkova
Copy link

SashaVolushkova commented Mar 4, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

I use openapi generator with spring boot. I have specification of api and i want use 3.1.1 Openapi version. I have a model with arrays and want to provide example.

when I set into spec 3.1.1 version i have a such code in generated files (incorrect):

  @Schema(name = "nodes", example = "[{name=Node1}, {name=Node2}, {name=Node3}]", description = "List of nodes in the EventGraph.", requiredMode = Schema.RequiredMode.NOT_REQUIRED)

when i set 3.0.1 version in spec file i have this (correct):

@Schema(name = "nodes", example = "[{\"name\":\"Node1\"},{\"name\":\"Node2\"},{\"name\":\"Node3\"}]", description = "List of nodes in the EventGraph.", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
openapi-generator version

gradle plugin id "org.openapi.generator" version "7.12.0"
generator: spring

OpenAPI declaration file content or url
openapi: 3.1.1
info:
  title: EventGraph API
  version: 1.0.0
paths:
  /simplePost:
    post:
      summary: Simple post request
      description: description
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SomeDTO'
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SomeDTO"
components:
  schemas:
    SomeDTO:
      type: object
      properties:
        name:
          type: string
        nodes:
          description: List of nodes in the EventGraph.
          type: array
          items:
            $ref: '#/components/schemas/NodeDTO'
          example:
            - name: Node1
            - name: Node2
            - name: Node3
    NodeDTO:
      type: object
      properties:
        name:
          type: string
      required:
        - name
Generation Details

generator - spring

openApiGenerate {
    generatorName = "spring"
    inputSpec = "${project.projectDir}/src/main/resources/error-test.yml".replace("\\","/")
    outputDir = "${buildDir}/generated"
    apiPackage = "pro.axenix_innovation.axenapi.web.api"
    modelPackage = "pro.axenix_innovation.axenapi.web.model"
    configOptions = [
            useSpringBoot3: "true",
            interfaceOnly: "true",
            useTags: "true",
            generateBuilders: "true",
            generatedConstructorWithRequiredArgs: "true",
            generateConstructorWithAllArgs: "true"
    ]
}
Steps to reproduce

Use my specification(i thing any spec with array example). Use gradle plugin with specification in the issue

Related issues/PRs
Suggest a fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant