@taico/openapi-sdkgen 0.8.6 → 0.9.1
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/README.md +1 -1
- package/dist/generator.js +5 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @taico/openapi-sdkgen
|
|
2
2
|
|
|
3
|
-
[](https://badge.socket.dev/npm/package/@taico/openapi-sdkgen/0.9.1)
|
|
4
4
|
|
|
5
5
|
A TypeScript SDK generator from OpenAPI specs with focus on developer ergonomics and maintainability.
|
|
6
6
|
|
package/dist/generator.js
CHANGED
|
@@ -44,11 +44,14 @@ function generateTypeDefinition(name, schema) {
|
|
|
44
44
|
return `export type ${name} = ${schemaToTypeScript(schema)};`;
|
|
45
45
|
}
|
|
46
46
|
function schemaToTypeScript(schema) {
|
|
47
|
+
// A nullable $ref (e.g. `{ nullable: true, allOf: [{ $ref }] }`) or inline
|
|
48
|
+
// enum must keep its `| null`, otherwise runtime nulls are hidden from callers.
|
|
47
49
|
if (schema.ref) {
|
|
48
|
-
return schema.ref;
|
|
50
|
+
return schema.nullable ? `${schema.ref} | null` : schema.ref;
|
|
49
51
|
}
|
|
50
52
|
if (schema.enum) {
|
|
51
|
-
|
|
53
|
+
const values = schema.enum.map((v) => `'${v}'`).join(' | ');
|
|
54
|
+
return schema.nullable ? `${values} | null` : values;
|
|
52
55
|
}
|
|
53
56
|
let baseType;
|
|
54
57
|
switch (schema.type) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taico/openapi-sdkgen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "PolyForm-Small-Business-1.0.0",
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"clean": "rm -rf test/client/generated",
|
|
33
33
|
"generate": "tsx src/cli.ts test/api/openapi.json test/client/generated",
|
|
34
34
|
"lint:generated": "tsc --noEmit --project test/client/tsconfig.json",
|
|
35
|
-
"test": "npm run clean && npm run generate:spec && npm run generate && npm run lint:generated && node test/run.mjs",
|
|
35
|
+
"test": "npm run clean && npm run generate:spec && npm run generate && npm run lint:generated && npm run test:contract && node test/run.mjs",
|
|
36
36
|
"pack": "npm run build && npm pack",
|
|
37
|
-
"release": "npm run build && npm publish --access public"
|
|
37
|
+
"release": "npm run build && npm publish --access public",
|
|
38
|
+
"test:contract": "tsx test/client/nullable-contract.ts"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@nestjs/common": "^11.1.17",
|