Skip to content
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
4 changes: 3 additions & 1 deletion .github/workflows/typescript-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
yarn version patch
yarn npm publish --provenance --access public
git add package.json
git commit -m "AUTOMATION: Bumped package version"
VERSION=$(jq -j .version package.json)
git tag -a "v$VERSION" -m "v$VERSION"
git commit -m "AUTOMATION: Bumped package version to v$VERSION"
git push
git push --tags
6 changes: 3 additions & 3 deletions typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"main": "taxonomy-api.js",
"devDependencies": {
"@types/node": "^22.13.16",
"openapi-typescript": "^7.10.1",
"tsx": "^4.19.3",
"typescript": "^5.3.3"
"openapi-typescript": "^7.13.0",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
},
"version": "1.0.49",
"packageManager": "yarn@4.10.3"
Expand Down
41 changes: 7 additions & 34 deletions typescript/scripts/generate-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@
*/

import fs from "node:fs";
import openapiTS, { astToString, TransformObject } from "openapi-typescript";
import ts, { TypeNode } from "typescript";
import openapiTS, { astToString } from "openapi-typescript";

if (process.argv.length !== 2) {
throw new Error("Invalid use");
}

const BLOB = ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier("Blob"),
);
const NULL = ts.factory.createLiteralTypeNode(ts.factory.createNull()); // `null`

async function generate_types(appName: string) {
async function generate_types() {
const jsonFile = `./openapi.json`;
console.log(`Parsing ${jsonFile} to generate typescript files...`);
const schema = await fs.promises.readFile(jsonFile, "utf8");
Expand All @@ -28,35 +18,18 @@ async function generate_types(appName: string) {
const ast = await openapiTS(schemaContent, {
defaultNonNullable: false,
exportType: true,
rootTypes: true,
rootTypesKeepCasing: true,
rootTypesNoSchemaPrefix: true,
});

const outputPath = `./taxonomy-api-openapi.ts`;
const outputPath = `./taxonomy-api.ts`;

const output = astToString(ast);

console.log(`Outputting to ${outputPath}`);

fs.writeFileSync(outputPath, output);

const header = `// This file is generated automatically. Do not edit.
`;
let newFileContent = `${header}import * as openapi from "./taxonomy-api-openapi";
type schemas = openapi.components["schemas"];
export { openapi };

`;

const schemas = schemaContent.components.schemas;
const schemaNames = Object.keys(schemas);
for (const schemaName of schemaNames) {
newFileContent += `export type ${schemaName} = schemas["${schemaName}"];\n`;
}

const newFilePath = `./taxonomy-api.ts`;

console.log(`Outputting to ${newFilePath}`);

fs.writeFileSync(newFilePath, newFileContent);
}

generate_types(process.argv[2]);
generate_types();
Loading