-
Notifications
You must be signed in to change notification settings - Fork 329
Add OpenAPI 3.2.0 defaultMapping support for discriminated unions #9262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: baywet <[email protected]>
- Add defaultVariant to DiscriminatedUnion return value in compiler - Create OpenAPI 3.2 schema emitter extending 3.1 emitter - Support defaultMapping property in discriminator for OpenAPI 3.2.0 - Include default variant in oneOf array for all versions - Add default variant discriminator value to mapping for versions < 3.2 - Use defaultMapping instead of mapping entry for OpenAPI 3.2.0 Co-authored-by: baywet <[email protected]>
Co-authored-by: baywet <[email protected]>
commit: |
|
@copilot add the following words to the cspell configuration, do not make any other changes:
|
Co-authored-by: baywet <[email protected]>
|
All changed packages have been documented.
Show changes
|
|
/azp run typespec - PR Tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
You can try these changes here
|
Implementation Plan for OpenAPI 3.2.0 defaultMapping Support ✅
Summary
This PR implements support for OpenAPI 3.2.0
defaultMappingproperty in discriminated unions as specified in the OpenAPI 3.2.0 specification.Problem
When a discriminated union has a default variant (unnamed variant), it was previously:
oneOfarrayThis meant the default variant was essentially lost in the OpenAPI output.
Solution
For OpenAPI 3.2.0:
oneOfarraydiscriminator.defaultMappingpropertymappingobjectFor OpenAPI 3.0.0 and 3.1.0:
oneOfarraymappingobject (backward compatibility)Example TypeSpec Input:
OpenAPI 3.2.0 Output:
Changes Made:
packages/compiler/src/core/helpers/discriminator-utils.ts
defaultVariantwas not being returned inDiscriminatedUnionstructurepackages/openapi3/src/schema-emitter-3-2.ts (NEW)
discriminatedUnionmethod withdefaultMappingsupportpackages/openapi3/src/schema-emitter.ts
oneOf#addDefaultVariantToMappingmethod for versions < 3.2#getStringValueFromTypehelper methodpackages/openapi3/src/openapi-spec-mappings.ts
packages/openapi3/test/union-schema.test.ts
.chronus/changes/openapi3-default-mapping-2025-12-22-14-42-58.md
cspell.yaml
Test Results:
✅ All OpenAPI 3 tests passing (2356 tests)
✅ All compiler tests passing (3531 tests)
✅ No linting errors
✅ Code formatted with prettier
✅ No breaking changes to existing functionality
References:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.