Skip to content
Merged
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
35 changes: 35 additions & 0 deletions src/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
8 changes: 6 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down