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] [okhttp-gson] enum values are not validated in some cases #16917

Closed
5 of 6 tasks
ctreatma opened this issue Oct 26, 2023 · 0 comments · Fixed by #16865
Closed
5 of 6 tasks

[BUG] [Java] [okhttp-gson] enum values are not validated in some cases #16917

ctreatma opened this issue Oct 26, 2023 · 0 comments · Fixed by #16865

Comments

@ctreatma
Copy link
Contributor

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

We are using the Java generator with okhttp-gson. We have noticed that enum values are not validated consistently by the generated models.

With the example schema below, we have observed that the code generated by okhttp-gson generator works as follows when deserializing an object that matches the FooThing schema (i.e., it has a kind property with value foo):

  • FooThing deserializes the object without an error (correct)
  • BarThing throws an error that the object isn't valid according to the schema (correct)
  • Thing model doesn't validate the enum values, throws an error that the object matches both FooThing and BarThing (incorrect)
  • Container model, which only allows a BarThing, doesn't validate the enum value and does not throw a validation error (incorrect)
openapi-generator version

v7.0.0

OpenAPI declaration file content or url
components:
  schemas:
    Thing:
      type: object
      oneOf:
        - $ref: '#/components/schemas/FooThing'
        - $ref: '#/components/schemas/BarThing'
    FooThing:
      type: object
      properties:
        kind:
          type: string
          enum:
          - foo
    BarThing:
      type: object
      properties:
        kind:
          type: string
          enum:
          - bar
    Container:
      type: object
      properties:
        thing:
          $ref: '#/components/schemas/BarThing'
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Generate validateJsonElement functions when using the Java okhttp-gson generator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant