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

Different http methods in the same path and with common property names are rendered incorrectly #2808

Open
viniciusxyz opened this issue Dec 9, 2024 · 0 comments

Comments

@viniciusxyz
Copy link

viniciusxyz commented Dec 9, 2024

Describe the bug

In the example project there are two endpoints a get and a post and the get response and the post body have different objects with different properties, but as the attribute name is the same the rendering is done incorrectly, let's look at swagger .yaml that I used as input to generate the code:

openapi: 3.0.0
info:
  title: User API
  description: User API
  version: 1.0.0
paths:
  /vinc/account:
    get:
      summary: Get account
      description: Get account
      operationId: getAccount
      responses:
        200:
          description: "Get account"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountTsDto'
    post:
      summary: Post Account
      description: Post Account
      operationId: postAccount
      requestBody:
        description: "Create account"
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountTsDtoTwo'
      responses:
        201:
          description: "Account"

components:
  schemas:
    AccountTsDto:
      type: object
      properties:
        account:
          $ref: '#/components/schemas/Account'

    Account:
      type: object
      properties:
        exampleOne:
          type: string

    AccountTsDtoTwo:
      type: object
      properties:
        account:
          $ref: '#/components/schemas/AccountExample'

    AccountExample:
      type: object
      properties:
        exampleTwo:
          type: string

And your visualization on Swagger Codegen

GET

image

POST

image

Everything seems correct, now let's see the result of the interface in spring-docs:

openapi: 3.0.1
info:
  description: |
    User API
servers:
- url: http://localhost:8080
  description: Generated server url
paths:
  /vinc/account:
    get:
      tags:
      - vinc-controller-adapter
      summary: Get account
      description: Get account
      operationId: getAccount
      responses:
        "200":
          description: Get account
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountTsDto"
    post:
      tags:
      - vinc-controller-adapter
      summary: Post Account
      description: Post Account
      operationId: postAccount
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AccountTsDtoTwo"
        required: true
      responses:
        "201":
          description: Account
components:
  schemas:
    AccountTsDtoTwo:
      type: object
      properties:
        account:
          $ref: "#/components/schemas/account"
      description: Create account
    account:
      type: object
      properties:
        exampleOne:
          type: string
    AccountTsDto:
      type: object
      properties:
        account:
          $ref: "#/components/schemas/account"

Swagger UI

GET

image

POST

image

To Reproduce

  1. Download this project
    demo.zip

  2. Compile and run

  3. Access http://localhost:8080/swagger-ui/index.html

As you can see, it appears that the Spring docs try to deduplicate items with the same names and this means that in the post where we should see exampleTwo we see exampleOne

Extra information

  • Spring Boot 3.4.0
  • Spring Docs 2.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant