Skip to content

fix(http-server-csharp): align error constructor types - #11902

Open
sophia-ramsey wants to merge 1 commit into
mainfrom
sramsey/csharp-record-parameter-types
Open

fix(http-server-csharp): align error constructor types#11902
sophia-ramsey wants to merge 1 commit into
mainfrom
sramsey/csharp-record-parameter-types

Conversation

@sophia-ramsey

Copy link
Copy Markdown
Member

This pull request addresses the way error model constructors are generated in the C# server emitter, ensuring that the constructor parameters use the correct generated property types for all supported shapes (records, arrays, tuples, and nullable unions). It also improves detection of when error models require JsonObject/JsonNodes imports and removes legacy type string generation logic. Comprehensive tests are added to verify the new behavior.

Error model constructor improvements

  • Error model constructors now use generated property types for parameters, including support for records, arrays, tuples, and nullable unions, ensuring accurate C# type mapping. [1] [2]

Improved detection for JsonObject usage

  • Enhanced the modelNeedsJsonNodes function to recursively detect when a model or any of its inherited properties require JsonObject (for nested or inherited record types), and updated its usage to include inherited properties for root error models. [1] [2]

Code cleanup and refactoring

  • Removed the legacy getCSharpTypeString function in favor of using the TypeExpression component for type rendering, simplifying type handling logic. [1] [2]

Testing

  • Added comprehensive tests to verify that error model constructors are generated with the correct parameter types and that necessary using statements for JsonObject are included when required by inherited properties.

Co-authored-by: Copilot <175728472+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@11902

commit: dbe8609

@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 ✏️

Use generated property types for error model constructor parameters, including records, arrays, tuples, and nullable unions.

@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 are scoped, consistent with existing emitter/type-rendering behavior, and include targeted tests plus a valid .chronus fix entry.

Pull request overview

This PR fixes C# http-server emitter error model constructor generation so constructor parameters use the same rendered C# types as the emitted model properties (covering records, arrays, tuples, and nullable unions), and updates JsonNodes import detection to include inherited properties for root error models.

Changes:

  • Switched error constructor parameter type rendering from legacy string mapping to the shared TypeExpression renderer.
  • Enhanced modelNeedsJsonNodes to recursively detect JsonObject usage through nested types and (optionally) inherited properties, and wired it for root error models.
  • Added tests validating constructor parameter types and System.Text.Json.Nodes import emission for inherited record properties.
File summaries
File Description
packages/http-server-csharp/src/components/models/models.tsx Passes a “root error model” flag to include inherited properties when deciding whether System.Text.Json.Nodes is needed.
packages/http-server-csharp/src/components/models/model-helpers.ts Refactors modelNeedsJsonNodes into a recursive type-walk with optional base-model traversal; removes legacy getCSharpTypeString.
packages/http-server-csharp/src/components/models/error-models.tsx Uses TypeExpression for error constructor parameter types to align with generated property types.
packages/http-server-csharp/src/components/models/error-models.test.tsx Adds coverage for structured constructor parameter typing and inherited JsonObject import detection.
.chronus/changes/fix-csharp-error-constructor-types-2026-9-8.md Adds a fix changeset for @typespec/http-server-csharp describing the user-visible behavior change.
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.

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