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

Schema annotation updates #601

Merged
merged 3 commits into from
May 8, 2024
Merged

Conversation

Azquelt
Copy link
Member

@Azquelt Azquelt commented Apr 16, 2024

Add new fields to @Schema and @SchemaProperty to support the new properties available in OpenAPI 3.1.

Builds on the model changes from #598

New properties:

  • examples
  • comment
  • constValue
  • ifSchema / thenSchema / elseSchema
  • dependentSchemas
  • contains / maxContains / minContains
  • prefixItems
  • patternProperties
  • dependentRequired
  • propertyNames
  • contentEncoding / contentMediaType / contentSchema

Additional changes:

  • deprecate example in preference of using examples
    • keep example to preserve backward compatibility
  • make True and False valid everywhere that Class is accepted to indicate a subschema
    • previously they were only applicable to additionalProperties
  • add additionalProperties to @SchemaProperty
    • I'm unsure why we didn't add it here in 3.1
    • If we don't allow additionalProperties in @SchemaProperty, then we may want to reconsider adding all the other new properties there also
  • Some fixes and clarifications to the @Schema javadoc
  • Removal of Javadoc indicating restrictions which are no longer present in OpenAPI 3.1 / Json Schema 2020-12

Other notes:

  • type and nullable are unchanged to preserve backward compatibility
  • I wanted to add new TCK tests for all the new properties, but I noticed that we don't have tests for the current properties which apply subschemas - we did have some but they were removed in Remove schema composition tests. #171 - so I haven't added new ones.

Test new parameters on the Schema annotation which don't involve
subschemas.

- comment
- const
- dependentRequired
- contentEncoding
- contentMediaType
@Azquelt Azquelt force-pushed the schema-annotation-updates branch from dc7eb28 to cd35c07 Compare May 7, 2024 17:02
@Azquelt Azquelt marked this pull request as ready for review May 7, 2024 17:04
@Azquelt Azquelt requested a review from MikeEdgar May 7, 2024 17:04
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.

Looks good, thanks @Azquelt

@@ -40,10 +54,7 @@
public @interface Schema {
Copy link
Member

Choose a reason for hiding this comment

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

What are your thoughts on having a String value() default "" property that could be used to set an arbitrary schema (that must be valid JSON/YAML)? That would give support for alternate dialects with the annotation.

I'm not sure myself, but I wanted to mention it as a possibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's certainly an interesting option which I hadn't considered. It becomes a bit more usable since Java 15 added text blocks too.

I'll raise a new issue to think about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #610 to continue the discussion after this is merged.

@Azquelt Azquelt merged commit dfedd16 into eclipse:main May 8, 2024
4 checks passed
@Azquelt Azquelt deleted the schema-annotation-updates branch May 8, 2024 11:20
@Azquelt Azquelt mentioned this pull request May 9, 2024
9 tasks
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.

2 participants