Skip to content

Commit

Permalink
Fix bytes in json part (#2724)
Browse files Browse the repository at this point in the history
fix #2701
  • Loading branch information
timotheeguerin authored Dec 4, 2023
1 parent 360add2 commit 81a3b3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}
4 changes: 3 additions & 1 deletion packages/openapi3/src/schema-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter<
return { type: "string", format: "binary" };
}

const refSchema = this.emitter.emitTypeReference(prop.type);
const refSchema = this.emitter.emitTypeReference(prop.type, {
referenceContext: isMultipart ? { contentType: "application/json" } : {},
});
if (refSchema.kind !== "code") {
throw new Error("Unexpected non-code result from emit reference");
}
Expand Down
3 changes: 1 addition & 2 deletions packages/openapi3/test/multipart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ describe("typespec-autorest: multipart", () => {
});
});

// Known issue https://github.com/microsoft/typespec/issues/2701
it.skip("bytes inside a json part will be treated as base64 encoded by default(same as for a json body)", async () => {
it("bytes inside a json part will be treated as base64 encoded by default(same as for a json body)", async () => {
const res = await openApiFor(
`
op upload(@header contentType: "multipart/form-data", address: {city: string, icon: bytes}): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ paths:
$ref: '#/components/schemas/DataMultiPart'
components:
schemas:
AddressMultiPart:
Address:
type: object
required:
- city
Expand All @@ -46,4 +46,4 @@ components:
type: string
format: binary
address:
$ref: '#/components/schemas/AddressMultiPart'
$ref: '#/components/schemas/Address'

0 comments on commit 81a3b3d

Please sign in to comment.