Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
15 stars 41 forks source link

[Bug]: TCGC reports wrong diagnostics "conflicting-multipart-model-usage" for valid multipart cases #1510

Closed msyyc closed 1 month ago

msyyc commented 1 month ago

Describe the bug

For the valid cases, TCGC reports wrong diagnostics "conflicting-multipart-model-usage"

Reproduction

    @service({title: "Test Service"}) namespace TestService;

    model MultiPartRequest {
      id: string;
      profileImage: bytes;
    }

    @post op basic1(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse;
    @put op basic2(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse;

Checklist

msyyc commented 1 month ago

The root cause is that TCGC always set a model with UsageFlags.Input: https://github.com/Azure/typespec-azure/blob/a6365a1770d07b763f5ae9805374cda11085e180/packages/typespec-client-generator-core/src/types.ts#L1658 so it is not proper to distinguish whether a model is used both in common content-type and multipart content-type: https://github.com/Azure/typespec-azure/blob/a6365a1770d07b763f5ae9805374cda11085e180/packages/typespec-client-generator-core/src/types.ts#L1633-L1642.

There are 2 solutions:

weidongxu-microsoft commented 1 month ago

Personal opinion: Make MultipartFormData exclusive to JSON/XML, as all of these relates to the serialization of the model.

msyyc commented 1 month ago

Personal opinion: Make MultipartFormData exclusive to JSON/XML, as all of these relates to the serialization of the model.

After discussion, we pretend to use this solution instead of adding new usage kind. Let me make a PR to fix it later.