Skip to content

Add union extends discriminated union Spector scenarios - #12288

Open
Chenjie Shi (tadelesh) wants to merge 2 commits into
microsoft:mainfrom
tadelesh:feat/discriminated-union-spector
Open

Chenjie Shi (tadelesh) wants to merge 2 commits into
microsoft:mainfrom
tadelesh:feat/discriminated-union-spector

Conversation

@tadelesh

@tadelesh Chenjie Shi (tadelesh) commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Add 18 GET/PUT Spector contracts for discriminated unions with explicit union extends model constraints and nominally inherited alternatives.

  • Cover declared and injected discriminators, custom discriminator names and wire tags, enum discriminator types, direct/transitive inheritance, and recursive model/array/dictionary/nullable references.
  • Preserve existing unconstrained discriminated-union scenarios and regenerate the scenario summary.
  • Make Spector's scenario and mock validators honor per-scenario project feature flags, including union-extends, while preserving existing validation imports and emitter/linter behavior. Surface configuration diagnostics and add virtual-filesystem regression tests.

These scenarios define wire contracts, not language-specific SDK representations. Envelope scenarios are deferred.

Related: Azure/typespec-azure#5703.

Validation

  • Relevant package/dependency build: pnpm -r --filter "@typespec/http-specs..." build.
  • Spector regression suite: 40 tests passed.
  • Scenario and mock API validation passed for the complete HTTP-specs corpus.
  • All 18 remaining contracts passed against the Spector mock server.
  • Spelling checks, repository-wide pnpm format, pnpm lint, documentation regeneration, and git diff --check passed.

The full pnpm build is blocked by an unrelated typespec-vs NuGet restore failure (NU1301, TLS handshake failure contacting api.nuget.org).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fe48cf1c-c567-4896-b51d-5ae7233ae454
Copilot AI balanced review requested due to automatic review settings October 16, 2026 02:34
@tadelesh Chenjie Shi (tadelesh) added the lib:http-specs For issues/prs related to the @typespec/http-specs package label Oct 16, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the spector Issues related to spector and the spec sets label Oct 16, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-specs@12288
npm i https://pkg.pr.new/@typespec/spector@12288

commit: e914166

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The contracts, mocks, and configuration handling are consistent, with focused regression coverage and no blocking issues identified.

0 open findings

What changed in this PR

Adds 22 Spector wire contracts for constrained discriminated unions and enables configuration-aware validation.

Changes:

  • Covers inherited alternatives, discriminator variations, envelopes, and recursive containers.
  • Honors scenario feature flags and reports configuration diagnostics while preserving validation behavior.
  • Adds regression tests, documentation, and package changelogs.
File Description
packages/​spector/​test/​compile-scenario.test.ts Tests feature flags and validation configuration.
packages/​spector/​src/​spec-utils/​compile-scenario.ts Centralizes configuration-aware compilation.
packages/​spector/​src/​scenarios-resolver.ts Uses the shared compilation helper.
packages/​spector/​src/​actions/​validate-mock-apis.ts Applies configuration-aware mock validation.
packages/​spector/​README.md Documents scenario feature flags.
packages/​http-specs/​specs/​type/​union/​discriminated/​extends/​tspconfig.yaml Enables union-extends.
packages/​http-specs/​specs/​type/​union/​discriminated/​extends/​mockapi.ts Defines mocks for all 22 contracts.
packages/​http-specs/​specs/​type/​union/​discriminated/​extends/​main.tsp Defines constrained-union scenarios.
packages/​http-specs/​spec-summary.md Documents the new endpoints and payloads.
.chronus/​changes/​spector-scenario-project-features.md Records the Spector validation fix.
.chronus/​changes/​discriminated-union-extends-scenarios.md Records the new HTTP scenarios.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-specs
  • ✅ @typespec/spector
Show changes

@typespec/http-specs - feature ✏️

Add Spector scenarios for discriminated unions with model constraints, covering explicit and injected discriminators, custom wire tags, enum discriminators, transitive inheritance, and recursive containers.

@typespec/spector - fix ✏️

Honor per-scenario project feature flags when compiling scenarios and validating mock APIs, and report configuration diagnostics.

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Comment thread .chronus/changes/discriminated-union-extends-scenarios.md Outdated
Comment thread packages/spector/test/compile-scenario.test.ts
Comment thread packages/http-specs/specs/type/union/discriminated/extends/main.tsp Outdated
Remove deferred envelope contracts and changelog examples, and use a virtual compiler filesystem in scenario configuration tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: fe48cf1c-c567-4896-b51d-5ae7233ae454
Copilot AI balanced review requested due to automatic review settings October 16, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking issues remain; the retained changelog documentation suggestion is minor.

1 open finding

🧠 Review effort: Balanced

Comment thread .chronus/changes/discriminated-union-extends-scenarios.md
@weidongxu-microsoft

Copy link
Copy Markdown
Contributor

Could we separate recursive-union coverage from explicit-null preservation?

nullableFriend?: Pet | null permits omission, but Recursive.put and its @scenarioDoc require "nullableFriend": null exactly. With the fixed Java emitter, that optional null field is omitted, so the mock rejects the request with HTTP 400.

Recursive subtype dispatch for properties, arrays and dictionaries, plus a non-null nullable-union round trip, passed in both sync and async checks. Consider using a non-null Pet for nullableFriend in this fixture and updating @scenarioDoc, with explicit-null preservation covered separately.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:http-specs For issues/prs related to the @typespec/http-specs package spector Issues related to spector and the spec sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants