Skip to content

Commit 1aa702d

Browse files
authored
Move test (openapi-ts#1628)
1 parent 5a1f86b commit 1aa702d

File tree

6 files changed

+123
-94
lines changed

6 files changed

+123
-94
lines changed

.changeset/smooth-cameras-fail.md

-5
This file was deleted.

docs/data/contributors.json

+1-1
Large diffs are not rendered by default.

docs/scripts/update-contributors.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ const ONE_WEEK = 1000 * 60 * 60 * 24 * 7;
1212
async function fetchUserInfo(username) {
1313
const res = await fetch(`https://github.com/${username}`, {
1414
headers: {
15-
accept:
16-
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
15+
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
1716
"accept-encoding": "gzip, deflate, br, zstd",
1817
"accept-language": "en-US,en;q=0.5",
1918
"cache-control": "no-cache",
2019
connection: "keep-alive",
21-
"user-agent":
22-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0",
20+
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0",
2321
},
2422
});
2523
if (!res.ok) {
@@ -148,6 +146,7 @@ const OPENAPI_TS_CONTRIBUTORS = [
148146
"raurfang",
149147
"JeanRemiDelteil",
150148
"TzviPM",
149+
"LucaSchwan",
151150
]),
152151
];
153152

@@ -183,15 +182,10 @@ export const OPENAPI_FETCH_CONTRIBUTORS = [
183182
async function main() {
184183
await Promise.all(
185184
["openapi-typescript", "openapi-fetch"].map(async (repo) => {
186-
const userlist =
187-
repo === "openapi-fetch"
188-
? OPENAPI_FETCH_CONTRIBUTORS
189-
: OPENAPI_TS_CONTRIBUTORS;
185+
const userlist = repo === "openapi-fetch" ? OPENAPI_FETCH_CONTRIBUTORS : OPENAPI_TS_CONTRIBUTORS;
190186
for (const username of userlist) {
191187
// skip profiles that have been updated within the past week
192-
const { lastFetch } = contributors[repo].find(
193-
(u) => u.username === username,
194-
) ?? { lastFetch: 0 };
188+
const { lastFetch } = contributors[repo].find((u) => u.username === username) ?? { lastFetch: 0 };
195189
if (Date.now() - lastFetch < ONE_WEEK) {
196190
continue;
197191
}
@@ -207,10 +201,7 @@ async function main() {
207201
};
208202
upsert(contributors[repo], userData);
209203
console.log(`Updated old contributor data for ${username}`); // biome-disable-line no-console
210-
fs.writeFileSync(
211-
new URL("../data/contributors.json", import.meta.url),
212-
JSON.stringify(contributors),
213-
); // update file while fetching (sync happens safely in between fetches)
204+
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(contributors)); // update file while fetching (sync happens safely in between fetches)
214205
} catch (err) {
215206
throw new Error(err);
216207
}

packages/openapi-typescript/package.json

+11-1
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
},

packages/openapi-typescript/test/node-api.test.ts

+105
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
{

packages/openapi-typescript/test/transform/request-body-object.test.ts

-72
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)