Class OpenApiResponseTypes
Why these exist
An endpoint that supports both offset and cursor pagination returnsObject and declares
its two shapes with @Schema(oneOf = {...}). An annotation can only name a Class,
and Java erases type arguments, so naming a raw generic container there —
PaginatedResponseDataObject.class — hands swagger-core a container whose data is an
array of bare object. The payload type is gone from the spec.
That is worse than a generator error. A generated client deserializes the untyped payload to raw camelCase dictionaries, and a wrapper that reads snake_case field names off them gets nulls for every column rather than a failure. gemmapy carried a private table of the missing item types for exactly this reason.
Binding the type argument in a named subclass restores it: swagger-core resolves the subclass
to a schema of the subclass's own simple name, with data typed as an array of the bound
value object.
Using them
Name the bound subclass in theoneOf, not the raw generic, and make sure it matches what
the method actually returns — the return type is Object, so nothing else checks:
@ApiResponse(responseCode = "200",
content = @Content(schema = @Schema(oneOf = {
PaginatedResponseDataObjectGeneValueObject.class,
CursorPaginatedResponseDataObjectGeneValueObject.class
})))
public Object getGenes( ... )
OpenApiTest.testPaginatedResponsesDeclareTheirPayloadType fails the build when a response
schema reachable from a path has lost its data item type, so a new raw-generic
oneOf cannot reach the published spec.
These classes are never instantiated; the endpoints build the generic parent. The constructors mirror the parent's so the subclass compiles and stays usable as a real return type.
DatasetsWebService declares its own bound containers rather than using this class,
because their generic parents (FilteredAndInferredAndPaginatedResponseDataObject and
friends, which carry inferred ontology terms) are themselves nested there.
- Author:
- phase3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCursor shape forGET /genes/{gene}/probesandGET /taxa/{taxon}/genes/{gene}/probes.static classCursor shape forGET /platforms/{platform}/datasets.static classCursor shape forGET /genesandGET /taxa/{taxon}/genes.static classCursor shape forGET /tickets/{id}/events.static classCursor shape forGET /tickets,GET /datasets/{dataset}/ticketsandGET /platforms/{platform}/tickets.static classCursor shape forGET /platforms,GET /platforms/{platform}andGET /platforms/blacklisted.static classCursor shape forGET /platforms/{platform}/elementsandGET /platforms/{platform}/elements/{probes}.static classCursor shape forGET /resultSets.static classCursor shape forGET /taxa/{taxon}/datasets.static classCursor shape forGET /platforms/{platform}/elements/{probe}/genes.static classLegacy shape forGET /platforms,GET /platforms/{platform}andGET /platforms/blacklisted.static classLegacy shape forGET /platforms/{platform}/elementsandGET /platforms/{platform}/elements/{probes}.static classLegacy shape forGET /resultSets.static classLegacy shape forGET /taxa/{taxon}/datasets.static classLegacy shape forGET /platforms/{platform}/elements/{probe}/genes.static classLegacy shape forGET /genes/{gene}/probesandGET /taxa/{taxon}/genes/{gene}/probes.static classLegacy shape forGET /platforms/{platform}/datasets.static classLegacy shape forGET /genesandGET /taxa/{taxon}/genes.static classLegacy shape forGET /tickets.static classLegacy shape forGET /tickets/{id}/events.static classLegacy shape forGET /datasets/{dataset}/ticketsandGET /platforms/{platform}/tickets. -
Method Summary