Skip to content

fix: link cls references when generating commands from TypeSpec - #574

Merged
Ethan Yang (necusjz) merged 1 commit into
Azure:devfrom
huiii99:fix/typespec-cls-reference
Sep 22, 2026
Merged

Ethan Yang (necusjz) merged 1 commit into
Azure:devfrom
huiii99:fix/typespec-cls-reference

Conversation

@huiii99

Copy link
Copy Markdown
Member

Problem

AddTypespec returns 500 (AssertionError in _build_output_type_schema) for some resources, e.g. Microsoft.Compute ComputeGallery 2026-03-03 galleries / image versions.

Root cause

For an ARM LRO put whose 202 carries the resource body, the emitter converts the model twice: the first response owns the definition ("cls": "Gallery_read") and the later one is a bare reference ({"type": "@Gallery_read"}). Swagger links such references while building the schema, but TypeSpec operations are parsed from json and arrive unlinked - and generate_outputs() runs before CMDCommand.link(), so the output built from the 202 reference has no implement.

Fix

Link the references in CMDBuilder.apply_cls_definitions(), which is shared by all three generation entry points and is a no-op for swagger.

Testing

  • New regression test fails before / passes after.
  • Generated command groups are byte-identical before/after for 562 swagger resources (datafactory, network, monitor, compute).

Typespec operations are parsed from json, so their cls references arrive
without `implement` set, while the swagger builder links them while it
builds the schema. `generate_outputs()` runs before `CMDCommand.link()`,
so a response body that is a bare cls reference - e.g. the body carrying 202
of the ARM LRO put of Microsoft.Compute galleries - hit an AssertionError in
`_build_output_type_schema`.
@necusjz
Ethan Yang (necusjz) merged commit 31379e6 into Azure:dev Sep 22, 2026
5 checks passed
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