Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/aaz_dev/swagger/model/schema/cmd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,11 @@ def apply_cls_definitions(self, *cmd_ops):
cmd_op.register_cls(cls_register_map=schema_cls_register_map)

for name, cls_register in schema_cls_register_map.items():
if cls_register.get('implement', None):
if implement := cls_register.get('implement', None):
# typespec operations are parsed from json, so their cls references arrive
# unlinked (swagger links them while building the schema).
for refer in cls_register['refers']:
refer.implement = implement
continue

new_schema = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import unittest

from command.model.configuration import CMDResource
from swagger.controller.command_generator import TypespecCommandGenerator
from utils.base64 import b64encode_str

PATH = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Mock/galleries/{galleryName}"
VERSION = "2026-03-03"


def _put_path_item():
# Shape emitted by typespec-aaz for an ARM LRO put whose 202 repeats the resource body
# (e.g. Microsoft.Compute galleries): the first response owns the definition and the
# following one is a bare cls reference.
resource_schema = {
"type": "object",
"cls": "Gallery_read",
"props": [
{"type": "string", "name": "id", "readOnly": True},
{"type": "string", "name": "location", "required": True},
],
}
return {
"put": {
"operationId": "Galleries_CreateOrUpdate",
"create": {
"operationId": "Galleries_CreateOrUpdate",
"http": {
"path": PATH,
"request": {
"method": "put",
"path": {"params": [
{"type": "string", "name": "galleryName", "required": True},
{"type": "string", "name": "resourceGroupName", "required": True},
{"type": "string", "name": "subscriptionId", "required": True},
]},
"query": {"params": [
{"type": "string", "name": "api-version", "required": True},
]},
"body": {"json": {"schema": {
"type": "object",
"name": "resource",
"required": True,
"clientFlatten": True,
"props": [{"type": "string", "name": "location", "required": True}],
}}},
},
"responses": [
{"statusCode": [200, 201], "body": {"json": {"schema": resource_schema}}},
{"statusCode": [202], "body": {"json": {"schema": {"type": "@Gallery_read"}}}},
{"isError": True, "body": {"json": {"schema": {
"readOnly": True, "type": "@MgmtErrorFormat"}}}},
],
},
},
},
}


class TypespecCommandGeneratorTestCase(unittest.TestCase):

def test_output_from_cls_reference_response(self):
generator = TypespecCommandGenerator()
generator.load_resources([{"path": PATH, "pathItem": _put_path_item()}])
resource = CMDResource({
"id": "/subscriptions/{}/resourcegroups/{}/providers/microsoft.mock/galleries/{}",
"version": VERSION,
"swagger": "mgmt-plane/mock/ResourceProviders/Microsoft.Mock"
f"/Paths/{b64encode_str(PATH)}/V/{b64encode_str(VERSION)}",
})

command_group = generator.create_draft_command_group(
resource, instance_var="$Instance", methods=("put",))

create_command = command_group.commands[0]
self.assertEqual([output.type for output in create_command.outputs], ["object"])
Loading