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

OAS 3.1 Schema model updates #598

Merged
merged 25 commits into from
Apr 23, 2024
Merged

OAS 3.1 Schema model updates #598

merged 25 commits into from
Apr 23, 2024

Conversation

Azquelt
Copy link
Member

@Azquelt Azquelt commented Feb 6, 2024

For #584

* the boolean value of this schema, or {@code null} if it is not a boolean schema
* @since 4.0
*/
void setBooleanSchema(Boolean booleanSchema);
Copy link
Member Author

Choose a reason for hiding this comment

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

Implementation note: having setBooleanSchema made it near-impossible to implement Schema as a thin wrapper around a Jackson representation of some JSON.

All the other setters merely change properties on the root object, but to implement this setter you have to change the root object itself. In Jackson, this means setting a new object on the parent and Jackson also doesn't allow you to traverse up a JSON tree (parents know about their children, but children don't know about their parents).

The other way of implementing this would be to have factory methods for an immutable boolean schema on OASFactory, but that would be very different than the way the rest of the MP OpenAPI model is designed.

There were other issues with implementing it as a wrapper around Jackson, e.g. calling code may assume that two calls to getAllOf() will return the same Schema instances, so I gave up on that approach.

@Azquelt Azquelt marked this pull request as ready for review April 9, 2024 11:06
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.

A few comments

* <li>{@code String}
* <li>{@code BigDecimal}
* <li>{@code BigInteger}
* <li>Any type which {@link OASFactory} can create
Copy link
Member Author

Choose a reason for hiding this comment

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

Noted that in the smallrye implementation, this would require quite a bit of refactoring since the class handling IO for each model type needs to have the IO class for every other model type passed in.

I still think it's a reasonable requirement, but would be open to changing it.

Copy link
Member

Choose a reason for hiding this comment

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

Is this because of on-the-fly serialization in the smallrye PR?

Copy link
Member Author

@Azquelt Azquelt Apr 22, 2024

Choose a reason for hiding this comment

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

At the moment, there's a separate IO class for each model class. When a model object has child model objects, the IO class needs a reference for the IO classes for those child object types. This is either passed into or created in the constructor.

This change means the SchemaIO class needs a reference to every other IO object, which makes for a rather large constructor. We also probably can't have it create a new instance in the constructor since we need to avoid creating a loop. I would propose moving the IO class references to IOContext and having every IO class retrieve them from there.

That's an irritating amount of refactoring though so I would like to make sure you think that's ok before I go ahead and do it.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I see your point now. We can discuss that in the other PR.

@Azquelt
Copy link
Member Author

Azquelt commented Apr 22, 2024

I've pushed commits to address the comments above and to add tests for reading and passing through a custom schema dialect via a model reader and a static document.

I think these are all the tests needed for the model parts of #584, so if these are approved I will squash the review change commits and merge this PR.

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.

LGTM

Azquelt and others added 15 commits April 23, 2024 15:57
- if/then/else
- $dialect
- comment
- depedentSchemas
- prefixItems
- contains
- patternProperties
- propertyNames
- unevaluatedItems
- unevaluatedProperties
- const
- maxContains
- minContains
- dependentRequired
- contentEncoding
- contentMediaType
- contentSchema

Co-authored-by: Michael Edgar <[email protected]>
Signifies that this schema represents a single boolean value, rather
than a schema object.
Now that OpenAPI allows boolean schemas in general, we don't need a
special case for additionalProperties.
These properties are now valid on all schemas.
Example is still a valid keyword in OpenAPI 3.1, though it is deprecated
in favor of examples.
Change exclusiveMinimum and exclusiveMaximum from boolean to BigDecimal.

Also update the javadoc for minimum and maximum to make the difference
in meaning between the properties more clear.
Nullable has been removed, type is now permitted to be an array of
permitted types and may include null.

Attempt to keep the old methods as far as they don't clash with the new
ones and can still be defined in a way that makes sense.
Example changed to examples and now must be an array.
Schema.type can now be either a string or an array of strings
exclusiveMinimum and exclusiveMaximum are now standalone numeric
properties, rather than boolean properties interpreted in conjunction
with minimum and maximum.
The exception type and stack-trace is important here.
Azquelt added 10 commits April 23, 2024 16:00
Tests for Schema.getAdditionalPropertiesBoolean and
getAdditionalPropertiesSchema.
This avoids conflicts between mutually exclusive properties now present
in Schema.

If setBooleanSchema is called with a non-null value, other methods may
fail.
These constructors are deprecated and cause problems when the model
tests call assertSameInstance.
Test that example and examples do not affect each other.
Test building a schema with a custom dialect in a model reader and
ensure it is serialized correctly.
@Azquelt Azquelt merged commit 8164b10 into eclipse:main Apr 23, 2024
4 checks passed
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