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] Model generated using allOf and $ref is affected by the presence of a description (regression from 7.9.0) #20440

Closed
3 of 6 tasks
oscar8880 opened this issue Jan 10, 2025 · 2 comments

Comments

@oscar8880
Copy link

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

Since upgrading to 7.10.0 from 7.9.0 previously working spec which uses allOf and $ref to extend a schema with another is now missing a property in the generated Java class.

In my application this is breaking request body validation because the request body class is missing a field which should be there, hence a valid request object throws an error:

Unrecognized field "key" (class testsdk_v7100.models.RequestBodyType), not marked as ignorable (one known property: "type"])

After some time tracking it down it seems the presence of a description field on the schema is impacting the generation somehow, and removing the description fixes the issue. I'm unsure of how this ends up impacting the generation, but my expectation would be that a description shouldn't have an impact on the generated code functionality.

openapi-generator version

7.10.0

This is a regression from 7.9.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  version: v1
paths:
  /test:
    post:
      operationId: test
      requestBody:
        required: true
        description: Lorem ipsum
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestBody'
      responses:
        201:
          description: foo
          content:
            application/json:
              schema:
                type: object
                properties:
                  foo:
                    type: string
      responses:
        201:
          description: foo
          content:
            application/json:
              schema:
                type: object
                properties:
                  foo:
                    type: string
components:
  schemas:
    RequestBody:
      required:
        - details
      properties:
        operation:
          type: string
        details:
          $ref: '#/components/schemas/Details'
    Details:
      allOf:
        - $ref: '#/components/schemas/RequestBodyType'
      description: Lorem ipsum # !!!! HERE !!!! - removing this description line fixes the issue
      discriminator:
        propertyName: type
        mapping:
          A: '#/components/schemas/RequestBodyTypeA'
          B: '#/components/schemas/RequestBodyTypeB'
    RequestBodyTypeA:
      allOf:
        - $ref: '#/components/schemas/Details'
      required:
        - key
      properties:
        key:
          type: string # actually an enum of values that differ to request type B, simplified here
    RequestBodyTypeB:
      allOf:
        - $ref: '#/components/schemas/Details'
      required:
        - key
      properties:
        key:
          type: string # actually an enum of values that differ to request type A, simplified here
    RequestBodyType:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - A
            - B

Here's a skeleton application with a reproduction:

open-api-generator-sandbox.zip

  • unzip the file somewhere
  • run the following inside the open-api-generator-sandbox directory
mvn clean
mvn generate-sources -Dopenapi-generator.version=7.9.0 -DpackageName=v790
mvn generate-sources -Dopenapi-generator.version=7.10.0 -DpackageName=v7100
mvn verify
  • observe that 1/4 tests fails
  • the first test is using 7.9.0 and has a description on the impacted schema - this passes
  • the second test is using 7.9.0 and does not have a description on the impacted schema - this passes
  • the third test is using 7.10.0 and has a description on the impacted schema - this FAILS
  • the fourth test is using 7.10.0 and does not have a description on the impacted schema - this passes
Related issues/PRs

It could be related to this recent fix: #19986 which relates to #17534, #19900

@wing328
Copy link
Member

wing328 commented Jan 11, 2025

thanks for reporting the issue.

reverted via #20446

will add a test to cover the issue moving forward.

@wing328 wing328 closed this as completed Jan 11, 2025
@oscar8880
Copy link
Author

Many thanks!

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

2 participants