Add support for OpenAPI discriminator in unions#172
Merged
andrewzolotukhin merged 3 commits intodevelopmentfrom Apr 15, 2026
Merged
Add support for OpenAPI discriminator in unions#172andrewzolotukhin merged 3 commits intodevelopmentfrom
andrewzolotukhin merged 3 commits intodevelopmentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds end-to-end support for emitting the OpenAPI discriminator keyword for discriminated unions across @cleverbrush/schema introspection and @cleverbrush/schema-json / @cleverbrush/server-openapi spec generation, with accompanying tests and documentation updates.
Changes:
- Expose
discriminatorPropertyNameviaUnionSchemaBuilder.introspect()when a union is detected as discriminated. - Emit
discriminator: { propertyName, mapping? }alongsideanyOfintoJsonSchema()for discriminated unions (mapping when branches are$refs). - Add tests and update docs/site content to document and validate discriminator behavior in generated OpenAPI/JSON Schema.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| website/app/server-openapi/page.tsx | Adds docs note that discriminated unions emit OpenAPI discriminator. |
| website/app/schema/sections/discriminated-unions.tsx | Documents JSON Schema/OpenAPI output for discriminated unions, including discriminator. |
| website/app/schema-json/page.tsx | Updates feature table to mention discriminator emission for unions. |
| libs/server-openapi/src/generateOpenApiSpec.test.ts | Adds OpenAPI-spec tests asserting discriminator emission and $ref mapping behavior. |
| libs/server-openapi/README.md | Documents discriminated unions and discriminator output in generated OpenAPI specs. |
| libs/schema/src/builders/UnionSchemaBuilder.ts | Adds discriminatorPropertyName to union introspection. |
| libs/schema/src/builders/UnionSchemaBuilder.test.ts | Adds tests for discriminatorPropertyName introspection behavior. |
| libs/schema/src/builders/SchemaBuilder.ts | Rewords .schemaName() docs to emphasize metadata role and broader tooling use. |
| libs/schema-json/src/types.ts | Extends JSON schema node typing to allow optional discriminator alongside anyOf. |
| libs/schema-json/src/toJsonSchema.ts | Emits discriminator (and optional mapping) for discriminated unions. |
| libs/schema-json/src/toJsonSchema.test.ts | Adds tests for discriminator emission, nullable unions, and $ref mapping. |
| libs/schema-json/README.md | Documents discriminator emission behavior for discriminated unions. |
| .changeset/discriminated-union-discriminator.md | Changeset describing the new feature and affected packages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Description
Type of Change
Checklist
npm run lintand fixed any issuesnpm run testand all tests passnpx changeset) if this changes package behavior