fix-binary-in-multipart-form-data #2056
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #2045
Currently, we will try to treat binary bytes the same as other encoding to use stringToUint8Array and unit8ArrayToString util to convert it, which is incorrect,
For binary in RLC layer,
if it's in input model, we should generate it as
string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream
,if it's in output model, we will generate it as
Uint8Array
For binary in Moular layer, current implemtation is treat it as Uint8Array regardless input or output.
Another change in this pr is that, previously, we will speculate if a bytes by default means binary data in the context of multipart/form-data request. As this is not yet decided by microsoft/typespec#2370, we will not do such assumption.
One more thing here, in the past swagger generation, because there's no way to express all those parts together in the multipart/form-data request, we have to manual build the body parameter, but in typespec, we naturally support to use model to group all parts for multipart/form-data request, we don't need this manual build body parameter step now. that's why I delete the
transformMultiFormBody
function in parameters transform.If that model is defined anonymously, we will just generate a anonymously model.
If that model has a name, we will just give it a name and put it into the models.ts