@sohcah/openapi-generator 0.1.2 → 0.2.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/dist/{chunk-51aI8Tpl.js → chunk-DYFKRlHt.js} +4 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +2 -2
- package/dist/generators/index.d.ts +1 -61
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +54 -17
- package/dist/generators/index.js.map +1 -1
- package/dist/{helpers-tkoILkcL.js → helpers-CqzmoMek.js} +4 -3
- package/dist/{helpers-tkoILkcL.js.map → helpers-CqzmoMek.js.map} +1 -1
- package/dist/{index-BOme2BJ_.d.ts → index-DY2v-Q37.d.ts} +5 -7
- package/dist/index-DY2v-Q37.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/src-DhXSDR6J.js +7997 -0
- package/dist/src-DhXSDR6J.js.map +1 -0
- package/dist/types-DMB5w9Tt.d.ts +147 -0
- package/dist/types-DMB5w9Tt.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/index-BOme2BJ_.d.ts.map +0 -1
- package/dist/src-Di4R7y_C.js +0 -164
- package/dist/src-Di4R7y_C.js.map +0 -1
- package/dist/types-DjImZ4S-.d.ts +0 -71
- package/dist/types-DjImZ4S-.d.ts.map +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
1
3
|
//#region rolldown:runtime
|
|
2
4
|
var __create = Object.create;
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
@@ -28,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
30
|
value: mod,
|
|
29
31
|
enumerable: true
|
|
30
32
|
}) : target, mod));
|
|
33
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
34
|
|
|
32
35
|
//#endregion
|
|
33
|
-
export { __commonJS, __export, __toESM };
|
|
36
|
+
export { __commonJS, __export, __require, __toESM };
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
2
|
+
import { generateToFile } from "./src-DhXSDR6J.js";
|
|
3
|
+
import "./helpers-CqzmoMek.js";
|
|
4
4
|
import { Command, Options } from "@effect/cli";
|
|
5
5
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
|
6
6
|
import { Effect } from "effect";
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import { OpenapiGenerateToFileOptions } from "./index-
|
|
1
|
+
import "./types-DMB5w9Tt.js";
|
|
2
|
+
import { OpenapiGenerateToFileOptions } from "./index-DY2v-Q37.js";
|
|
3
3
|
|
|
4
4
|
//#region src/config.d.ts
|
|
5
5
|
declare const defineConfig: (config: OpenapiGenerateToFileOptions) => OpenapiGenerateToFileOptions;
|
|
@@ -1,67 +1,7 @@
|
|
|
1
|
-
import { DocumentContext, HttpMethod, ImportReference, NotImplementedError, OpenApiClientGenerator, OpenApiGenerator, OpenApiParametersSchema, OpenApiResponseSchema, OpenApiSchemaGenerator, OperationKey, OperationObject, SchemaObject, helpers_d_exports } from "../types-
|
|
1
|
+
import { DocumentContext, HttpMethod, ImportReference, NotImplementedError, OpenApiClientGenerator, OpenApiGenerator, OpenApiParametersSchema, OpenApiResponseSchema, OpenApiSchemaGenerator, OperationKey, OperationObject, SchemaGeneratorOptions, SchemaObject, createSchemaGenerator, helpers_d_exports } from "../types-DMB5w9Tt.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import * as t from "@babel/types";
|
|
4
4
|
|
|
5
|
-
//#region src/generators/schema.d.ts
|
|
6
|
-
|
|
7
|
-
interface SchemaGeneratorOptions {
|
|
8
|
-
/** @default null */
|
|
9
|
-
custom?: (schema: SchemaObject) => ImportReference | null;
|
|
10
|
-
/** @default false */
|
|
11
|
-
experimental_includeTypes?: boolean;
|
|
12
|
-
/** @default true */
|
|
13
|
-
includeSchemas?: boolean;
|
|
14
|
-
/** @default false */
|
|
15
|
-
includeOperations?: boolean;
|
|
16
|
-
/** @default "unknown" */
|
|
17
|
-
deprecationHandling?: "unknown" | "optional";
|
|
18
|
-
}
|
|
19
|
-
interface DefaultSchemaGeneratorOptions extends SchemaGeneratorOptions {
|
|
20
|
-
modifiers: {
|
|
21
|
-
lazy: (expression: t.Expression) => t.Expression;
|
|
22
|
-
optional: (expression: t.Expression) => t.Expression;
|
|
23
|
-
regex: (expression: t.Expression, pattern: string) => t.Expression;
|
|
24
|
-
immutable: (expression: t.Expression) => t.Expression;
|
|
25
|
-
mutable: (expression: t.Expression) => t.Expression;
|
|
26
|
-
nullable: (expression: t.Expression) => t.Expression;
|
|
27
|
-
};
|
|
28
|
-
types: {
|
|
29
|
-
schema: t.TSQualifiedName;
|
|
30
|
-
typeDecoded: t.TSQualifiedName;
|
|
31
|
-
typeEncoded: t.TSQualifiedName;
|
|
32
|
-
};
|
|
33
|
-
schema: {
|
|
34
|
-
record: (key: t.Expression, value: t.Expression) => t.Expression;
|
|
35
|
-
union: (expressions: t.Expression[]) => t.Expression;
|
|
36
|
-
enum: (expressions: t.Expression[]) => t.Expression;
|
|
37
|
-
instanceOf: t.Expression;
|
|
38
|
-
boolean: t.Expression;
|
|
39
|
-
string: t.Expression;
|
|
40
|
-
number: t.Expression;
|
|
41
|
-
integer: t.Expression;
|
|
42
|
-
array: t.Expression;
|
|
43
|
-
object: t.Expression;
|
|
44
|
-
null: t.Expression;
|
|
45
|
-
unknown: t.Expression;
|
|
46
|
-
};
|
|
47
|
-
transformer: (options: {
|
|
48
|
-
encoded: t.Expression;
|
|
49
|
-
decoded: t.Expression;
|
|
50
|
-
decode: t.Expression | t.BlockStatement;
|
|
51
|
-
decodeAsync?: boolean;
|
|
52
|
-
encode: t.Expression | t.BlockStatement;
|
|
53
|
-
encodeAsync?: boolean;
|
|
54
|
-
}) => t.Expression;
|
|
55
|
-
transformerCatch: (expression: t.Expression) => t.BlockStatement;
|
|
56
|
-
methods: {
|
|
57
|
-
encode: (schema: t.Expression, value: t.Expression) => t.Expression;
|
|
58
|
-
decode: (schema: t.Expression, value: t.Expression) => t.Expression;
|
|
59
|
-
parse: (schema: t.Expression, value: t.Expression) => t.Expression;
|
|
60
|
-
};
|
|
61
|
-
supportsImmutability: boolean;
|
|
62
|
-
}
|
|
63
|
-
declare function createSchemaGenerator(options: DefaultSchemaGeneratorOptions): OpenApiSchemaGenerator;
|
|
64
|
-
//#endregion
|
|
65
5
|
//#region src/generators/effect.d.ts
|
|
66
6
|
declare const createEffectSchemaGenerator: (options: SchemaGeneratorOptions) => {
|
|
67
7
|
initialize: () => Effect.Effect<void, never, DocumentContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/generators/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/generators/effect.ts","../../../src/generators/zod.ts","../../../src/generators/client.ts"],"sourcesContent":[],"mappings":";;;;;cAQa,uCACF;EADE,UAAA,EAAA,GAAA,gBAqNX,CAAA,IAAA,EAAA,KAAA,EApN+B,eAAA,CAoN/B;EAAA,cAAA,EAAA,CAAA,MAAA,cAAA,EAAA,QAAA,cAAA,EAAA,gBAAA,aAAA,CAAA;EAAA,gBApNS,EAAA,CAAA,MAAA,cAAA,EAAA,UAAA,cAAA,EAAA,gBAAA,aAAA,CAAA;EAAsB,sBAAA,EAAA,CAAA,YAAA,cAAA,EAAA,SAAA,iBAAA,EAAA,IAAA,EAAA,MAAA,EAAA,gBAAA,+DAAA;;;;;;;;UCDhB,yBAAA,SAAkC;EDAtC;EAqNX,IAAA,CAAA,EAAA,OAAA;;AApN+B,cCuBpB,wBDvBoB,EAAA,CAAA;EAAA,IAAA;EAAA,GAAA;AAAA,CAAA,EC0B9B,yBD1B8B,EAAA,GAAA;+CC0BL,eAAA;;;;;;;;;;;UCzBX,6BAAA;UACP;;iBAGM,+BAAA,UACL,gCACR"}
|
package/dist/generators/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { __toESM } from "../chunk-
|
|
2
|
-
import { DocumentContext, NotImplementedError, ensureImport, ensureNamespaceImport, getKey, helpers_exports, notImplementedStatement, require_lib } from "../helpers-
|
|
1
|
+
import { __toESM } from "../chunk-DYFKRlHt.js";
|
|
2
|
+
import { DocumentContext, NotImplementedError, ensureImport, ensureNamespaceImport, getKey, helpers_exports, notImplementedStatement, require_lib } from "../helpers-CqzmoMek.js";
|
|
3
3
|
import { Context, Effect } from "effect";
|
|
4
4
|
import escapeRegex from "regex-escape";
|
|
5
5
|
|
|
@@ -177,13 +177,14 @@ function createSchemaGenerator(options) {
|
|
|
177
177
|
const schemaKeyIdentifier = import_lib$3.identifier(schemaKey.upper);
|
|
178
178
|
if (options.experimental_includeTypes) schemaKeyIdentifier.typeAnnotation = import_lib$3.tsTypeAnnotation(import_lib$3.tsTypeReference(options.types.schema, import_lib$3.tsTypeParameterInstantiation([schemaExpression.typeDecoded, schemaExpression.typeEncoded])));
|
|
179
179
|
ctx.schemas.set(schemaName, [import_lib$3.exportNamedDeclaration(import_lib$3.variableDeclaration("const", [import_lib$3.variableDeclarator(schemaKeyIdentifier, schemaExpression.expression)])), import_lib$3.exportNamedDeclaration(import_lib$3.tsTypeAliasDeclaration(import_lib$3.identifier(schemaKey.upper), null, import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))]))))]);
|
|
180
|
+
ctx.schemaTypeMeta.set(schemaName, schemaExpression.typeMeta);
|
|
180
181
|
ctx.processingSchemas.delete(schemaName);
|
|
181
182
|
}
|
|
182
183
|
return {
|
|
183
184
|
expression: import_lib$3.identifier(schemaKey.upper),
|
|
184
185
|
typeDecoded: import_lib$3.tsTypeReference(options.types.typeDecoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
185
186
|
typeEncoded: import_lib$3.tsTypeReference(options.types.typeEncoded, import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsTypeQuery(import_lib$3.identifier(schemaKey.upper))])),
|
|
186
|
-
typeMeta
|
|
187
|
+
typeMeta: ctx.schemaTypeMeta.get(schemaName)
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
190
|
if (schema.deprecated) if (options.deprecationHandling === "optional") typeMeta.optional = true;
|
|
@@ -203,6 +204,23 @@ function createSchemaGenerator(options) {
|
|
|
203
204
|
typeMeta
|
|
204
205
|
};
|
|
205
206
|
}
|
|
207
|
+
if (schema.allOf) {
|
|
208
|
+
const results = yield* Effect.forEach((schema$1) => ensureSchema(schema$1))(schema.allOf);
|
|
209
|
+
let result;
|
|
210
|
+
if (results.length === 1) result = results[0];
|
|
211
|
+
else result = {
|
|
212
|
+
expression: options.schema[results.every((i) => i.typeMeta.isObject) ? "objectExtend" : "intersection"](results.map((result$1) => result$1.expression)),
|
|
213
|
+
typeDecoded: import_lib$3.tsIntersectionType(results.map((result$1) => result$1.typeDecoded)),
|
|
214
|
+
typeEncoded: import_lib$3.tsIntersectionType(results.map((result$1) => result$1.typeEncoded)),
|
|
215
|
+
typeMeta
|
|
216
|
+
};
|
|
217
|
+
if ("nullable" in schema && schema.nullable) {
|
|
218
|
+
result.expression = options.modifiers.nullable(result.expression);
|
|
219
|
+
result.typeDecoded = import_lib$3.tsUnionType([result.typeDecoded, import_lib$3.tsNullKeyword()]);
|
|
220
|
+
result.typeEncoded = import_lib$3.tsUnionType([result.typeEncoded, import_lib$3.tsNullKeyword()]);
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
206
224
|
if (schema.enum) {
|
|
207
225
|
const unsupportedEnumValue = schema.enum.find((i) => typeof i !== "string" && typeof i !== "number" && typeof i !== "boolean" && i !== null);
|
|
208
226
|
if (unsupportedEnumValue !== void 0) return yield* new NotImplementedError({ message: `Unsupported 'enum' value: ${JSON.stringify(unsupportedEnumValue)}` });
|
|
@@ -248,6 +266,7 @@ function createSchemaGenerator(options) {
|
|
|
248
266
|
typeMeta
|
|
249
267
|
};
|
|
250
268
|
case "object": {
|
|
269
|
+
typeMeta.isObject = true;
|
|
251
270
|
const object = import_lib$3.objectExpression([]);
|
|
252
271
|
const objectTypeDecoded = import_lib$3.tsTypeLiteral([]);
|
|
253
272
|
const objectTypeEncoded = import_lib$3.tsTypeLiteral([]);
|
|
@@ -292,11 +311,13 @@ function createSchemaGenerator(options) {
|
|
|
292
311
|
typeMeta
|
|
293
312
|
};
|
|
294
313
|
}
|
|
295
|
-
case "null":
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
314
|
+
case "null":
|
|
315
|
+
typeMeta.isNull = true;
|
|
316
|
+
return {
|
|
317
|
+
expression: options.schema.null,
|
|
318
|
+
...equivalentType(import_lib$3.tsNullKeyword()),
|
|
319
|
+
typeMeta
|
|
320
|
+
};
|
|
300
321
|
case void 0: return {
|
|
301
322
|
expression: options.schema.unknown,
|
|
302
323
|
...equivalentType(import_lib$3.tsUnknownKeyword()),
|
|
@@ -310,11 +331,6 @@ function createSchemaGenerator(options) {
|
|
|
310
331
|
const applyModifiers = Effect.fn(function* (expression, schema) {
|
|
311
332
|
if ("$ref" in schema) return expression;
|
|
312
333
|
const modified = { ...expression };
|
|
313
|
-
if ("nullable" in schema && schema.nullable) {
|
|
314
|
-
modified.expression = options.modifiers.nullable(modified.expression);
|
|
315
|
-
modified.typeDecoded = import_lib$3.tsUnionType([modified.typeDecoded, import_lib$3.tsNullKeyword()]);
|
|
316
|
-
modified.typeEncoded = import_lib$3.tsUnionType([modified.typeEncoded, import_lib$3.tsNullKeyword()]);
|
|
317
|
-
}
|
|
318
334
|
if (options.supportsImmutability) if (schema.readOnly) {
|
|
319
335
|
modified.expression = options.modifiers.immutable(modified.expression);
|
|
320
336
|
modified.typeMeta ??= {};
|
|
@@ -328,6 +344,7 @@ function createSchemaGenerator(options) {
|
|
|
328
344
|
if (schema$1.oneOf) return schema$1.oneOf;
|
|
329
345
|
return [schema$1];
|
|
330
346
|
}).flatMap((schema$1) => {
|
|
347
|
+
if (typeof schema$1 === "boolean") return [];
|
|
331
348
|
if ("$ref" in schema$1) return [schema$1];
|
|
332
349
|
if (Array.isArray(schema$1.type)) return schema$1.type.map((type) => ({
|
|
333
350
|
...schema$1,
|
|
@@ -335,15 +352,27 @@ function createSchemaGenerator(options) {
|
|
|
335
352
|
}));
|
|
336
353
|
return [schema$1];
|
|
337
354
|
});
|
|
338
|
-
|
|
355
|
+
let expressions = [];
|
|
339
356
|
for (const schema$1 of schemas) expressions.push(yield* applyModifiers(yield* getBaseEffectSchema(schema$1), schema$1));
|
|
340
|
-
|
|
357
|
+
let isNullable = false;
|
|
358
|
+
if (expressions.some((e) => e.typeMeta?.isNull)) {
|
|
359
|
+
isNullable = true;
|
|
360
|
+
expressions = expressions.filter((e) => !e.typeMeta?.isNull);
|
|
361
|
+
}
|
|
362
|
+
let result;
|
|
363
|
+
if (expressions.length === 1) result = expressions[0];
|
|
364
|
+
else result = {
|
|
341
365
|
expression: options.schema.union(expressions.map((e) => e.expression)),
|
|
342
366
|
typeDecoded: import_lib$3.tsUnionType(expressions.map((e) => e.typeDecoded)),
|
|
343
367
|
typeEncoded: import_lib$3.tsUnionType(expressions.map((e) => e.typeEncoded)),
|
|
344
368
|
typeMeta: {}
|
|
345
369
|
};
|
|
346
|
-
|
|
370
|
+
if (isNullable) {
|
|
371
|
+
result.expression = options.modifiers.nullable(result.expression);
|
|
372
|
+
result.typeDecoded = import_lib$3.tsUnionType([result.typeDecoded, import_lib$3.tsNullKeyword()]);
|
|
373
|
+
result.typeEncoded = import_lib$3.tsUnionType([result.typeEncoded, import_lib$3.tsNullKeyword()]);
|
|
374
|
+
}
|
|
375
|
+
return result;
|
|
347
376
|
});
|
|
348
377
|
const ensureParametersSchema = Effect.fn(function* (operationKey, method, path) {
|
|
349
378
|
const ctx = yield* DocumentContext;
|
|
@@ -512,6 +541,8 @@ const createEffectSchemaGenerator = (options) => ({
|
|
|
512
541
|
schema: {
|
|
513
542
|
record: (key, value) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Record")), [import_lib$2.objectExpression([import_lib$2.objectProperty(import_lib$2.identifier("key"), key), import_lib$2.objectProperty(import_lib$2.identifier("value"), value)])]),
|
|
514
543
|
union: (expressions) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Union")), expressions),
|
|
544
|
+
intersection: (expressions) => expressions.reduce((a, b) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("extend")), [a, b])),
|
|
545
|
+
objectExtend: (expressions) => expressions.reduce((a, b) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("extend")), [a, b])),
|
|
515
546
|
enum: (expressions) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Literal")), expressions),
|
|
516
547
|
instanceOf: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("instanceOf")),
|
|
517
548
|
boolean: import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Boolean")),
|
|
@@ -560,8 +591,12 @@ const createEffectSchemaGenerator = (options) => ({
|
|
|
560
591
|
//#endregion
|
|
561
592
|
//#region src/generators/zod.ts
|
|
562
593
|
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
594
|
+
const z = import_lib$1.identifier("z");
|
|
595
|
+
function getObjectShape(expression) {
|
|
596
|
+
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && expression.callee.object.type === "Identifier" && expression.callee.object.name === "z" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "object" && expression.arguments.length === 1 && expression.arguments[0]?.type === "ObjectExpression") return expression.arguments[0];
|
|
597
|
+
return import_lib$1.memberExpression(expression, import_lib$1.identifier("shape"));
|
|
598
|
+
}
|
|
563
599
|
const createZodSchemaGenerator = ({ mini = false,...options }) => {
|
|
564
|
-
const z = import_lib$1.identifier("z");
|
|
565
600
|
const maybeExtension = (expression, extension, args) => mini ? import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier(extension)), [expression, ...args]) : import_lib$1.callExpression(import_lib$1.memberExpression(expression, import_lib$1.identifier(extension)), args);
|
|
566
601
|
return {
|
|
567
602
|
...createSchemaGenerator({
|
|
@@ -582,6 +617,8 @@ const createZodSchemaGenerator = ({ mini = false,...options }) => {
|
|
|
582
617
|
schema: {
|
|
583
618
|
record: (key, value) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("record")), [key, value]),
|
|
584
619
|
union: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("union")), [import_lib$1.arrayExpression(expressions)]),
|
|
620
|
+
intersection: (expressions) => expressions.reduce((a, b) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("intersection")), [a, b])),
|
|
621
|
+
objectExtend: (expressions) => expressions.reduce((a, b) => import_lib$1.callExpression(import_lib$1.memberExpression(mini ? z : a, import_lib$1.identifier("extend")), [...mini ? [a] : [], getObjectShape(b)])),
|
|
585
622
|
enum: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("enum")), [import_lib$1.arrayExpression(expressions)]),
|
|
586
623
|
instanceOf: import_lib$1.memberExpression(z, import_lib$1.identifier("instanceof")),
|
|
587
624
|
boolean: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("boolean")), []),
|