Skip to content

[http-client-csharp] Build discriminated base description from discriminated base type, not abstract modifier - #11412

Merged
jorgerangel-msft merged 6 commits into
mainfrom
copilot/http-client-csharp-discriminator-message-update
Jul 27, 2026
Merged

[http-client-csharp] Build discriminated base description from discriminated base type, not abstract modifier#11412
jorgerangel-msft merged 6 commits into
mainfrom
copilot/http-client-csharp-discriminator-message-update

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

The discriminator "Please note this is the abstract base class..." description was only emitted when a model carried the Abstract declaration modifier. Whether a discriminated base type is modeled as abstract is an implementation detail — downstream emitters (e.g. provisioning) may not declare it abstract, causing the derived-classes note to be dropped.

Changes

  • ModelProvider: Added IsDiscriminatedBaseType helper — a model with a discriminator property but no discriminator value.
  • BuildDescription: Gates the derived-classes note on IsDiscriminatedBaseType instead of the Abstract modifier, decoupling documentation from abstractness.
  • BuildDeclarationModifiers: Reuses the same helper for the abstract decision, keeping the base emitter's behavior unchanged.
  • Tests: Added DiscriminatedBaseDescriptionIsBuiltEvenWhenNotAbstract, using a ModelProvider subclass that strips Abstract to mimic a downstream emitter and asserting the note is still built.
private bool IsDiscriminatedBaseType =>
    _inputModel.DiscriminatorProperty is not null && _inputModel.DiscriminatorValue is null;

@azure-pipelines

Copy link
Copy Markdown
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.

…scriminated base type, not abstract modifier

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jul 27, 2026
Copilot AI changed the title [WIP] Update discriminator message handling for base types [http-client-csharp] Build discriminated base description from discriminated base type, not abstract modifier Jul 27, 2026
Copilot AI requested a review from jorgerangel-msft July 27, 2026 15:24
@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11412

commit: eb5834f

… and bespoke test provider

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…WhenNotAbstract test

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…ated base type is not abstract

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

@jorgerangel-msft jorgerangel-msft 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.

@copilot ensure we regenerate all the test libraries and all tests are passing

… for abstract and non-abstract

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ensure we regenerate all the test libraries and all tests are passing

Regenerated all test libraries via pwsh ./eng/scripts/Generate.ps1 (Sample-TypeSpec + all Spector projects) — this produced no generated-file changes, since the base emitter still marks discriminated base types as abstract, so the emitted descriptions are unchanged. Verified all tests pass:

  • Microsoft.TypeSpec.Generator.Tests: 1722 passed, 0 failed
  • Microsoft.TypeSpec.Generator.ClientModel.Tests: 1513 passed, 0 failed

@jorgerangel-msft jorgerangel-msft 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.

@jorgerangel-msft
jorgerangel-msft marked this pull request as ready for review July 27, 2026 20:15
@jorgerangel-msft
jorgerangel-msft added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit 9ba642d Jul 27, 2026
30 checks passed
@jorgerangel-msft
jorgerangel-msft deleted the copilot/http-client-csharp-discriminator-message-update branch July 27, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-csharp] discriminator message should be added when the type is a discriminated base instead of checking abstract

3 participants