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

setting all required fields as optional should not serialize "required" as an empty array #2943

Open
ben-lc opened this issue Nov 12, 2024 · 6 comments

Comments

@ben-lc
Copy link

ben-lc commented Nov 12, 2024

Expected Behavior

When fields are set as required on a schema and then set back as optional so that "required" field is empty, "required" should no be serialized in json or yaml, cause empty array is invalid for some openapi versions (cf: https://community.smartbear.com/discussions/swaggerostools/empty-array-in-required-field-in-schema-object/193184)

Actual Behavior

Required field is serialized as an empty array.

Steps to Reproduce the Problem

  1. Create a new openapi spec
  2. Create a new data type
  3. Create an required property on the data type
  4. Set previous property as not required

Specifications

  • apicurio studio: 0.2.62.Final
  • apicurio data models: 1.1.28

Cause

In apicurio-data-models, the ChangePropertyTypeCommand which is called when required field is changed on a property will create a new array to store required properties and will keep an empty array when all required properties are removed.

Proposed solution

Call parent.setRequiredProperties(null); to replace empty array by null so that "required" is not serialized when empty.

@ben-lc
Copy link
Author

ben-lc commented Nov 12, 2024

Hi @EricWittmann, I created PR Apicurio/apicurio-data-models#838 in apicurio-data-models to solve this issue.

@EricWittmann
Copy link
Member

Interesting! Nice catch on this. I think we can go ahead with merging your PR, but for data models 2.0 I'm wondering if this logic should be captured in the data model serializer. I'll give it some thought...

@ben-lc
Copy link
Author

ben-lc commented Nov 14, 2024

I agree, it should be better to handle this at serialization level.

@EricWittmann
Copy link
Member

FYI I merged the PR and am trying to release data-models. Having trouble, will keep working on it.

@EricWittmann
Copy link
Member

OK release is done successfully.

@ben-lc
Copy link
Author

ben-lc commented Nov 14, 2024 via email

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

2 participants