typed-openapi 2.2.3 → 2.2.4

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.
@@ -5,7 +5,7 @@ import {
5
5
  generateFile,
6
6
  generateTanstackQueryFile,
7
7
  mapOpenApiEndpoints
8
- } from "./chunk-RVHSVZW7.js";
8
+ } from "./chunk-ZM3UP6UJ.js";
9
9
  import {
10
10
  prettify
11
11
  } from "./chunk-KAEXXJ7X.js";
@@ -170,12 +170,20 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
170
170
  const objectType = additionalProperties ? t.intersection([t.object(props), additionalProperties]) : t.object(props);
171
171
  return isPartial ? t.reference("Partial", [objectType]) : objectType;
172
172
  }
173
- if (!schemaType) return t.unknown();
173
+ if (!schemaType) {
174
+ const nullableKey = Object.keys(schema).filter(
175
+ (key) => !["nullable"].includes(key)
176
+ );
177
+ if (nullableKey.length === 0 && schema.nullable) {
178
+ return t.literal("null");
179
+ }
180
+ return t.unknown();
181
+ }
174
182
  throw new Error(`Unsupported schema type: ${schemaType}`);
175
183
  };
176
184
  let output = getTs();
177
185
  if (!isReferenceObject(schema)) {
178
- if (schema.nullable) {
186
+ if (schema.nullable && output.value !== "null") {
179
187
  output = t.union([output, t.literal("null")]);
180
188
  }
181
189
  }
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-GIUNFA7X.js";
3
+ } from "./chunk-62WASHT2.js";
4
4
  import {
5
5
  allowedRuntimes
6
- } from "./chunk-RVHSVZW7.js";
6
+ } from "./chunk-ZM3UP6UJ.js";
7
7
  import "./chunk-KAEXXJ7X.js";
8
8
 
9
9
  // src/cli.ts
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  openApiSchemaToTs,
9
9
  tsFactory,
10
10
  unwrap
11
- } from "./chunk-RVHSVZW7.js";
11
+ } from "./chunk-ZM3UP6UJ.js";
12
12
  import "./chunk-KAEXXJ7X.js";
13
13
  export {
14
14
  createBoxFactory,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-GIUNFA7X.js";
4
- import "./chunk-RVHSVZW7.js";
3
+ } from "./chunk-62WASHT2.js";
4
+ import "./chunk-ZM3UP6UJ.js";
5
5
  import "./chunk-KAEXXJ7X.js";
6
6
  export {
7
7
  generateClientFiles
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-openapi",
3
3
  "type": "module",
4
- "version": "2.2.3",
4
+ "version": "2.2.4",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {
@@ -180,7 +180,17 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
180
180
  return isPartial ? t.reference("Partial", [objectType]) : objectType;
181
181
  }
182
182
 
183
- if (!schemaType) return t.unknown();
183
+ if (!schemaType) {
184
+ const nullableKey = Object.keys(schema).filter(
185
+ key => !['nullable'].includes(key)
186
+ );
187
+
188
+ if (nullableKey.length === 0 && (schema as LibSchemaObject).nullable) {
189
+ return t.literal("null");
190
+ }
191
+
192
+ return t.unknown();
193
+ }
184
194
 
185
195
  throw new Error(`Unsupported schema type: ${schemaType}`);
186
196
  };
@@ -188,7 +198,7 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
188
198
  let output = getTs();
189
199
  if (!isReferenceObject(schema)) {
190
200
  // OpenAPI 3.1 does not have nullable, but OpenAPI 3.0 does
191
- if ((schema as LibSchemaObject).nullable) {
201
+ if ((schema as LibSchemaObject).nullable && output.value !== "null") {
192
202
  output = t.union([output, t.literal("null")]);
193
203
  }
194
204
  }