microsoft / microsoft/typespec

how to interpret body in bodyRoot

Open
#4,815 8 comments 0 reactions 0 assignees View on GitHub
compiler:core docs needs-area triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

[Playground Link](https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7DQoNCnVzaW5nIEh0dHA7DQpvcCB0ZXN0KEBib2R5Um9vdCDECToge8URxw1UZXN0fSk6IHZvaWTFQ21vZGVsxRcgew0KICBwcm9wOnN0cmluZzsNCn0%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)
In this tsp
```
op test(@bodyRoot body: {@body body: Test}): void;
```

is the body parameter Test or an anonymous model with a property named body whose type is Test?
the openapi3 emitter result shows the former
![Image](https://github.com/user-attachments/assets/f2114c9a-4f06-44bd-9236-7e4af0459650)

but the type graph shows the later?
![Image](https://github.com/user-attachments/assets/c8df7ebc-7df5-45d5-b6e8-463455e81aa4)

it's a real case https://github.com/Azure/azure-rest-api-specs/blob/ca4b71ab0e3bb7e4c44b44bf4d84d9c51f7b8264/specification/workloads/Workloads.SAPVirtualInstance.Management/SAPCentralServerInstance.tsp#L61, and seems quite common as azure operation template uses bodyRoot here
https://github.com/Azure/typespec-azure/blob/main/packages/typespec-azure-resource-manager/lib/operations.tsp#L502

According to https://github.com/microsoft/typespec/issues/2868#issue-2110782074 it feels like the former is correct?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.