typed-openapi 0.1.2 → 0.1.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.
package/dist/cli.cjs CHANGED
@@ -31,7 +31,7 @@ var import_promises = require("fs/promises");
31
31
 
32
32
  // package.json
33
33
  var name = "typed-openapi";
34
- var version = "0.1.1";
34
+ var version = "0.1.4";
35
35
 
36
36
  // src/generator.ts
37
37
  var import_server2 = require("pastable/server");
@@ -214,10 +214,7 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
214
214
  }
215
215
  const isRequired = Boolean(isPartial ? true : hasRequiredArray ? schema.required?.includes(prop) : false);
216
216
  const isOptional = !isPartial && !isRequired;
217
- return [
218
- `${wrapWithQuotesIfNeeded(prop)}${isOptional ? "?" : ""}`,
219
- isOptional ? t.optional(propType) : propType
220
- ];
217
+ return [`${wrapWithQuotesIfNeeded(prop)}`, isOptional ? t.optional(propType) : propType];
221
218
  })
222
219
  );
223
220
  const objectType = additionalProperties ? t.intersection([t.object(props), additionalProperties]) : t.object(props);
@@ -227,7 +224,13 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
227
224
  return t.unknown();
228
225
  throw new Error(`Unsupported schema type: ${schemaType}`);
229
226
  };
230
- return getTs();
227
+ let output = getTs();
228
+ if (!isReferenceObject(schema)) {
229
+ if (schema.nullable) {
230
+ output = t.union([output, t.reference("null")]);
231
+ }
232
+ }
233
+ return output;
231
234
  };
232
235
 
233
236
  // src/box.ts
@@ -725,7 +728,11 @@ var tsFactory = createFactory({
725
728
  any: () => "any",
726
729
  never: () => "never",
727
730
  object: (props) => {
728
- const propsString = Object.entries(props).map(([prop, type3]) => `${wrapWithQuotesIfNeeded(prop)}: ${unwrap(type3)}`).join(", ");
731
+ const propsString = Object.entries(props).map(
732
+ ([prop, type3]) => `${wrapWithQuotesIfNeeded(prop)}${typeof type3 !== "string" && Box.isOptional(type3) ? "?" : ""}: ${unwrap(
733
+ type3
734
+ )}`
735
+ ).join(", ");
729
736
  return `{ ${propsString} }`;
730
737
  }
731
738
  });