[http-server-csharp] Import JsonNodes for record arrays - #11796
[http-server-csharp] Import JsonNodes for record arrays#11796nightcityblade wants to merge 2 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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
modelNeedsJsonNodesto unwrap array element types before checking forRecord<unknown>. - Add a focused unit test ensuring
Record<unknown>nested in array properties is detected (andRecord<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.
| 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); | ||
| }); |
commit: |
|
All changed packages have been documented.
Show changes
|
|
Added the required Chronus change description in the latest commit. |
|
nightcityblade please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Fixes #11733.
Summary
JsonObjectRecord<unknown>-only behavior, including for nested arraysRecord<unknown>arrays and typed record arraysThis ensures generated models using
Record<unknown>[]importSystem.Text.Json.Nodes, whileRecord<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 lintpnpm --filter @typespec/http-server-csharp buildpnpm exec prettier --check packages/http-server-csharp/src/components/models/model-helpers.ts packages/http-server-csharp/src/components/models/models.test.tsxAI-assisted; I reviewed the change and verified the commands above locally.