Compound models - allOf, anyOf, oneOf support #2299
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
implements #2277, DON'T MERGE yet, clarify points below and add reorganized tests before merging.
some notes;
swagger-annotations
(see updatedSchema
annotation, and new annotationDiscriminatorMapping
)As an example if we define a "parent" bean like:
and a "child":
when we resolve with a code like:
then both
BaseBean
andSub1Bean
are resolvedif a
@JsonSubTypes
is not declared on the parent, resolver won't be able to "know" about Sub1Bean which will not be resolved.e.g with:
and a "child":
when we resolve with a code like:
then also
BaseBean
will be resolved; this was different in 2.0, where a@JsonSubTypes
was needed on the parent. See temporarily commented code here4, atm anyOf (regardless if interfaces) are resolved not as ref model but inline; this is not true for oneOf or allOf. @fehguy @webron what would be the best behaviour here? in 2.0 ref model was used in allOf, possibly we can:
A. resolve anyOf, allOf, and oneOf as referenced models
B. resolve anyOf, allOf, and oneOf as inline models (duplicating possibly definitions)
C. resolve anyOf inline, only if referenced type is interface
@Schema (allOf = ..)
annotation is present and/or a@JsonSubTypes
is declared on the parent bean, and other properties are declared in the "child" bean, the result JSON will have anallOf
field holding the parent schema refs, and will declare its own properties in theproperties
field.This is different from 2.0 behaviour, which "merged" also bean "own" properties into allOf array; I guess the former behaviour is possibly more correct, also possibly previous behaviour was related to the way allOf resolving was handled (parent/child "trigger' methods on ComposedModel).
As an example if we define a "parent" bean like:
and a "child":
the serialized JSON/YAML will look like:
@webron @fehguy is this ok?
position
field (annotations/model/resolver/spec); is it planned, or should we remove refs in tests, etc?swagger-core
module; this would include fix/re-enable/refactor/remove what currently disabled, and optionally write new ones (equivalent to 2.0), idea is more or less the following:Current: swagger-core/modules/swagger-core/src/test/java/io/swagger/deserialization
swagger-core/modules/swagger-core/src/test/java/io/swagger/oas.models
swagger-core/modules/swagger-core/src/test/java/io/swagger/properties
swagger-core/modules/swagger-core/src/test/java/io/swagger/util
swagger-core/modules/swagger-core/src/test/java/io/swagger
Reorganized: reorganize into swagger-core/modules/swagger-core/src/test/java/io/swagger/deserialization
Current: swagger-core/modules/swagger-core/src/test/java/io/swagger/jackson
swagger-core/modules/swagger-core/src/test/java/io/swagger
Reorganized: move them all to swagger-core/modules/swagger-core/src/test/java/io/swagger/resolve
Current: swagger-core/modules/swagger-core/src/test/java/io/swagger/parameter
swagger-core/modules/swagger-core/src/test/java/io/swagger/properties
swagger-core/modules/swagger-core/src/test/java/io/swagger/util
swagger-core/modules/swagger-core/src/test/java/io/swagger
Reorganized: move them all to swagger-core/modules/swagger-core/src/test/java/io/swagger/serialize
Current: swagger-core/modules/swagger-core/src/test/java/io/swagger
Reorganized: keep it (renable/refactor,create new)