Skip to content

Move test #1628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
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
5 changes: 0 additions & 5 deletions .changeset/smooth-cameras-fail.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/data/contributors.json

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions docs/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ const ONE_WEEK = 1000 * 60 * 60 * 24 * 7;
async function fetchUserInfo(username) {
const res = await fetch(`https://github.com/${username}`, {
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": "en-US,en;q=0.5",
"cache-control": "no-cache",
connection: "keep-alive",
"user-agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0",
},
});
if (!res.ok) {
Expand Down Expand Up @@ -148,6 +146,7 @@ const OPENAPI_TS_CONTRIBUTORS = [
"raurfang",
"JeanRemiDelteil",
"TzviPM",
"LucaSchwan",
]),
];

Expand Down Expand Up @@ -183,15 +182,10 @@ export const OPENAPI_FETCH_CONTRIBUTORS = [
async function main() {
await Promise.all(
["openapi-typescript", "openapi-fetch"].map(async (repo) => {
const userlist =
repo === "openapi-fetch"
? OPENAPI_FETCH_CONTRIBUTORS
: OPENAPI_TS_CONTRIBUTORS;
const userlist = repo === "openapi-fetch" ? OPENAPI_FETCH_CONTRIBUTORS : OPENAPI_TS_CONTRIBUTORS;
for (const username of userlist) {
// skip profiles that have been updated within the past week
const { lastFetch } = contributors[repo].find(
(u) => u.username === username,
) ?? { lastFetch: 0 };
const { lastFetch } = contributors[repo].find((u) => u.username === username) ?? { lastFetch: 0 };
if (Date.now() - lastFetch < ONE_WEEK) {
continue;
}
Expand All @@ -207,10 +201,7 @@ async function main() {
};
upsert(contributors[repo], userData);
console.log(`Updated old contributor data for ${username}`); // biome-disable-line no-console
fs.writeFileSync(
new URL("../data/contributors.json", import.meta.url),
JSON.stringify(contributors),
); // update file while fetching (sync happens safely in between fetches)
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(contributors)); // update file while fetching (sync happens safely in between fetches)
} catch (err) {
throw new Error(err);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@
"url": "https://github.com/drwpow/openapi-typescript",
"directory": "packages/openapi-typescript"
},
"keywords": ["swagger", "typescript", "ts", "dts", "openapi", "codegen", "generation", "openapi 3", "node"],
"keywords": [
"swagger",
"typescript",
"ts",
"dts",
"openapi",
"codegen",
"generation",
"openapi 3",
"node"
],
"bugs": {
"url": "https://github.com/drwpow/openapi-typescript/issues"
},
Expand Down
105 changes: 105 additions & 0 deletions packages/openapi-typescript/test/node-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { TestCase } from "./test-helpers.js";
const EXAMPLES_DIR = new URL("../examples/", import.meta.url);

const DATE = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Date"));
const BLOB = ts.factory.createTypeReferenceNode("Blob");

describe("Node.js API", () => {
const tests: TestCase<any, OpenAPITSOptions>[] = [
Expand Down Expand Up @@ -423,6 +424,110 @@ export type operations = Record<string, never>;`,
},
},
],
[
"options > transform with blob",
{
given: {
openapi: "3.1",
info: { title: "Test", version: "1.0" },
components: {
requestBodies: {
Blob: {
content: {
"application/json": {
schema: {
type: "string",
format: "binary",
},
},
},
},
},
},
},
want: `export type paths = Record<string, never>;
export type webhooks = Record<string, never>;
export interface components {
schemas: never;
responses: never;
parameters: never;
requestBodies: {
Blob: {
content: {
"application/json": Blob;
};
};
};
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;`,
options: {
transform(schemaObject) {
if (schemaObject.format === "binary") {
return BLOB;
}
},
},
},
],
[
"options > transform with optional blob property",
{
given: {
openapi: "3.1",
info: { title: "Test", version: "1.0" },
components: {
requestBodies: {
Blob: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
blob: { type: "string", format: "binary" },
},
},
},
},
},
},
},
},
want: `export type paths = Record<string, never>;
export type webhooks = Record<string, never>;
export interface components {
schemas: never;
responses: never;
parameters: never;
requestBodies: {
Blob: {
content: {
"application/json": {
/** Format: binary */
blob?: Blob;
};
};
};
};
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;`,
options: {
transform(schemaObject) {
if (schemaObject.format === "binary") {
return {
schema: BLOB,
questionToken: true,
};
}
},
},
},
],
[
"options > postTransform",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const DEFAULT_OPTIONS = {
ctx: { ...DEFAULT_CTX },
};

const BLOB = ts.factory.createTypeReferenceNode("Blob");

describe("transformRequestBodyObject", () => {
const tests: TestCase[] = [
[
Expand Down Expand Up @@ -53,76 +51,6 @@ describe("transformRequestBodyObject", () => {
// options: DEFAULT_OPTIONS,
},
],
[
"blob with transform",
{
given: {
content: {
"application/json": {
schema: {
type: "string",
format: "binary",
},
},
},
},
want: `{
content: {
"application/json": Blob;
};
}`,
options: {
...DEFAULT_OPTIONS,
ctx: {
...DEFAULT_CTX,
transform(schemaObject) {
if (schemaObject.format === "binary") {
return BLOB;
}
},
},
},
},
],
[
"optional blob property with transform",
{
given: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
blob: { type: "string", format: "binary" },
},
},
},
},
},
want: `{
content: {
"application/json": {
/** Format: binary */
blob?: Blob;
};
};
}`,
options: {
...DEFAULT_OPTIONS,
ctx: {
...DEFAULT_CTX,
transform(schemaObject) {
if (schemaObject.format === "binary") {
return {
schema: BLOB,
questionToken: true,
};
}
},
},
},
},
],
];

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