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

[tcgc] add support for a MultiPartFile type #165

Closed
iscai-msft opened this issue Jan 24, 2024 · 2 comments · Fixed by #166
Closed

[tcgc] add support for a MultiPartFile type #165

iscai-msft opened this issue Jan 24, 2024 · 2 comments · Fixed by #166
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@iscai-msft
Copy link
Contributor

Currently, our code at large assumes models to be JSON objects. Since we need to support multipart/form-data, this is not the case. For example, in the following model

model JsonModel {
  prop: bytes
}

prop will default to a b64 encoded string, which is the correct behavior. However, in a model used for multipart, we would instead want to recognize the bytes as being for a file, and also add information about content-type and filename.

model MultipartInputModel {
  picture: bytes;
}

So proposal is to add a new primitive type like the following, which would be the above property picture's type

interface MultipartFormDataFile:
  kind: "multipartformdatafile";
  fileStream: SdkBytesType (with default encoding of `binary`, still has access to @encodedType);
  filename: string | undefined;
  contentType: string | undefined;
@iscai-msft iscai-msft added P0 - Blocking lib:tcgc Issues for @azure-tools/typespec-client-generator-core library labels Jan 24, 2024
@iscai-msft iscai-msft self-assigned this Jan 24, 2024
@iscai-msft
Copy link
Contributor Author

Notes:

  1. raise a diagnostic error if we have a model used both as multipart and as json.
  2. Typing of a MultipartFormDataFile will be FileContent | [string, FileContent] | [string, FileContent, string]
  3. We do not recursively set models as multipart form data. If a multipart model has a property that is a model, that property off model will be JSON

@weidongxu-microsoft
Copy link
Member

Looks good. Java currently would have different class for different multipart file field (i.e. image field generates ImageFileDetails class), but that would be our internal processing and it could change in future if this gets to azure-core.

I assume 2nd point
Typing of a MultipartFormDataFile will be FileContent | [string, FileContent] | [string, FileContent, string]
Just means a combination the types of fileStream, filename, contentType?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants