@sohcah/openapi-generator 0.2.0 → 0.2.2
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.js +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/generators/index.d.ts +3 -3
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +33 -3
- package/dist/generators/index.js.map +1 -1
- package/dist/{index-DY2v-Q37.d.ts → index-nKXk7_RC.d.ts} +3 -3
- package/dist/index-nKXk7_RC.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{src-CjChjKnL.js → src-BhVleMDu.js} +3 -6
- package/dist/{src-CjChjKnL.js.map → src-BhVleMDu.js.map} +1 -1
- package/dist/{types-DMB5w9Tt.d.ts → types-CHhQKnbs.d.ts} +4 -3
- package/dist/types-CHhQKnbs.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/index-DY2v-Q37.d.ts.map +0 -1
- package/dist/types-DMB5w9Tt.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { generateToFile } from "./src-
|
|
2
|
+
import { generateToFile } from "./src-BhVleMDu.js";
|
|
3
3
|
import "./helpers-CqzmoMek.js";
|
|
4
4
|
import { Command, Options } from "@effect/cli";
|
|
5
5
|
import { NodeContext, NodeRuntime } from "@effect/platform-node";
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import { OpenapiGenerateToFileOptions } from "./index-
|
|
1
|
+
import "./types-CHhQKnbs.js";
|
|
2
|
+
import { OpenapiGenerateToFileOptions } from "./index-nKXk7_RC.js";
|
|
3
3
|
|
|
4
4
|
//#region src/config.d.ts
|
|
5
5
|
declare const defineConfig: (config: OpenapiGenerateToFileOptions) => OpenapiGenerateToFileOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentContext, HttpMethod, ImportReference, NotImplementedError, OpenApiClientGenerator, OpenApiGenerator, OpenApiParametersSchema, OpenApiResponseSchema, OpenApiSchemaGenerator, OperationKey, OperationObject, SchemaGeneratorOptions, SchemaObject, createSchemaGenerator, 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-CHhQKnbs.js";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import * as t from "@babel/types";
|
|
4
4
|
|
|
@@ -10,7 +10,7 @@ declare const createEffectSchemaGenerator: (options: SchemaGeneratorOptions) =>
|
|
|
10
10
|
ensureParametersSchema: (operationKey: OperationKey, operation: OperationObject, path: string) => Effect.Effect<OpenApiParametersSchema, NotImplementedError, DocumentContext>;
|
|
11
11
|
ensureResponseSchema: (operationKey: OperationKey, operation: OperationObject) => Effect.Effect<OpenApiResponseSchema, NotImplementedError, DocumentContext>;
|
|
12
12
|
schemaType: t.TSEntityName;
|
|
13
|
-
processSchema
|
|
13
|
+
processSchema: (schema: SchemaObject) => Effect.Effect<void, NotImplementedError, DocumentContext>;
|
|
14
14
|
processOperation?: (operationKey: OperationKey, path: string, method: HttpMethod, operation: OperationObject) => Effect.Effect<void, NotImplementedError, DocumentContext>;
|
|
15
15
|
};
|
|
16
16
|
//#endregion
|
|
@@ -29,7 +29,7 @@ declare const createZodSchemaGenerator: ({
|
|
|
29
29
|
ensureParametersSchema: (operationKey: OperationKey, operation: OperationObject, path: string) => Effect.Effect<OpenApiParametersSchema, NotImplementedError, DocumentContext>;
|
|
30
30
|
ensureResponseSchema: (operationKey: OperationKey, operation: OperationObject) => Effect.Effect<OpenApiResponseSchema, NotImplementedError, DocumentContext>;
|
|
31
31
|
schemaType: t.TSEntityName;
|
|
32
|
-
processSchema
|
|
32
|
+
processSchema: (schema: SchemaObject) => Effect.Effect<void, NotImplementedError, DocumentContext>;
|
|
33
33
|
processOperation?: (operationKey: OperationKey, path: string, method: HttpMethod, operation: OperationObject) => Effect.Effect<void, NotImplementedError, DocumentContext>;
|
|
34
34
|
};
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,gBAwOX,CAAA,IAAA,EAAA,KAAA,EAvO+B,eAAA,CAuO/B;EAAA,cAAA,EAAA,CAAA,MAAA,cAAA,EAAA,QAAA,cAAA,EAAA,gBAAA,aAAA,CAAA;EAAA,gBAvOS,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;EAwOX,IAAA,CAAA,EAAA,OAAA;;AAvO+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
|
@@ -287,6 +287,26 @@ function createSchemaGenerator(options) {
|
|
|
287
287
|
objectTypeDecoded.members.push(decodedMember);
|
|
288
288
|
objectTypeEncoded.members.push(encodedMember);
|
|
289
289
|
}
|
|
290
|
+
if (schema.additionalProperties) {
|
|
291
|
+
const valueSchema = yield* ensureSchema(schema.additionalProperties === true ? { type: void 0 } : schema.additionalProperties);
|
|
292
|
+
if (object.properties.length === 0) return {
|
|
293
|
+
expression: options.schema.record(options.schema.string, valueSchema.expression),
|
|
294
|
+
typeDecoded: import_lib$3.tsTypeReference(import_lib$3.identifier("Record"), import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsStringKeyword(), valueSchema.typeDecoded])),
|
|
295
|
+
typeEncoded: import_lib$3.tsTypeReference(import_lib$3.identifier("Record"), import_lib$3.tsTypeParameterInstantiation([import_lib$3.tsStringKeyword(), valueSchema.typeEncoded])),
|
|
296
|
+
typeMeta
|
|
297
|
+
};
|
|
298
|
+
const expression = options.schema.catchall(import_lib$3.callExpression(options.schema.object, [object]), valueSchema.expression);
|
|
299
|
+
const keyParam = import_lib$3.identifier("key");
|
|
300
|
+
keyParam.typeAnnotation = import_lib$3.tsTypeAnnotation(import_lib$3.tsStringKeyword());
|
|
301
|
+
const indexSignatureDecoded = import_lib$3.tsIndexSignature([keyParam], import_lib$3.tsTypeAnnotation(valueSchema.typeDecoded));
|
|
302
|
+
const indexSignatureEncoded = import_lib$3.tsIndexSignature([keyParam], import_lib$3.tsTypeAnnotation(valueSchema.typeEncoded));
|
|
303
|
+
return {
|
|
304
|
+
expression,
|
|
305
|
+
typeDecoded: import_lib$3.tsTypeLiteral([...objectTypeDecoded.members, indexSignatureDecoded]),
|
|
306
|
+
typeEncoded: import_lib$3.tsTypeLiteral([...objectTypeEncoded.members, indexSignatureEncoded]),
|
|
307
|
+
typeMeta
|
|
308
|
+
};
|
|
309
|
+
}
|
|
290
310
|
return {
|
|
291
311
|
expression: import_lib$3.callExpression(options.schema.object, [object]),
|
|
292
312
|
typeDecoded: objectTypeDecoded,
|
|
@@ -492,7 +512,7 @@ function createSchemaGenerator(options) {
|
|
|
492
512
|
};
|
|
493
513
|
});
|
|
494
514
|
const processSchema = Effect.fn(function* (schema) {
|
|
495
|
-
if (options.includeSchemas
|
|
515
|
+
if (options.includeSchemas) yield* ensureSchema(schema);
|
|
496
516
|
});
|
|
497
517
|
const processOperation = Effect.fn(function* (operationKey, path, _method, operation) {
|
|
498
518
|
if (options.includeOperations) {
|
|
@@ -540,6 +560,7 @@ const createEffectSchemaGenerator = (options) => ({
|
|
|
540
560
|
},
|
|
541
561
|
schema: {
|
|
542
562
|
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)])]),
|
|
563
|
+
catchall: (object, value) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("extend")), [object, 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"), import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("String"))), import_lib$2.objectProperty(import_lib$2.identifier("value"), value)])])]),
|
|
543
564
|
union: (expressions) => import_lib$2.callExpression(import_lib$2.memberExpression(import_lib$2.identifier("Schema"), import_lib$2.identifier("Union")), expressions),
|
|
544
565
|
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
566
|
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])),
|
|
@@ -591,8 +612,12 @@ const createEffectSchemaGenerator = (options) => ({
|
|
|
591
612
|
//#endregion
|
|
592
613
|
//#region src/generators/zod.ts
|
|
593
614
|
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
615
|
+
const z = import_lib$1.identifier("z");
|
|
616
|
+
function getObjectShape(expression) {
|
|
617
|
+
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];
|
|
618
|
+
return import_lib$1.memberExpression(expression, import_lib$1.identifier("shape"));
|
|
619
|
+
}
|
|
594
620
|
const createZodSchemaGenerator = ({ mini = false,...options }) => {
|
|
595
|
-
const z = import_lib$1.identifier("z");
|
|
596
621
|
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);
|
|
597
622
|
return {
|
|
598
623
|
...createSchemaGenerator({
|
|
@@ -612,9 +637,10 @@ const createZodSchemaGenerator = ({ mini = false,...options }) => {
|
|
|
612
637
|
},
|
|
613
638
|
schema: {
|
|
614
639
|
record: (key, value) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("record")), [key, value]),
|
|
640
|
+
catchall: (object, value) => import_lib$1.callExpression(import_lib$1.memberExpression(mini ? z : object, import_lib$1.identifier("catchall")), [...mini ? [object] : [], value]),
|
|
615
641
|
union: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("union")), [import_lib$1.arrayExpression(expressions)]),
|
|
616
642
|
intersection: (expressions) => expressions.reduce((a, b) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("intersection")), [a, b])),
|
|
617
|
-
objectExtend: (expressions) => expressions.reduce((a, b) => import_lib$1.callExpression(import_lib$1.memberExpression(mini ? z : a, import_lib$1.identifier("extend")), [...mini ? [a] : [], b])),
|
|
643
|
+
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)])),
|
|
618
644
|
enum: (expressions) => import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("enum")), [import_lib$1.arrayExpression(expressions)]),
|
|
619
645
|
instanceOf: import_lib$1.memberExpression(z, import_lib$1.identifier("instanceof")),
|
|
620
646
|
boolean: import_lib$1.callExpression(import_lib$1.memberExpression(z, import_lib$1.identifier("boolean")), []),
|
|
@@ -680,6 +706,10 @@ function createReactQueryClientGenerator(options) {
|
|
|
680
706
|
yield* ensureApi();
|
|
681
707
|
if (options.schema.initialize) yield* options.schema.initialize();
|
|
682
708
|
}),
|
|
709
|
+
processSchema: Effect.fn(function* (schema) {
|
|
710
|
+
yield* ensureApi();
|
|
711
|
+
yield* options.schema.processSchema(schema);
|
|
712
|
+
}),
|
|
683
713
|
processOperation: Effect.fn(function* (operationKey, path, method, operation) {
|
|
684
714
|
const parametersSchema = yield* options.schema.ensureParametersSchema(operationKey, operation, path);
|
|
685
715
|
const responseSchema = yield* options.schema.ensureResponseSchema(operationKey, operation);
|