Skip to content

Add support for OpenAPI discriminator in unions#172

Merged
andrewzolotukhin merged 3 commits intodevelopmentfrom
feat/openapi-schema-descriminator
Apr 15, 2026
Merged

Add support for OpenAPI discriminator in unions#172
andrewzolotukhin merged 3 commits intodevelopmentfrom
feat/openapi-schema-descriminator

Conversation

@andrewzolotukhin
Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / internal improvement

Checklist

  • I've added tests for my changes
  • I've run npm run lint and fixed any issues
  • I've run npm run test and all tests pass
  • I've added a changeset (npx changeset) if this changes package behavior

Copilot AI review requested due to automatic review settings April 15, 2026 08:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 discriminatorPropertyName via UnionSchemaBuilder.introspect() when a union is detected as discriminated.
  • Emit discriminator: { propertyName, mapping? } alongside anyOf in toJsonSchema() 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.

Comment thread libs/schema-json/src/toJsonSchema.ts Outdated
Comment thread libs/server-openapi/README.md Outdated
andrewzolotukhin and others added 2 commits April 15, 2026 11:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@andrewzolotukhin andrewzolotukhin merged commit dfc8834 into development Apr 15, 2026
1 check passed
@andrewzolotukhin andrewzolotukhin deleted the feat/openapi-schema-descriminator branch April 15, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants