feat: support the OpenAPI 3.2 QUERY method in PathItem and the JAX-RS reade#5253
Open
CommanderGeek wants to merge 3 commits into
Open
feat: support the OpenAPI 3.2 QUERY method in PathItem and the JAX-RS reade#5253CommanderGeek wants to merge 3 commits into
CommanderGeek wants to merge 3 commits into
Conversation
Add the `query` HTTP method introduced in OpenAPI 3.2 to PathItem: field, accessors and fluent builder, HttpMethod.QUERY enum constant, and wiring in readOperations, readOperationsMap, operation(), equals, hashCode and toString. Adds model tests plus a swagger-core serialization round-trip. Refs swagger-api/swagger-parser#2248 (swagger-api/swagger-parser#2248)
Route the "query" method in Reader.setPathItemOperation onto PathItem.query(), and include query operationIds in extractOperationIdFromPathItem. Adds QueryMethodTest. No new public API: ReaderUtils.getHttpMethodFromCustomAnnotations already resolves any @HttpMethod-meta-annotated annotation, so an application's own @query binding maps with no further support. The @query here is a test fixture standing in for that binding Refs swagger-api/swagger-parser#2248 (swagger-api/swagger-parser#2248)
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds support for the
queryHTTP method, which OpenAPI 3.2 introduced as a fixed field of thePath Item Object,
and maps it from the JAX-RS annotation reader, while keeping it out of OpenAPI 3.0 and 3.1 output,
where the field is not valid.
Three commits, each self-contained:
swagger-models,PathItem.query: field, accessors and fluent builder,HttpMethod.QUERY,and wiring through
readOperations(),readOperationsMap(),operation(),equals,hashCodeand
toString.swagger-core, version gating: a newPathItemMixinmarksgetQuery()@JsonIgnorefor the3.0 and 3.1 mappers, so neither can emit a Path Item field that those versions do not define.
swagger-jaxrs2,Reader.setPathItemOperationroutes"query"ontoPathItem.query(), andextractOperationIdFromPathItemincludes query operationIds in the uniqueness check.Motivation is swagger-parser's OpenAPI 3.2 work: the parser builds on
swagger-models, so the modelhas to be able to carry a
queryoperation before 3.2 documents can be represented at all.Refs: swagger-api/swagger-parser#2248
Type of Change
Checklist
Screenshots / Additional Context
Three notes for reviewers
1.
queryis deliberately not emitted by any current mapper. swagger-core has no OpenAPI 3.2support today ,
SpecVersionisV30/V31only, so there is no mapper that may legitimately writethe field, and both existing ones are gated. The field is therefore enabling work for downstream
consumers rather than something that changes swagger-core's output. Adding
SpecVersion.V32plusJson32/Yaml32is the natural next step, but it is a much larger change (openapi31is threaded asa
booleanthrough dozens of signatures across core, jaxrs2, integration and the build plugins), andit commits the project to a 3.2 design that is better agreed up front than smuggled in here. Happy to
follow up on that in whatever shape you prefer.
2. The gating applies on read as well as write.
@JsonIgnoreon a mixin accessor removes theproperty in both directions, so the 3.0/3.1 mappers also drop a
querykey when parsing. That issymmetric with how
SchemaMixintreats the 3.1-only schema fields ($id,$anchor,prefixItems, …)under the 3.0 mapper, and it is pinned by an explicit test rather than left implicit.
3. No new public API in swagger-jaxrs2: the only main-source change there is the
Readerswitchcase.
ReaderUtils.getHttpMethodFromCustomAnnotationsalready resolves any annotation meta-annotatedwith
@HttpMethodto its lower-cased method name, so an application's own@QUERYbinding maps ontoPathItem.querywith no further support needed. The@QUERYannotation in this PR lives in testsources purely as the stand-in for that user-declared binding. If you would rather ship one from
swagger-jaxrs2 as a convenience, that is an easy addition, it just seemed like public surface you
should choose to own, not inherit from this PR.
Known follow-up
additionalOperations, the other new 3.2 Path Item field, is not included. It has its own designquestions like how non-enum methods surface through
readOperations/readOperationsMap, and the specrule that the map MUST NOT duplicate methods with fixed fields, so it seemed better kept separate
than bundled here.
Test results
Full suites, run locally on JDK 21:
swagger-modelsswagger-coreswagger-jaxrs2New coverage:
PathItemTest(model wiring,equals/hashCode,readOperations*), two tests inJsonSerializationTest(3.0 and 3.1 mappers omitqueryon write, drop it on read), andQueryMethodTest(reader maps@QUERYontoPathItem.query; the resulting operation does not reachJson/Json31/Yaml/Yaml31output).