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

Skip IO of fields added in OpenAPI 3.1 when reading or writing OpenAPI 3.0 documents #2117

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

Azquelt
Copy link
Contributor

@Azquelt Azquelt commented Dec 18, 2024

Add a new field to the model metadata to indicate which version of OpenAPI added the field.

I changed SmallRyeOASModels.Properties to PropertyMetadata so that it doesn't conflict with other uses of Properties, but I'd be happy to change the naming here if other people have better ideas.

More detail in the commit messages.

Fixes #2105

@MikeEdgar MikeEdgar added this to the 4.0.6 milestone Dec 18, 2024
MikeEdgar
MikeEdgar previously approved these changes Dec 18, 2024
Copy link
Member

@MikeEdgar MikeEdgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. Thank you @Azquelt for working on this. Are you planning any additional changes or is it good to merge? I don't have any concern with the changes here.

- Add a field to the model metadata indicating the minimum version of
  OpenAPI that includes that field
- When reading or writing objects, ignore fields which require a newer
  version of OpenAPI than the one specified in the current document.

When the metadata is updated to set the new field, this will prevent the
inclusion of fields from OpenAPI 3.1 when writing OpenAPI 3.0 documents.

Implementation notes:
- Move IOContext.OpenApiVersion to its own file in the model project so
  we can use it from the OASModelProperty annotation.
- Move generated SmallRyeOASModels.Properties interface to its own file
  in the model project so we can reference it from BaseModel. Rename to
  PropertyMetadata so that it doesn't clash with other uses of the word
  "properties".
- Add a new method to BaseModel to get the PropertiesMetadata for the
  object. Add a PROPERTIES constant to each generated model class to
  implement this method.
Update the model metadata to set minVersion for all fields added in
OpenAPI 3.1.
Test that new fields added for OpenAPI 3.1 are read and written
correctly in 3.1 and 3.0 modes.
@Azquelt
Copy link
Contributor Author

Azquelt commented Dec 18, 2024

@MikeEdgar I wasn't planning any more functional changes. My previous push was to fix a couple of issues that sonarqube pointed out but I broke the imports >_>

I now think it's good to merge.

@MikeEdgar MikeEdgar merged commit 24df123 into smallrye:main Dec 18, 2024
7 checks passed
@Azquelt Azquelt deleted the drop-fields-30 branch December 18, 2024 17:22
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

Successfully merging this pull request may close these issues.

Invalid properties included in OpenAPI v3.0 output document
2 participants