[http-server-csharp] Import JsonNodes for record arrays by nightcityblade · Pull Request #11796 · microsoft/typespec · GitHub
Skip to content

[http-server-csharp] Import JsonNodes for record arrays - #11796

Open
nightcityblade wants to merge 2 commits into
microsoft:mainfrom
nightcityblade:fix/issue-11733
Open

[http-server-csharp] Import JsonNodes for record arrays#11796
nightcityblade wants to merge 2 commits into
microsoft:mainfrom
nightcityblade:fix/issue-11733

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Fixes #11733.

Summary

  • unwrap array element types before checking whether a model property maps to JsonObject
  • keep the existing Record<unknown>-only behavior, including for nested arrays
  • add focused coverage for nested Record<unknown> arrays and typed record arrays

This ensures generated models using Record<unknown>[] import System.Text.Json.Nodes, while Record<string>[] continues to use dictionary types without that import.

Verification

  • pnpm --filter @typespec/http-server-csharp exec vitest run src/components/models/models.test.tsx (6 passed)
  • pnpm --filter @typespec/http-server-csharp lint
  • pnpm --filter @typespec/http-server-csharp build
  • pnpm exec prettier --check packages/http-server-csharp/src/components/models/model-helpers.ts packages/http-server-csharp/src/components/models/models.test.tsx

AI-assisted; I reviewed the change and verified the commands above locally.

@azure-pipelines

Copy link
Copy Markdown

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.

Pull request overview

Fixes a bug in the @typespec/http-server-csharp emitter where models containing Record<unknown>[] (including nested arrays) could emit JsonObject[] without adding the required System.Text.Json.Nodes using, causing generated C# to fail compilation.

Changes:

  • Update modelNeedsJsonNodes to unwrap array element types before checking for Record<unknown>.
  • Add a focused unit test ensuring Record<unknown> nested in array properties is detected (and Record<string>[] is not).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/http-server-csharp/src/components/models/model-helpers.ts Unwrap nested array types in modelNeedsJsonNodes so Record<unknown>[] triggers System.Text.Json.Nodes imports.
packages/http-server-csharp/src/components/models/models.test.tsx Adds test coverage for Record<unknown> nested in arrays and ensures typed record arrays don’t trigger JsonNodes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +134 to +147
it("detects Record<unknown> nested in array properties", async () => {
const { JsonObjectArray, StringMapArray } = await runner.compile(t.code`
model ${t.model("JsonObjectArray")} {
items: Record<unknown>[][];
}
model ${t.model("StringMapArray")} {
items: Record<string>[];
}
`);
const tk = $(runner.program);

expect(modelNeedsJsonNodes(tk, JsonObjectArray)).toBe(true);
expect(modelNeedsJsonNodes(tk, StringMapArray)).toBe(false);
});
@pkg-pr-new

pkg-pr-new Bot commented Aug 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: ecc93a0

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-server-csharp
Show changes

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

Import JsonNode collection types when generating models containing record arrays.

Copilot AI review requested due to automatic review settings September 1, 2026 03:03
@nightcityblade

Copy link
Copy Markdown
Contributor Author

Added the required Chronus change description in the latest commit. pnpm exec prettier --check and pnpm chronus verify both pass.

@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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.

[Bug]: [http-server-csharp] Model with a Record<unknown>[] property generates C# that does not compile (missing using System.Text.Json.Nodes;)

2 participants