Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to interpret body in bodyRoot #4815

Open
qiaozha opened this issue Oct 22, 2024 · 4 comments
Open

how to interpret body in bodyRoot #4815

qiaozha opened this issue Oct 22, 2024 · 4 comments
Labels
compiler:core Issues for @typespec/compiler docs Improvements or additions to documentation needs-area triaged:core
Milestone

Comments

@qiaozha
Copy link
Member

qiaozha commented Oct 22, 2024

Playground Link
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

but the type graph shows the later?
Image

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 #2868 (comment) it feels like the former is correct?

@qiaozha
Copy link
Member Author

qiaozha commented Oct 22, 2024

Can we have a linter rule to prevent the usage of body in bodyRoot? I wonder if there's a real case that customer has to write their typespec this way?

In the above case, the Azure operation template has been changed from @body to @bodyRoot according to this https://github.com/Azure/typespec-azure/pull/708/files pr, but is it really expected? I wonder if we can change the service typespec instead of changing the operation template here?

@timotheeguerin
Copy link
Member

The azure specs shouldn't use @Body here it has no value and just pass start request

@markcowl markcowl added docs Improvements or additions to documentation compiler:core Issues for @typespec/compiler labels Oct 22, 2024
@markcowl markcowl added this to the Backlog milestone Oct 22, 2024
@allenjzhang
Copy link
Member

@qiaozha , do you know the reason for them to declare this way? Why wouldn't it work just using StartRequest as Request parameter?

  start is ArmResourceActionAsync<
    SAPCentralServerInstance,
    {
      @doc("SAP Central Services instance start request body.")
      @body
      body?: StartRequest;
    },
    Foundations.OperationStatusResult
  >;

@qiaozha
Copy link
Member Author

qiaozha commented Oct 23, 2024

My guess is they want to override the body description, I can double confirm with the service team. But if service team should not use @body decorator in the operation template, would it be an indicator that we should add this linter rule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler docs Improvements or additions to documentation needs-area triaged:core
Projects
None yet
Development

No branches or pull requests

4 participants