Repository navigation
fix(openapi3): reduce visibility context of array declarations - #12300
Hardik K (hardikkaurani) wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hello Timothee Guerin (@timotheeguerin), I have submitted this pull request to resolve issue #12198 regarding named array models receiving unexpected visibility suffixes (such as Following the pattern established for other declaration kinds and template instantiations, this PR overrides All regression tests, prettier formatting, and oxlint checks pass cleanly, and a Chronus changelog entry has been included. Please review when convenient. Thank you for your time. |
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix follows existing context-reduction behavior, includes regression coverage, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Fixes #12198 by preserving canonical names for named array schemas referenced through both collection and direct operations.
Changes:
- Applies existing visibility-context reduction to array declarations.
- Adds regression coverage for schema names and references.
- Adds an OpenAPI3 fix changelog entry.
| File | Description |
|---|---|
| packages/openapi3/test/metadata.test.ts | Verifies canonical array schema naming and references. |
| packages/openapi3/src/schema-emitter.ts | Reduces array declaration reference context. |
| .chronus/changes/fix-openapi3-array-declaration-visibility-context.md | Documents the naming fix. |
Review effort: Balanced
Fixes #12198
Problem
When a named array model (e.g.
model Range is int32[][]) is referenced in both a collection operation (Foo[]) and direct operation (Foo), it is emitted under a suffixed name (such asRangeItem) instead of its canonical declaration name.In
@typespec/openapi3,SchemaEmitteroverridesmodelDeclarationReferenceContext,modelInstantiationReferenceContext,scalarDeclarationReferenceContext,enumDeclarationReferenceContext, andunionDeclarationReferenceContext, all of which callreduceContextso that a reference to a type not transformed by visibility collapses back to the declaration's context.However,
arrayDeclarationReferenceContextwas not overridden inSchemaEmitter. When the array model is reached through an array item context (Foo[]withVisibility.Item), the declaration retainedVisibility.Item. BecausegetUsage()reports multiple visibility states,#createDeclarationappends anItemsuffix, resulting inRangeItem.Fix
Override
arrayDeclarationReferenceContextinOpenAPI3SchemaEmitterBaseto callreduceContext(array). WhenisTransformedis false,reduceContextcollapses the visibility back, avoiding unnecessary suffixed declarations for named array models.The schema output for the reproduction in #12198 now correctly emits
FooandRangewithout an artificialRangeItemsuffix.Tests
Added
named array model referenced by collection and direct operations is emitted oncetopackages/openapi3/test/metadata.test.ts.mainbefore fix: schemas producedFoo,RangeItem.Foo,Rangewith property$ref: "#/components/schemas/Range".metadata.test.ts), andprettier --check+oxlintare clean..chronus/changes/fix-openapi3-array-declaration-visibility-context.md.