@ndla/types-taxonomy 1.0.38 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -17,10 +17,10 @@
17
17
  "main": "taxonomy-api.js",
18
18
  "devDependencies": {
19
19
  "@types/node": "^22.13.16",
20
- "openapi-typescript": "^7.6.1",
20
+ "openapi-typescript": "^7.10.1",
21
21
  "tsx": "^4.19.3",
22
22
  "typescript": "^5.3.3"
23
23
  },
24
- "version": "1.0.38",
24
+ "version": "1.0.40",
25
25
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
26
26
  }
@@ -23,27 +23,40 @@ async function generate_types(appName: string) {
23
23
  const jsonFile = `./openapi.json`;
24
24
  console.log(`Parsing ${jsonFile} to generate typescript files...`);
25
25
  const schema = await fs.promises.readFile(jsonFile, "utf8");
26
+ const schemaContent = JSON.parse(schema);
26
27
 
27
- const ast = await openapiTS(JSON.parse(schema), {
28
- exportType: true,
29
- // https://openapi-ts.dev/migration-guide#defaultnonnullable-true-by-default
28
+ const ast = await openapiTS(schemaContent, {
30
29
  defaultNonNullable: false,
31
- transform(schemaObject, _options): TypeNode | undefined {
32
- if (schemaObject.format === "binary") {
33
- if (schemaObject.nullable) {
34
- return ts.factory.createUnionTypeNode([BLOB, NULL]);
35
- } else {
36
- return BLOB;
37
- }
38
- }
39
- },
30
+ exportType: true,
40
31
  });
41
32
 
42
- const outputPath = `./taxonomy-api.ts`;
33
+ const outputPath = `./taxonomy-api-openapi.ts`;
34
+
43
35
  const output = astToString(ast);
44
36
 
45
37
  console.log(`Outputting to ${outputPath}`);
38
+
46
39
  fs.writeFileSync(outputPath, output);
40
+
41
+ const header = `// This file is generated automatically. Do not edit.
42
+ `;
43
+ let newFileContent = `${header}import * as openapi from "./taxonomy-api-openapi";
44
+ type schemas = openapi.components["schemas"];
45
+ export { openapi };
46
+
47
+ `;
48
+
49
+ const schemas = schemaContent.components.schemas;
50
+ const schemaNames = Object.keys(schemas);
51
+ for (const schemaName of schemaNames) {
52
+ newFileContent += `export type ${schemaName} = schemas["${schemaName}"];\n`;
53
+ }
54
+
55
+ const newFilePath = `./taxonomy-api.ts`;
56
+
57
+ console.log(`Outputting to ${newFilePath}`);
58
+
59
+ fs.writeFileSync(newFilePath, newFileContent);
47
60
  }
48
61
 
49
- generate_types(process.argv[2]);
62
+ generate_types(process.argv[2]);