Skip to content

Commit

Permalink
Fix JSON extension
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Nov 10, 2022
1 parent 32465ab commit 75ea679
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
File renamed without changes.
4 changes: 3 additions & 1 deletion scripts/download-schemas.ts
@@ -1,4 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import degit from "degit";
import { fetch } from "undici";
Expand Down Expand Up @@ -26,7 +27,8 @@ const EXAMPLES_DIR = new URL("../examples/", import.meta.url);
export async function download() {
await Promise.all([
...Object.entries(singleFile).map(async ([k, url]) => {
const dest = new URL(`${k}.yaml`, EXAMPLES_DIR);
const ext = path.extname(url);
const dest = new URL(`${k}${ext}`, EXAMPLES_DIR);
if (fs.existsSync(dest)) {
const { mtime } = fs.statSync(dest);
if (Date.now() - mtime.getTime() < ONE_DAY) return; // only update every 24 hours at most
Expand Down
4 changes: 3 additions & 1 deletion scripts/update-examples.ts
@@ -1,4 +1,5 @@
import { execa } from "execa";
import path from "node:path";
import { URL } from "node:url";
import { download, singleFile, multiFile } from "./download-schemas.js";

Expand All @@ -7,7 +8,8 @@ async function generateSchemas() {
const cwd = new URL("../", import.meta.url);
await Promise.all([
...Object.keys(singleFile).map(async (name) => {
await execa("node", ["./bin/cli.js", `./examples/${name}.yaml`, "-o", `./examples/${name}.ts`], { cwd });
const ext = path.extname(singleFile[name as keyof typeof singleFile]);
await execa("node", ["./bin/cli.js", `./examples/${name}${ext}`, "-o", `./examples/${name}.ts`], { cwd });
}),
...Object.entries(multiFile).map(async ([name, meta]) => {
await execa(
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.ts
Expand Up @@ -20,7 +20,7 @@ describe("CLI", () => {
}, 30000);
test("Octokit GHES 3.6 Diff to API", async () => {
const expected = fs.readFileSync(new URL("./examples/octokit-ghes-3.6-diff-to-api.ts", cwd), "utf8").trim();
const { stdout } = await execa(cmd, ["./examples/octokit-ghes-3.6-diff-to-api.yaml"], { cwd });
const { stdout } = await execa(cmd, ["./examples/octokit-ghes-3.6-diff-to-api.json"], { cwd });
expect(stdout).toBe(expected);
}, 30000);
test("Stripe API", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Expand Up @@ -466,7 +466,7 @@ export type operations = Record<string, never>;
});
describe("Octokit GHES 3.6 Diff to API", () => {
test("default options", async () => {
const generated = await openapiTS(new URL("./octokit-ghes-3.6-diff-to-api.yaml", EXAMPLES_DIR));
const generated = await openapiTS(new URL("./octokit-ghes-3.6-diff-to-api.json", EXAMPLES_DIR));
expect(generated).toBe(fs.readFileSync(new URL("./octokit-ghes-3.6-diff-to-api.ts", EXAMPLES_DIR), "utf8"));
}, 30000);
});
Expand Down

0 comments on commit 75ea679

Please sign in to comment.