Skip to content

Commit 488b87e

Browse files
authored
Move test (openapi-ts#1628)
1 parent 9437f39 commit 488b87e

File tree

3 files changed

+116
-73
lines changed

3 files changed

+116
-73
lines changed

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@
2525
"url": "https://github.com/drwpow/openapi-typescript",
2626
"directory": "packages/openapi-typescript"
2727
},
28-
"keywords": ["swagger", "typescript", "ts", "dts", "openapi", "codegen", "generation", "openapi 3", "node"],
28+
"keywords": [
29+
"swagger",
30+
"typescript",
31+
"ts",
32+
"dts",
33+
"openapi",
34+
"codegen",
35+
"generation",
36+
"openapi 3",
37+
"node"
38+
],
2939
"bugs": {
3040
"url": "https://github.com/drwpow/openapi-typescript/issues"
3141
},

test/node-api.test.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { TestCase } from "./test-helpers.js";
77
const EXAMPLES_DIR = new URL("../examples/", import.meta.url);
88

99
const DATE = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Date"));
10+
const BLOB = ts.factory.createTypeReferenceNode("Blob");
1011

1112
describe("Node.js API", () => {
1213
const tests: TestCase<any, OpenAPITSOptions>[] = [
@@ -423,6 +424,110 @@ export type operations = Record<string, never>;`,
423424
},
424425
},
425426
],
427+
[
428+
"options > transform with blob",
429+
{
430+
given: {
431+
openapi: "3.1",
432+
info: { title: "Test", version: "1.0" },
433+
components: {
434+
requestBodies: {
435+
Blob: {
436+
content: {
437+
"application/json": {
438+
schema: {
439+
type: "string",
440+
format: "binary",
441+
},
442+
},
443+
},
444+
},
445+
},
446+
},
447+
},
448+
want: `export type paths = Record<string, never>;
449+
export type webhooks = Record<string, never>;
450+
export interface components {
451+
schemas: never;
452+
responses: never;
453+
parameters: never;
454+
requestBodies: {
455+
Blob: {
456+
content: {
457+
"application/json": Blob;
458+
};
459+
};
460+
};
461+
headers: never;
462+
pathItems: never;
463+
}
464+
export type $defs = Record<string, never>;
465+
export type operations = Record<string, never>;`,
466+
options: {
467+
transform(schemaObject) {
468+
if (schemaObject.format === "binary") {
469+
return BLOB;
470+
}
471+
},
472+
},
473+
},
474+
],
475+
[
476+
"options > transform with optional blob property",
477+
{
478+
given: {
479+
openapi: "3.1",
480+
info: { title: "Test", version: "1.0" },
481+
components: {
482+
requestBodies: {
483+
Blob: {
484+
content: {
485+
"application/json": {
486+
schema: {
487+
type: "object",
488+
properties: {
489+
blob: { type: "string", format: "binary" },
490+
},
491+
},
492+
},
493+
},
494+
},
495+
},
496+
},
497+
},
498+
want: `export type paths = Record<string, never>;
499+
export type webhooks = Record<string, never>;
500+
export interface components {
501+
schemas: never;
502+
responses: never;
503+
parameters: never;
504+
requestBodies: {
505+
Blob: {
506+
content: {
507+
"application/json": {
508+
/** Format: binary */
509+
blob?: Blob;
510+
};
511+
};
512+
};
513+
};
514+
headers: never;
515+
pathItems: never;
516+
}
517+
export type $defs = Record<string, never>;
518+
export type operations = Record<string, never>;`,
519+
options: {
520+
transform(schemaObject) {
521+
if (schemaObject.format === "binary") {
522+
return {
523+
schema: BLOB,
524+
questionToken: true,
525+
};
526+
}
527+
},
528+
},
529+
},
530+
],
426531
[
427532
"options > postTransform",
428533
{

test/transform/request-body-object.test.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const DEFAULT_OPTIONS = {
99
ctx: { ...DEFAULT_CTX },
1010
};
1111

12-
const BLOB = ts.factory.createTypeReferenceNode("Blob");
13-
1412
describe("transformRequestBodyObject", () => {
1513
const tests: TestCase[] = [
1614
[
@@ -53,76 +51,6 @@ describe("transformRequestBodyObject", () => {
5351
// options: DEFAULT_OPTIONS,
5452
},
5553
],
56-
[
57-
"blob with transform",
58-
{
59-
given: {
60-
content: {
61-
"application/json": {
62-
schema: {
63-
type: "string",
64-
format: "binary",
65-
},
66-
},
67-
},
68-
},
69-
want: `{
70-
content: {
71-
"application/json": Blob;
72-
};
73-
}`,
74-
options: {
75-
...DEFAULT_OPTIONS,
76-
ctx: {
77-
...DEFAULT_CTX,
78-
transform(schemaObject) {
79-
if (schemaObject.format === "binary") {
80-
return BLOB;
81-
}
82-
},
83-
},
84-
},
85-
},
86-
],
87-
[
88-
"optional blob property with transform",
89-
{
90-
given: {
91-
content: {
92-
"application/json": {
93-
schema: {
94-
type: "object",
95-
properties: {
96-
blob: { type: "string", format: "binary" },
97-
},
98-
},
99-
},
100-
},
101-
},
102-
want: `{
103-
content: {
104-
"application/json": {
105-
/** Format: binary */
106-
blob?: Blob;
107-
};
108-
};
109-
}`,
110-
options: {
111-
...DEFAULT_OPTIONS,
112-
ctx: {
113-
...DEFAULT_CTX,
114-
transform(schemaObject) {
115-
if (schemaObject.format === "binary") {
116-
return {
117-
schema: BLOB,
118-
questionToken: true,
119-
};
120-
}
121-
},
122-
},
123-
},
124-
},
125-
],
12654
];
12755

12856
for (const [testName, { given, want, options = DEFAULT_OPTIONS, ci }] of tests) {

0 commit comments

Comments
 (0)