fix(codegen): traverse references in all supported OpenAPI fields - #2554
Open
abramchikd wants to merge 1 commit into
Open
abramchikd wants to merge 1 commit into
abramchikd wants to merge 1 commit into
Conversation
Contributor
|
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.
fix(codegen): traverse references in all supported OpenAPI fields
Summary
Extend the codegen reference walker so component pruning discovers references
from all
SchemaRef-bearing fields supported by the current kin-openapi model,as well as from webhooks and nested media-type content.
Previously, a component referenced only from an OpenAPI 3.1 JSON Schema keyword,
an OpenAPI 3.2
itemSchema, a webhook, header content, or an encoding headercould be treated as unused and removed from
components.Problem
pruneUnusedComponentsdetermines which components are reachable throughfindComponentRefs, which in turn uses the sharedwalkSwaggertraversal.That traversal covered the original OpenAPI 3.0 schema locations but did not
keep pace with fields added to kin-openapi for OpenAPI 3.1 and 3.2.
For example, the reference in this OpenAPI 3.1 schema was not visited:
The same problem affected references under
prefixItems,contains,patternProperties,dependentSchemas,unevaluatedItems,unevaluatedProperties,if/then/else,$defs, andcontentSchema.Root-level webhooks were also skipped. In addition, media-type traversal did not
visit OpenAPI 3.2
itemSchema, schemas insideHeader.Content, or headers nestedunder
MediaType.Encoding.Changes
paths.schemaChildRefs.SchemaRef-bearing field currently exposed byopenapi3.Schema, including the OpenAPI 3.1 JSON Schema keywords.walkContent.schemaand OpenAPI 3.2itemSchemain media types.header content.
Scope
This change does not add a local workaround for kin-openapi's lossy
SchemaRef.MarshalJSONbehavior with OpenAPI 3.1$refsibling keywords.Preserving the original sibling fields, including explicitly empty values and
self-referential schemas, requires a fix in kin-openapi because the relevant
source-presence information is stored in private
SchemaReffields.Once kin-openapi preserves those fields during marshaling, oapi-codegen's
existing embedded-spec flow can continue to internalize external references and
marshal the document without clearing
$refor implementing its own cycledetection.
This pull request was created with the assistance of OpenAI Codex.