Skip to content

Commit 653a729

Browse files
authored
Fix operations responseBody (#464)
#463
1 parent 10e26ad commit 653a729

File tree

6 files changed

+1228
-12
lines changed

6 files changed

+1228
-12
lines changed

src/transform/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function transformAll(schema: any, { version, rawSchema }: TransformOptio
113113
output += ` "${operationId}": {\n ${transformOperationObj(
114114
operation,
115115
schema.components && schema.components.parameters
116-
)};\n }\n`;
116+
)}\n }\n`;
117117
});
118118
}
119119
output += `}\n`; // close operations

tests/paths.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import prettier from "prettier";
22
import { transformPathsObj } from "../src/transform/paths";
33

4-
const transform = (schema: any, operations?: any, parameters?: any) =>
4+
const transform = (schema: any, operations: any = { operations: {}, parameters: {} }, parameters?: any) =>
55
prettier.format(`export interface paths {\n${transformPathsObj(schema, { operations, parameters })}\n}`.trim(), {
66
parser: "typescript",
77
});
@@ -199,6 +199,10 @@ describe("transformPathsObj", () => {
199199
},
200200
},
201201
},
202+
delete: {
203+
operationId: "testsDelete",
204+
requestBody: { $ref: "#/components/schemas/Pet" },
205+
},
202206
},
203207
})
204208
).toBe(`export interface paths {
@@ -222,6 +226,7 @@ describe("transformPathsObj", () => {
222226
};
223227
};
224228
};
229+
delete: operations["testsDelete"];
225230
};
226231
}\n`);
227232
});

tests/v2/index.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import fs from "fs";
22
import path from "path";
33
import { execSync } from "child_process";
44

5+
const schemas = fs.readdirSync(path.join(__dirname, "specs"));
6+
57
// simple snapshot tests with valid schemas to make sure it can generally parse & generate output
68
describe("cli", () => {
7-
["stripe", "manifold", "petstore"].forEach((file) => {
8-
it(`reads ${file} spec (v2) from file`, () => {
9-
execSync(`../../pkg/bin/cli.js specs/${file}.yaml -o generated/${file}.ts`, {
9+
schemas.forEach((schema) => {
10+
const output = schema.replace(/\ya?ml$/i, "ts");
11+
it(`reads ${schema} spec (v2) from file`, () => {
12+
execSync(`../../pkg/bin/cli.js specs/${schema} -o generated/${output}`, {
1013
cwd: __dirname,
1114
});
12-
const expected = fs.readFileSync(path.join(__dirname, "expected", `${file}.ts`), "utf8");
13-
const generated = fs.readFileSync(path.join(__dirname, "generated", `${file}.ts`), "utf8");
15+
const expected = fs.readFileSync(path.join(__dirname, "expected", output), "utf8");
16+
const generated = fs.readFileSync(path.join(__dirname, "generated", output), "utf8");
1417
expect(generated).toBe(expected);
1518
});
1619
});

0 commit comments

Comments
 (0)