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 header
could be treated as unused and removed from components.
Problem
pruneUnusedComponents determines which components are reachable through
findComponentRefs, which in turn uses the shared walkSwagger traversal.
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:
components:
schemas:
Text:
type: string
Container:
type: object
propertyNames:
$ref: '#/components/schemas/Text'
The same problem affected references under prefixItems, contains,
patternProperties, dependentSchemas, unevaluatedItems,
unevaluatedProperties, if/then/else, $defs, and contentSchema.
Root-level webhooks were also skipped. In addition, media-type traversal did not
visit OpenAPI 3.2 itemSchema, schemas inside Header.Content, or headers nested
under MediaType.Encoding.
Changes
- Visit root-level webhooks using the same path-item traversal as normal paths.
- Continue walking components when an OpenAPI 3.1 document omits
paths.
- Centralize traversal of child schema references in
schemaChildRefs.
- Cover every
SchemaRef-bearing field currently exposed by
openapi3.Schema, including the OpenAPI 3.1 JSON Schema keywords.
- Centralize media-type traversal in
walkContent.
- Visit both
schema and OpenAPI 3.2 itemSchema in media types.
- Visit schemas and examples nested in parameter, request-body, response, and
header content.
- Visit headers nested under media-type encodings.
- Reuse path-item traversal for callbacks.
This pull request was created with the assistance of OpenAI Codex.