Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/typespec-aaz/src/convertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
CMDIdentityObjectSchemaBase,
CMDBooleanSchemaBase,
CMDAnyTypeSchemaBase,
CMDBinarySchema,
} from "./model/schema.js";
import { reportDiagnostic } from "./lib.js";
import { getExtensions, getOpenAPITypeName, isReadonlyProperty } from "@typespec/openapi";
Expand Down Expand Up @@ -373,9 +374,6 @@ function extractHttpRequest(
if (body.bodyKind === "multipart") {
throw new Error("NotImplementedError: Multipart form data payloads are not supported.");
}
if (isBinaryPayload(body.type, consumes)) {
throw new Error("NotImplementedError: Binary payloads are not supported.");
}
if (consumes.includes("multipart/form-data")) {
throw new Error("NotImplementedError: Multipart form data payloads are not supported.");
}
Expand Down Expand Up @@ -413,6 +411,12 @@ function extractHttpRequest(
clientFlatten: true,
} as CMDObjectSchema;
}
if (isBinaryPayload(body.type, consumes)) {
schema = {
...schema,
type: "binary",
} as CMDBinarySchema;
}
request.body = {
json: {
schema,
Expand Down
49 changes: 49 additions & 0 deletions src/typespec-aaz/test/http-request.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { TestHost, BasicTestRunner } from "@typespec/compiler/testing";
import { describe, expect, it, beforeEach } from "vitest";
import { createTypespecAazTestHost, createTypespecAazTestRunner, compileTypespecAAZOperations } from "./test-aaz.js";
import { findObjectsWithKey } from "./util.js";

describe("http request parsing", () => {
let host: TestHost;
let runner: BasicTestRunner;

beforeEach(async () => {
host = await createTypespecAazTestHost();
runner = await createTypespecAazTestRunner(host);
});

it("validate http request body with bytes", async () => {
const code: string = `
@versioned(Versions)
@service(#{ title: "My service" })
namespace Service;
enum Versions {A, B, C}
model P {
@bodyRoot
body: bytes;
}
model Q {
q: string;
}

#suppress "@azure-tools/typespec-azure-core/use-standard-operations" "This is a test."
@route("/test1")
@get
op test1(p: P): Q;
`;
const result = await compileTypespecAAZOperations(
code,
{
"operation": "get-resources-operations",
"api-version": "A",
"resources": ["/test1"],
},
runner,
);
const resultObj = JSON.parse(result!);
expect(Array.isArray(resultObj)).toBe(true);
expect(resultObj.length).toBe(1);
const targetObj = findObjectsWithKey(resultObj[0].pathItem.get.read.http.request, "body");
await expect(JSON.stringify(targetObj, null, 2)).toMatchFileSnapshot("./snapshots/http-request-bytes-body.json");
});
});
5 changes: 5 additions & 0 deletions src/typespec-aaz/test/snapshots/http-request-bytes-body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "binary",
"name": "body",
"required": true
}