Skip to content

fix(http-server-csharp): honor models-only output - #11907

Open
sophia-ramsey wants to merge 3 commits into
mainfrom
sramsey/csharp-models-only
Open

fix(http-server-csharp): honor models-only output#11907
sophia-ramsey wants to merge 3 commits into
mainfrom
sramsey/csharp-models-only

Conversation

@sophia-ramsey

Copy link
Copy Markdown
Member

This pull request updates the @typespec/http-server-csharp emitter to fully support the output-type: models option, ensuring that only models and their required support files are emitted when this option is set. The implementation introduces a new option to control operation canonicalization, updates the emitter logic to honor the models-only output, and adds comprehensive tests to verify the new behavior.

Enhancements to models-only output:

  • The emitter now checks for the output-type: models option and, when enabled, emits only models and essential support files, skipping controllers, operations, mocks, and project files. [1] [2] [3]

Service type resolution improvements:

  • Added a ServiceTypeResolutionOptions interface and updated the resolveServiceTypes function to accept a canonicalizeOperations flag, allowing it to skip HTTP operation canonicalization when only models are being emitted. [1] [2] [3]

Testing and validation:

  • Introduced new tests to ensure that when output-type: models is set, only model files and required support files are generated, and no controllers, operations, mocks, or project files are emitted.
  • Added a unit test to verify that operation canonicalization is skipped when disabled.

Documentation:

  • Added a change note describing the fix and its effect.

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

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-server-csharp@11907

commit: a8a4a67

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

@typespec/http-server-csharp - fix ✏️

Honor output-type: models by emitting only models and their required support files.

@azure-sdk-automation

azure-sdk-automation Bot commented Sep 9, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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 changes correctly gate non-model outputs for output-type: models, avoid unnecessary canonicalization, and include targeted tests plus a valid .chronus fix entry.

Pull request overview

This PR updates the @typespec/http-server-csharp emitter to correctly honor the output-type: models option by suppressing non-model artifacts (controllers, operations, mocks, project files, and docs) while still emitting models plus required shared support code.

Changes:

  • Gate controller/interface generation, Program.cs, and documentation emission behind a modelsOnly check in the emitter entrypoint.
  • Add a ServiceTypeResolutionOptions flag to skip HTTP operation canonicalization when operation artifacts won’t be emitted.
  • Add/extend tests to verify models-only output behavior and that canonicalization is not invoked when disabled.
File summaries
File Description
packages/http-server-csharp/test/emitter.test.ts Adds an integration-style emitter test asserting that output-type: models only emits models + required support files and skips controllers/ops/mocks/project/docs.
packages/http-server-csharp/src/service-resolution.ts Introduces ServiceTypeResolutionOptions and conditionally skips operation canonicalization when configured.
packages/http-server-csharp/src/service-resolution.test.ts Adds a unit test to validate canonicalization is skipped (and HttpCanonicalizer.canonicalize is not called) when disabled.
packages/http-server-csharp/src/emitter.tsx Implements modelsOnly gating for operation/controller/program/docs emission and passes canonicalization option accordingly.
.chronus/changes/fix-csharp-models-only-output-2026-9-8.md Adds a fix changelog entry for the user-visible behavior correction.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@timotheeguerin

Copy link
Copy Markdown
Member

Models-only output still appears to include an ASP.NET-dependent action filter. The unconditional <JsonConverters /> call also emits HttpServiceExceptionFilter, including its Microsoft.AspNetCore.Mvc imports and IActionFilter/IOrderedFilter dependencies.

Even a simple model Pet { name: string; } with output-type: models therefore carries controller infrastructure into the generated output. Consuming those files in a normal Microsoft.NET.Sdk class library requires ASP.NET references, despite only requesting models.

Could we separate the HttpServiceException base class, which @error models need, from the action filter and its ASP.NET imports, and emit the filter only when generating server output?

Copilot AI review requested due to automatic review settings September 11, 2026 18:34

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.

🟡 Changes recommended

Add explicit framework usings to HttpServiceException before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 9/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 11, 2026 22:28

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 unresolved review comments were supplied, and the changes include focused tests and snapshots.

Review details
  • Files reviewed: 9/11 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

3 participants