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/chunk-E7HJBSR2.js +815 -0
- package/dist/chunk-M3WPXWOV.js +821 -0
- package/dist/chunk-TUNDL3P7.js +822 -0
- package/dist/cli.cjs +14 -7
- package/dist/cli.js +9 -809
- package/dist/index.cjs +866 -0
- package/dist/index.d.cts +266 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.js +20 -0
- package/package.json +17 -5
- package/src/cli.ts +0 -1
- package/src/generator.ts +1 -0
- package/src/index.ts +7 -0
- package/src/openapi-schema-to-ts.ts +11 -5
- package/src/ts-factory.ts +7 -1
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.
|
|
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
|
-
|
|
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(
|
|
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
|
});
|