-
Notifications
You must be signed in to change notification settings - Fork 230
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
[Ask] Do we allow mixed usage for file
models among mfd and non-mfd operations?
#5376
Comments
My understanding:
|
I think this is the intention of how
|
@markcowl Any idea if we allow to share the models among mfd and non-mfd operations for unbranded? |
@markcowl I want to point out the previous bytes related discussion is still pending on typespec side bytes loop |
file
models among mfd and non-mfd operations?
All three of these cases can coexist. Just to clarify, in case 2, File cannot be the type of the multipart body itself, so I assume we are talking about when Here are the cases: // Payload: { filename?: string, contentType?: string, contents: base64 }
op case1(@header contentType: "application/json", @body data: Http.File);
// Payload: Multipart Form Data, array of files as parts with name `files`
// Part payload: byte stream
op case2(@header contentType: "multipart/form-data", @multipartBody: { files: HttpPart<Http.File>[] });
// Payload: Multipart Form Data, array of JSON objects as parts with name: `files`.
// Part Payload: { file: { filename?: string, contentType?: string, contents: base64 } }
op case3(@header contentType: "multipart/form-data", @multipartBody: { files: HttpPart<{ file: Http.File }>[] }); In general, when In interface File {
filename?: string;
contentType?: string;
contents: Uint8Array;
} The serialization/deserialization of the type changes depending on the content-type it's referenced from, but it always ends up in that shape. If I had to generate a different representation of the type for multipart vs. JSON, then I'd add a suffix or prefix to the type names to distinguish them, i.e. @bterlson @markcowl I think there is probably a fourth case, where the content-type is unspecified and the body is exactly op case4(@bodyRoot file: Http.File); In this case we may want to get |
Background
Below cases are relevant to multipart/form-data I've derived from todo spec and I'd like to confirm if we have any limitation on model sharing among mfd and non-mfd operations in typespec side?
I am asking because if the model is used in a mfd operation, emitters may handle them differently and generate different APIs for that model. And previously tcgc tried to add some limitations on model mixed usage and would report errors(tcgc diagnostic code) and I guess this is for Azure scope? Then how about unbranded?
playground here
Todo Spec Cases
Say we have models with
TodoFileAttachment
. The first question would be:File
(spec) to be used as non-mfd operations for exampleop createJson(@header contentType: "application/json", contents: File): void;
?I would assume yes, since this is todo's pr demoed. Then we could have the model referenced by mfd and non-mfd ops.
Here are the questions on how to intercept them:
contents
in File, should we intercept as base64 string? How about it is used in other content type? Will we interceptbytes
differently?Thinking in File
Option 1: Take
File
as a generic file conceptCurrently
File
is a quite generic name and almost every languages have file relevant operations and in typespec we leveragemodel
to representFile
but without any limitation on that. Like in todo example bothcreateForm
andcreateJson
want to upload files but one is file and the other is a record. This caused misleadings because we only takeFile
as a real file object in multipart operation. In other situations it is just a model with three properties.I was wondering if we could take
File
just as file in any cases, maybe another built-in scalar type, kind ofbytes
type in TypeSpec but having semantics to link with a file object.Option 2: Take
File
only for a file part in MFDOr we could limit the scope to multipart file, only allowed to use under
@multipartBody
. Then maybe it's better to rename asMultipartFile
?Not sure if we are allowed to extend with more properties or spread into another models.
The text was updated successfully, but these errors were encountered: