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] Java generator generates wrong default type when type is defined inside allOf #19117

Open
5 of 6 tasks
gtsystem opened this issue Jul 9, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@gtsystem
Copy link
Contributor

gtsystem commented Jul 9, 2024

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

There is a schema of type number and an attribute uses such schema and set a default. The type number is casted to BigDecimal, but the default is not and compilation fails.

openapi-generator version

Tested with 7.7.0 and 7.8.0-SNAPSHOT (latest docker image)

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Example API v1
  description: A reference API
  contact: {}
  version: 2.0.0

paths: {}

components:
  schemas:
    Length:
      description: Distance in meters between the beginning and end of a roadway or sub-segment.
      type: number
      minimum: 0.0

    MySchema:
      type: object
      properties:
        length:
          allOf:
            - $ref: "#/components/schemas/Length"
          default: 0.0
Generation Details

language: java
library: tested without setting library or jersey2

Steps to reproduce
  1. Create the file openapi-example.yml with the content above in the current directory
  2. Execute docker run -v `pwd`:/temp -it openapitools/openapi-generator-cli:latest generate -g java -i /temp/src/main/resources/apis/ols/intermodal/openapi-example.yml -o /temp/build/
  3. Check the generated schema in build/src/main/java/org/openapitools/client/model/MySchema.java

Expected:

private BigDecimal test = new BigDecimal("0.0");

Actual:

private BigDecimal test = 0.0;
Related issues/PRs

Maybe #12883

Suggest a fix

Not a fix, but the work arounds I found so far:

1: repeat the type in the parameter:

    MySchema:
      type: object
      properties:
        length:
          allOf:
            - $ref: "#/components/schemas/Length"
          type: number.  # <-- this fix the issue
          default: 0.0

or set format: double in the Length schema

    Length:
      description: Distance in meters between the beginning and end of a roadway or sub-segment.
      type: number
      format: double
      minimum: 0.0
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