From f8ee651d7d3e76e8636e1e3531e72bfd94b37632 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Mon, 16 Feb 2026 21:26:51 -0800 Subject: [PATCH] fix(create): accept 201 status codes the AEPs use 201 created for a resource created. That should be honored in addition to 200. --- src/api/api.test.ts | 35 +++++++++++++++++++++++++++++++++++ src/api/api.ts | 8 ++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/api/api.test.ts b/src/api/api.test.ts index 2552ebb..412410c 100644 --- a/src/api/api.test.ts +++ b/src/api/api.test.ts @@ -410,5 +410,40 @@ describe("APIClient", () => { expect(api.contact?.email).toBe("john.doe@example.com"); expect(api.contact?.url).toBe("https://example.com"); }); + it("should handle create method with 201 response", async () => { + const openAPI: OpenAPI = { + openapi: "3.1.0", + servers: [{ url: "https://api.example.com" }], + info: { title: "Test API", version: "1.0.0", description: "Test API" }, + paths: { + "/widgets": { + post: { + operationId: "CreateWidget", + responses: { + "201": { + description: "Created", + content: { + "application/json": { + schema: { $ref: "#/components/schemas/Widget" }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: { + Widget: { type: "object" }, + }, + }, + }; + + const client = await APIClient.fromOpenAPI(openAPI); + const api = (client as unknown as { api: API }).api; + const widget = api.resources["widget"]; + expect(widget).toBeDefined(); + expect(widget.createMethod).toBeDefined(); + }); }); }); diff --git a/src/api/api.ts b/src/api/api.ts index c4cebb4..5698176 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -49,7 +49,9 @@ export class APIClient { } if (pathItem.post) { - const response = pathItem.post.responses?.["200"]; + const response = + pathItem.post.responses?.["200"] || + pathItem.post.responses?.["201"]; if (response) { const schema = getSchemaFromResponse(response, openAPI); const responseSchema = schema @@ -112,7 +114,9 @@ export class APIClient { } } else { if (pathItem.post) { - const response = pathItem.post.responses?.["200"]; + const response = + pathItem.post.responses?.["200"] || + pathItem.post.responses?.["201"]; if (response) { schemaRef = getSchemaFromResponse(response, openAPI); const supportsUserSettableCreate =