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] codegenProperty retrieves wrong property if one is required and another is optional #12857

Closed
2 of 6 tasks
spacether opened this issue Jul 13, 2022 · 0 comments · Fixed by #12858
Closed
2 of 6 tasks

Comments

@spacether
Copy link
Contributor

spacether commented Jul 13, 2022

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

codegenProperty retrieves wrong property if one is required and another is optional

openapi-generator version
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: openapi 3.0.3 sample spec
  description: sample spec for testing openapi functionality, built from json schema
    tests for draft6
  version: 0.0.1
paths: {}
components:
  schemas:
    FooRequired:
      properties:
        foo: {}
      required:
      - foo
    FooOptional:
      properties:
        foo: {}
Generation Details

Any generator

Steps to reproduce

Generate code and see that
the required property is not correct in

  • FooRequired.vars[0].required
  • FooOptional.vars[0].required

This is happening because we store the required status (defined at a schema level higher) in the codegenProperty instance.

Related issues/PRs

This came up when working on
#12826
Where the property foo is optional in one place and required in another

Suggest a fix

Add the required boolean into fromProperty creation signature and cache call.

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