Azure / Azure/typespec-azure

[TCGC] a helper function to show whether a type is wrapped by `HttpPart`

Open
#1,488 4 comments 0 reactions 1 assignee Claimed by @msyyc View on GitHub
design:proposed lib:tcgc
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

For the property `temperature`, TCGC emits its type to a model. The model contains properties for `body` and `contentType`. Emitters may only care about type of `body`. Then how to judge whether we need to parse the property type specially?

```
op float(
@header contentType: "multipart/form-data",
@multipartBody body: {
temperature: HttpPart<{
@body body: float64;
@header contentType: "text/plain";
}>;
},
): NoContentResponse;
```

One solution is that judge its `kind` like [here](https://github.com/Azure/autorest.python/pull/2815/commits/574ec8dacb91c1210d95fafff95e30da7511f048#diff-97e08823c94cd89b94201c510751899a6390cc43cde84849e1d744f63bf6527c). However, it is not that robust. Since common body may could also define property with `prop: {@body body: string}` like [here](https://cadlplayground.z22.web.core.windows.net/cadl-azure/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZdmVyc2lvbmluZ8wfYXp1cmUtdG9vbHMvyCstxhVjb3JlIjsKCnVzaW5nIFR5cGVTcGVjLkh0dHA70BVSZXN00RVWyXLIG0HEWS5Db3Jl0hIuVHJhaXRzOwoKQHVzZUF1dGgoCiAgQXBpS2V5xA48xgtMb2NhdGlvbi5oZWFkZXIsICJhcGkta2V5Ij4gfCBPxCoyxS9bCiAgICB7xQYgIOQA3DrHH0Zsb3fkAKUuaW1wbGljaXQsxyVhdXRob3JpesVhVXJsOiAi5AFoczovL2xvZ2luLmNvbnRvc28uY29tL2NvbW1vbi9vxDUyL3YyLjAvyEBlIshSc2NvcGVzOiBbyUl3aWRnZXTNSi5kZWZhdWx0Il3GN30KICBdPgopCkBzZXJ2aWNlKOQAxnRpdGxlOiAiQ8Y6IFfFSSBNYW5hZ2VyIiwKfccxZXLkATkie2VuZHBvaW50fcd05QCV0D9BUElzxRnEYyAgLyoqIApTdXDkAh5lZMglU%2BYAh3MgyFNzIChwcm90b2NvbCBhbmQgaG9zdG5hbWUsIGZvciBleGFtcGxlOgrpAPRlc3R1cy5hcGku8gD%2FKS4KICovxX7IXzogc3RyaW5n5ACYfeQBCOcCvGVkKOcAvy7mAJrnAP3oAmpzKQrkAIZzcGFjZSDVKjsKCuQA41RoySDvAUgg5wFzIMdzLuQAnGVudW0gyGTlASrERccRIDIwMjItMDgtMzHELCAg5AK%2FRGVwZW5kZW5jeSjrAuLIQy52MV8wX1ByZXZpZXdfMikKICBgyUYwYCwKfQoKb3AgYWPkAogoYm9keTrFdkDECyDKEM4SZmxvYXQzMuUBNH0pOiB2b2lkOwo%3D&e=%40azure-tools%2Ftypespec-autorest&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40azure-tools%2Ftypespec-azure-rulesets%2Fdata-plane%22%5D%7D%7D).

So maybe TCGC need provide a helper funcion (e.g. `isWrappedByHttpPart` to help emitters judge whether need special logic for the property type.

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.