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 annotations 3.1 #1801

Draft
wants to merge 12 commits into
base: main-4.0
Choose a base branch
from

Conversation

Azquelt
Copy link
Contributor

@Azquelt Azquelt commented Apr 16, 2024

Implement the @Schema and @SchemaProperty changes from eclipse/microprofile-open-api#601.

This builds on #1793, so only the last few commits are relevant.

I haven't duplicated cases which are already covered by the TCK.

@Azquelt
Copy link
Contributor Author

Azquelt commented Apr 16, 2024

In e83724a I made some of the scanner tests output the actual JSON document in the event of a failure because it was more helpful to me during development than configuring logging and finding the logs, but that part is not relevant to the actual changes and can be dropped if desired.

- Change schema to hold a freeform map of objects
- New getters and setters added
- Type now holds an array, but is output as a single string if it only
  contains one item
- $ref is now valid with other fields so we cannot remove other fields
  at serialization time.
- When merging objects, some array properties should be merged, but
  others (e.g. examples) shouldn't.
- Old behaviour of setType and setNullable is maintained, as we rely on it
  fairly heavily to build up schema data from multiple sources
Make a copy of a ref schema before returning it to the caller after
registering a new type to prevent the caller from corrupting the
registry entry.

This is more likely now that $ref is valid alongside other properties.

We already did a copy when a ref was retrieved from the registry, but
not when it was first registered.
- Type can now be an array, but will still be output as a string if it
  only has one element
- The schema construction for "this object, but also allow null" is
  different. Previously we could combine a $ref with nullable = true,
  but nullable has been removed and we need to instead state that null
  is allowed as a type. This requires us to use anyOf instead.
- When generating from annotations, examples is used instead of example
Existing code relying on the old semantics of these methods was changed
to use static methods on SchemaImpl which preserves the old behavior.
For consistency with other model setters.
This test took a noticable amount of time and more than 50% was string
contatentation building the test file.
Include the full JSON output from the scanner when a test fails, to
avoid needing to search the logs and enable debug logging.
Tests for:
- if/then/else
- allOf/anyOf/oneOf/not
- dependentSchemas
- prefixItems
- contains/maxContains/minContains
- propertyNames
- patternProperties
- contentEncoding
- contentMediaType
- contentSchema
- examples
- comment
- if/then/elseSchema
- dependentSchemas
- prefixItems
- contains/minContains/maxContains
- patternProperties
- propertyNames
- constValue
- dependentRequired
- contentEncoding/contentMediaType/contentSchema
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.

None yet

1 participant