@effect/openapi-generator 4.0.0-beta.8 → 4.0.0-beta.81
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/HttpApiTransformer.d.ts +41 -0
- package/dist/HttpApiTransformer.d.ts.map +1 -0
- package/dist/HttpApiTransformer.js +393 -0
- package/dist/HttpApiTransformer.js.map +1 -0
- package/dist/JsonSchemaGenerator.d.ts +25 -3
- package/dist/JsonSchemaGenerator.d.ts.map +1 -1
- package/dist/JsonSchemaGenerator.js +178 -47
- package/dist/JsonSchemaGenerator.js.map +1 -1
- package/dist/OpenApiGenerator.d.ts +81 -7
- package/dist/OpenApiGenerator.d.ts.map +1 -1
- package/dist/OpenApiGenerator.js +763 -119
- package/dist/OpenApiGenerator.js.map +1 -1
- package/dist/OpenApiPatch.d.ts +47 -24
- package/dist/OpenApiPatch.d.ts.map +1 -1
- package/dist/OpenApiPatch.js +42 -19
- package/dist/OpenApiPatch.js.map +1 -1
- package/dist/OpenApiTransformer.d.ts +85 -12
- package/dist/OpenApiTransformer.d.ts.map +1 -1
- package/dist/OpenApiTransformer.js +85 -8
- package/dist/OpenApiTransformer.js.map +1 -1
- package/dist/ParsedOperation.d.ts +184 -1
- package/dist/ParsedOperation.d.ts.map +1 -1
- package/dist/ParsedOperation.js +32 -0
- package/dist/ParsedOperation.js.map +1 -1
- package/dist/Utils.d.ts +51 -0
- package/dist/Utils.d.ts.map +1 -1
- package/dist/Utils.js +61 -0
- package/dist/Utils.js.map +1 -1
- package/dist/main.d.ts +12 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +41 -8
- package/dist/main.js.map +1 -1
- package/package.json +10 -8
- package/src/HttpApiTransformer.ts +552 -0
- package/src/JsonSchemaGenerator.ts +272 -47
- package/src/OpenApiGenerator.ts +1057 -165
- package/src/OpenApiPatch.ts +56 -31
- package/src/OpenApiTransformer.ts +89 -12
- package/src/ParsedOperation.ts +235 -1
- package/src/Utils.ts +61 -0
- package/src/main.ts +58 -10
|
@@ -1,7 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate TypeScript source for JSON Schema declarations extracted from
|
|
3
|
+
* OpenAPI documents.
|
|
4
|
+
*
|
|
5
|
+
* This module is the schema-rendering stage of the OpenAPI generator. Callers
|
|
6
|
+
* register named OpenAPI 3.0 or 3.1 schemas, provide the reusable component
|
|
7
|
+
* definitions for the document, and receive source text containing exported
|
|
8
|
+
* TypeScript aliases plus Effect Schema runtime values. The generator first
|
|
9
|
+
* normalizes OpenAPI-specific schema shapes into Effect's JSON Schema model,
|
|
10
|
+
* then delegates recursive analysis and runtime expression construction to
|
|
11
|
+
* `SchemaRepresentation`.
|
|
12
|
+
*
|
|
13
|
+
* The renderer keeps the emitted module usable for both human maintainers and
|
|
14
|
+
* automated code-generation consumers by grouping recursive declarations,
|
|
15
|
+
* reusable references, and locally registered schemas. It also contains the
|
|
16
|
+
* HttpApi-specific multipart file substitutions that map generated schemas to
|
|
17
|
+
* Effect's multipart runtime types.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
20
|
+
*/
|
|
1
21
|
import * as Arr from "effect/Array";
|
|
2
22
|
import * as JsonSchema from "effect/JsonSchema";
|
|
3
23
|
import * as Rec from "effect/Record";
|
|
4
24
|
import * as SchemaRepresentation from "effect/SchemaRepresentation";
|
|
25
|
+
/**
|
|
26
|
+
* Create a stateful JSON Schema code generator for OpenAPI-derived schemas.
|
|
27
|
+
*
|
|
28
|
+
* **Details**
|
|
29
|
+
*
|
|
30
|
+
* Schemas registered with the returned generator are converted into TypeScript
|
|
31
|
+
* type aliases and Effect Schema runtime declarations, with reusable OpenAPI
|
|
32
|
+
* component definitions supplied at generation time.
|
|
33
|
+
*
|
|
34
|
+
* @category code generation
|
|
35
|
+
* @since 4.0.0
|
|
36
|
+
*/
|
|
5
37
|
export function make() {
|
|
6
38
|
const store = {};
|
|
7
39
|
function addSchema(name, schema) {
|
|
@@ -12,64 +44,163 @@ export function make() {
|
|
|
12
44
|
return name;
|
|
13
45
|
}
|
|
14
46
|
function generate(source, components, typeOnly, options) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (const [name, js] of Object.entries(store)) {
|
|
19
|
-
nameMap.push(name);
|
|
20
|
-
schemas.push(fromSchemaOpenApi(js).schema);
|
|
47
|
+
const generated = makeCodeDocument(source, components, options);
|
|
48
|
+
if (generated === undefined) {
|
|
49
|
+
return "";
|
|
21
50
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
return options?.onEnter?.(out) ?? out;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const codeDocument = SchemaRepresentation.toCodeDocument(multiDocument);
|
|
39
|
-
const nonRecursives = codeDocument.references.nonRecursives.map(({
|
|
40
|
-
$ref,
|
|
41
|
-
code
|
|
42
|
-
}) => renderSchema($ref, code));
|
|
43
|
-
const recursives = Object.entries(codeDocument.references.recursives).map(([$ref, code]) => renderSchema($ref, code));
|
|
44
|
-
const codes = codeDocument.codes.map((code, i) => renderSchema(nameMap[i], code));
|
|
45
|
-
const s = render("non-recursive definitions", nonRecursives) + render("recursive definitions", recursives) + render("schemas", codes);
|
|
46
|
-
return s;
|
|
51
|
+
const nonRecursiveReferences = generated.codeDocument.references.nonRecursives;
|
|
52
|
+
const recursiveReferences = Object.entries(generated.codeDocument.references.recursives);
|
|
53
|
+
const nonRecursives = nonRecursiveReferences.map(({
|
|
54
|
+
$ref,
|
|
55
|
+
code
|
|
56
|
+
}) => renderSchemaTypeAndRuntime($ref, code, typeOnly));
|
|
57
|
+
const recursiveDeclarations = [];
|
|
58
|
+
const recursives = [];
|
|
59
|
+
if (typeOnly) {
|
|
60
|
+
for (const [$ref, code] of recursiveReferences) {
|
|
61
|
+
recursives.push(renderSchemaTypeAndRuntime($ref, code, true));
|
|
62
|
+
}
|
|
47
63
|
} else {
|
|
64
|
+
const recursivelyForwardReferenced = collectForwardReferencedRecursives(nonRecursiveReferences, recursiveReferences);
|
|
65
|
+
const recursiveInternalNames = makeRecursiveInternalNameMap(recursivelyForwardReferenced, [...nonRecursiveReferences.map(({
|
|
66
|
+
$ref
|
|
67
|
+
}) => $ref), ...recursiveReferences.map(([$ref]) => $ref), ...generated.nameMap]);
|
|
68
|
+
for (const [$ref, code] of recursiveReferences) {
|
|
69
|
+
if (recursivelyForwardReferenced.has($ref)) {
|
|
70
|
+
const internalName = recursiveInternalNames.get($ref);
|
|
71
|
+
recursiveDeclarations.push(renderRecursiveReferenceDeclaration($ref, code, internalName));
|
|
72
|
+
recursives.push(`const ${internalName} = ${code.runtime}`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
recursives.push(renderSchemaTypeAndRuntime($ref, code, false));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const codes = generated.codeDocument.codes.map((code, i) => renderSchemaTypeAndRuntime(generated.nameMap[i], code, typeOnly));
|
|
79
|
+
return render("recursive declarations", recursiveDeclarations) + render("non-recursive definitions", nonRecursives) + render("recursive definitions", recursives) + render("schemas", codes);
|
|
80
|
+
}
|
|
81
|
+
function generateHttpApi(source, components, options) {
|
|
82
|
+
const generated = makeCodeDocument(source, components, options);
|
|
83
|
+
if (generated === undefined) {
|
|
48
84
|
return "";
|
|
49
85
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
const nonRecursiveReferences = generated.codeDocument.references.nonRecursives;
|
|
87
|
+
const recursiveReferences = Object.entries(generated.codeDocument.references.recursives);
|
|
88
|
+
const nonRecursives = nonRecursiveReferences.map(({
|
|
89
|
+
$ref,
|
|
90
|
+
code
|
|
91
|
+
}) => renderSchemaTypeAndRuntime($ref, code, false, options?.multipartSchemaRefs));
|
|
92
|
+
const recursivelyForwardReferenced = collectForwardReferencedRecursives(nonRecursiveReferences, recursiveReferences);
|
|
93
|
+
const recursiveInternalNames = makeRecursiveInternalNameMap(recursivelyForwardReferenced, [...nonRecursiveReferences.map(({
|
|
94
|
+
$ref
|
|
95
|
+
}) => $ref), ...recursiveReferences.map(([$ref]) => $ref), ...generated.nameMap]);
|
|
96
|
+
const recursiveDeclarations = [];
|
|
97
|
+
const recursives = [];
|
|
98
|
+
for (const [$ref, code] of recursiveReferences) {
|
|
99
|
+
if (recursivelyForwardReferenced.has($ref)) {
|
|
100
|
+
const internalName = recursiveInternalNames.get($ref);
|
|
101
|
+
recursiveDeclarations.push(renderRecursiveReferenceDeclaration($ref, code, internalName));
|
|
102
|
+
recursives.push(`const ${internalName} = ${code.runtime}`);
|
|
103
|
+
continue;
|
|
56
104
|
}
|
|
105
|
+
recursives.push(renderSchemaTypeAndRuntime($ref, code, false, options?.multipartSchemaRefs));
|
|
57
106
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
107
|
+
const codes = generated.codeDocument.codes.map((code, i) => renderSchemaTypeAndRuntime(generated.nameMap[i], code, false, options?.multipartSchemaRefs));
|
|
108
|
+
return render("recursive declarations", recursiveDeclarations) + render("non-recursive definitions", nonRecursives) + render("recursive definitions", recursives) + render("schemas", codes);
|
|
109
|
+
}
|
|
110
|
+
function makeCodeDocument(source, components, options) {
|
|
111
|
+
const nameMap = [];
|
|
112
|
+
const schemas = [];
|
|
113
|
+
const definitions = Rec.map(components, js => fromSchemaOpenApi(source, js).schema);
|
|
114
|
+
for (const [name, js] of Object.entries(store)) {
|
|
115
|
+
nameMap.push(name);
|
|
116
|
+
schemas.push(fromSchemaOpenApi(source, js).schema);
|
|
64
117
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return "// " + title + "\n" + as.join("\n") + "\n";
|
|
118
|
+
if (!Arr.isArrayNonEmpty(schemas)) {
|
|
119
|
+
return;
|
|
68
120
|
}
|
|
121
|
+
const multiDocument = SchemaRepresentation.fromJsonSchemaMultiDocument({
|
|
122
|
+
dialect: "draft-2020-12",
|
|
123
|
+
schemas,
|
|
124
|
+
definitions
|
|
125
|
+
}, {
|
|
126
|
+
onEnter(js) {
|
|
127
|
+
const out = {
|
|
128
|
+
...js
|
|
129
|
+
};
|
|
130
|
+
if (out.type === "object" && out.additionalProperties === undefined) {
|
|
131
|
+
out.additionalProperties = false;
|
|
132
|
+
}
|
|
133
|
+
return options?.onEnter?.(out) ?? out;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
nameMap,
|
|
138
|
+
codeDocument: SchemaRepresentation.toCodeDocument(multiDocument)
|
|
139
|
+
};
|
|
69
140
|
}
|
|
70
141
|
return {
|
|
71
142
|
addSchema,
|
|
72
|
-
generate
|
|
143
|
+
generate,
|
|
144
|
+
generateHttpApi
|
|
73
145
|
};
|
|
74
146
|
}
|
|
147
|
+
function fromSchemaOpenApi(source, jsonSchema) {
|
|
148
|
+
switch (source) {
|
|
149
|
+
case "openapi-3.1":
|
|
150
|
+
return JsonSchema.fromSchemaOpenApi3_1(jsonSchema);
|
|
151
|
+
case "openapi-3.0":
|
|
152
|
+
return JsonSchema.fromSchemaOpenApi3_0(jsonSchema);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function renderSchemaTypeAndRuntime($ref, code, typeOnly, multipartSchemaRefs) {
|
|
156
|
+
if (!typeOnly && multipartSchemaRefs !== undefined) {
|
|
157
|
+
if ($ref === multipartSchemaRefs.singleFile) {
|
|
158
|
+
return [`export type ${$ref} = Multipart.PersistedFile`, `export const ${$ref} = Multipart.SingleFileSchema`].join("\n");
|
|
159
|
+
}
|
|
160
|
+
if ($ref === multipartSchemaRefs.files) {
|
|
161
|
+
return [`export type ${$ref} = ReadonlyArray<Multipart.PersistedFile>`, `export const ${$ref} = Multipart.FilesSchema`].join("\n");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const strings = [`export type ${$ref} = ${code.Type}`];
|
|
165
|
+
if (!typeOnly) {
|
|
166
|
+
strings.push(`export const ${$ref} = ${code.runtime}`);
|
|
167
|
+
}
|
|
168
|
+
return strings.join("\n");
|
|
169
|
+
}
|
|
170
|
+
function renderRecursiveReferenceDeclaration($ref, code, internalName) {
|
|
171
|
+
return [`export type ${$ref} = ${code.Type}`, `export const ${$ref} = Schema.suspend((): Schema.Codec<${$ref}> => ${internalName})`].join("\n");
|
|
172
|
+
}
|
|
173
|
+
function render(title, as) {
|
|
174
|
+
if (as.length === 0) return "";
|
|
175
|
+
return "// " + title + "\n" + as.join("\n") + "\n";
|
|
176
|
+
}
|
|
177
|
+
const tokenPattern = /[A-Za-z_$][A-Za-z0-9_$]*/g;
|
|
178
|
+
function collectForwardReferencedRecursives(nonRecursives, recursives) {
|
|
179
|
+
const recursiveNames = new Set(recursives.map(([name]) => name));
|
|
180
|
+
const referenced = new Set();
|
|
181
|
+
for (const {
|
|
182
|
+
code
|
|
183
|
+
} of nonRecursives) {
|
|
184
|
+
for (const token of code.runtime.matchAll(tokenPattern)) {
|
|
185
|
+
const identifier = token[0];
|
|
186
|
+
if (recursiveNames.has(identifier)) {
|
|
187
|
+
referenced.add(identifier);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return referenced;
|
|
192
|
+
}
|
|
193
|
+
function makeRecursiveInternalNameMap(recursiveNames, existingNames) {
|
|
194
|
+
const usedNames = new Set(existingNames);
|
|
195
|
+
const internalNames = new Map();
|
|
196
|
+
for (const name of recursiveNames) {
|
|
197
|
+
let candidate = `__recursive_${name}`;
|
|
198
|
+
while (usedNames.has(candidate)) {
|
|
199
|
+
candidate = `_${candidate}`;
|
|
200
|
+
}
|
|
201
|
+
usedNames.add(candidate);
|
|
202
|
+
internalNames.set(name, candidate);
|
|
203
|
+
}
|
|
204
|
+
return internalNames;
|
|
205
|
+
}
|
|
75
206
|
//# sourceMappingURL=JsonSchemaGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSchemaGenerator.js","names":["Arr","JsonSchema","Rec","SchemaRepresentation","make","store","addSchema","name","schema","Error","generate","source","components","typeOnly","options","
|
|
1
|
+
{"version":3,"file":"JsonSchemaGenerator.js","names":["Arr","JsonSchema","Rec","SchemaRepresentation","make","store","addSchema","name","schema","Error","generate","source","components","typeOnly","options","generated","makeCodeDocument","undefined","nonRecursiveReferences","codeDocument","references","nonRecursives","recursiveReferences","Object","entries","recursives","map","$ref","code","renderSchemaTypeAndRuntime","recursiveDeclarations","push","recursivelyForwardReferenced","collectForwardReferencedRecursives","recursiveInternalNames","makeRecursiveInternalNameMap","nameMap","has","internalName","get","renderRecursiveReferenceDeclaration","runtime","codes","i","render","generateHttpApi","multipartSchemaRefs","schemas","definitions","js","fromSchemaOpenApi","isArrayNonEmpty","multiDocument","fromJsonSchemaMultiDocument","dialect","onEnter","out","type","additionalProperties","toCodeDocument","jsonSchema","fromSchemaOpenApi3_1","fromSchemaOpenApi3_0","singleFile","join","files","strings","Type","title","as","length","tokenPattern","recursiveNames","Set","referenced","token","matchAll","identifier","add","existingNames","usedNames","internalNames","Map","candidate","set"],"sources":["../src/JsonSchemaGenerator.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;AAoBA,OAAO,KAAKA,GAAG,MAAM,cAAc;AACnC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,GAAG,MAAM,eAAe;AACpC,OAAO,KAAKC,oBAAoB,MAAM,6BAA6B;AAenE;;;;;;;;;;;;AAYA,OAAM,SAAUC,IAAIA,CAAA;EAClB,MAAMC,KAAK,GAA0C,EAAE;EAEvD,SAASC,SAASA,CAACC,IAAY,EAAEC,MAA6B;IAC5D,IAAID,IAAI,IAAIF,KAAK,EAAE;MACjB,MAAM,IAAII,KAAK,CAAC,UAAUF,IAAI,i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aAAa,CAAC;EACxC,MAAME,aAAa,GAAG,IAAIC,GAAG,EAAkB;EAE/C,KAAK,MAAM3E,IAAI,IAAIiE,cAAc,EAAE;IACjC,IAAIW,SAAS,GAAG,eAAe5E,IAAI,EAAE;IACrC,OAAOyE,SAAS,CAAC3C,GAAG,CAAC8C,SAAS,CAAC,EAAE;MAC/BA,SAAS,GAAG,IAAIA,SAAS,EAAE;IAC7B;IACAH,SAAS,CAACF,GAAG,CAACK,SAAS,CAAC;IACxBF,aAAa,CAACG,GAAG,CAAC7E,IAAI,EAAE4E,SAAS,CAAC;EACpC;EAEA,OAAOF,aAAa;AACtB","ignoreList":[]}
|
|
@@ -1,32 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `OpenApiGenerator` module orchestrates converting OpenAPI and Swagger
|
|
3
|
+
* documents into generated Effect source.
|
|
4
|
+
*
|
|
5
|
+
* It normalizes Swagger 2.0 input, resolves local references, builds the
|
|
6
|
+
* parsed operation model, registers request and response schemas, applies
|
|
7
|
+
* HttpApi-specific adaptations such as multipart helpers and security metadata,
|
|
8
|
+
* emits warnings for unsupported or lossy OpenAPI features, and then delegates
|
|
9
|
+
* final rendering to the HttpClient or HttpApi code generators.
|
|
10
|
+
*
|
|
11
|
+
* @since 4.0.0
|
|
12
|
+
*/
|
|
13
|
+
import * as Context from "effect/Context";
|
|
1
14
|
import * as Effect from "effect/Effect";
|
|
2
15
|
import type * as JsonSchema from "effect/JsonSchema";
|
|
3
16
|
import * as Layer from "effect/Layer";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
declare const OpenApiGenerator_base: ServiceMap.ServiceClass<OpenApiGenerator, "OpenApiGenerator", {
|
|
17
|
+
import type { OpenAPISpec, OpenAPISpecMethodName } from "effect/unstable/httpapi/OpenApi";
|
|
18
|
+
declare const OpenApiGenerator_base: Context.ServiceClass<OpenApiGenerator, "OpenApiGenerator", {
|
|
7
19
|
readonly generate: (spec: OpenAPISpec, options: OpenApiGenerateOptions) => Effect.Effect<string>;
|
|
8
20
|
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Service for turning OpenAPI or Swagger specifications into generated Effect
|
|
23
|
+
* HTTP client or HttpApi source code.
|
|
24
|
+
*
|
|
25
|
+
* @category services
|
|
26
|
+
* @since 4.0.0
|
|
27
|
+
*/
|
|
9
28
|
export declare class OpenApiGenerator extends OpenApiGenerator_base {
|
|
10
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Output targets supported by the OpenAPI generator.
|
|
32
|
+
*
|
|
33
|
+
* @category models
|
|
34
|
+
* @since 4.0.0
|
|
35
|
+
*/
|
|
36
|
+
export type OpenApiGeneratorFormat = "httpclient" | "httpclient-type-only" | "httpapi";
|
|
37
|
+
/**
|
|
38
|
+
* Stable identifiers for non-fatal OpenAPI generation warnings.
|
|
39
|
+
*
|
|
40
|
+
* @category models
|
|
41
|
+
* @since 4.0.0
|
|
42
|
+
*/
|
|
43
|
+
export type OpenApiGeneratorWarningCode = "cookie-parameter-dropped" | "additional-tags-dropped" | "sse-operation-skipped" | "response-headers-ignored" | "optional-request-body-approximated" | "default-response-remapped" | "security-and-downgraded" | "no-body-method-request-body-skipped" | "naming-collision";
|
|
44
|
+
/**
|
|
45
|
+
* Describes a non-fatal issue encountered while mapping an OpenAPI operation to
|
|
46
|
+
* generated Effect source.
|
|
47
|
+
*
|
|
48
|
+
* @category models
|
|
49
|
+
* @since 4.0.0
|
|
50
|
+
*/
|
|
51
|
+
export interface OpenApiGeneratorWarning {
|
|
52
|
+
readonly code: OpenApiGeneratorWarningCode;
|
|
53
|
+
readonly message: string;
|
|
54
|
+
readonly path?: string | undefined;
|
|
55
|
+
readonly method?: OpenAPISpecMethodName | undefined;
|
|
56
|
+
readonly operationId?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options that control one OpenAPI generation run.
|
|
60
|
+
*
|
|
61
|
+
* @category options
|
|
62
|
+
* @since 4.0.0
|
|
63
|
+
*/
|
|
11
64
|
export interface OpenApiGenerateOptions {
|
|
12
65
|
/**
|
|
13
|
-
* The name to give to the generated
|
|
66
|
+
* The name to give to the generated output.
|
|
14
67
|
*/
|
|
15
68
|
readonly name: string;
|
|
16
69
|
/**
|
|
17
|
-
*
|
|
18
|
-
* specification (without corresponding schemas).
|
|
70
|
+
* The output format to generate.
|
|
19
71
|
*/
|
|
20
|
-
readonly
|
|
72
|
+
readonly format: OpenApiGeneratorFormat;
|
|
21
73
|
/**
|
|
22
74
|
* Hook to transform each JSON Schema node before processing.
|
|
23
75
|
*/
|
|
24
76
|
readonly onEnter?: ((js: JsonSchema.JsonSchema) => JsonSchema.JsonSchema) | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Callback to receive non-fatal generation warnings.
|
|
79
|
+
*/
|
|
80
|
+
readonly onWarning?: ((warning: OpenApiGeneratorWarning) => void) | undefined;
|
|
25
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Constructs the OpenAPI generator service implementation.
|
|
84
|
+
*
|
|
85
|
+
* @category constructors
|
|
86
|
+
* @since 4.0.0
|
|
87
|
+
*/
|
|
26
88
|
export declare const make: Effect.Effect<{
|
|
27
89
|
readonly generate: (_: OpenAPISpec, options: OpenApiGenerateOptions) => Effect.Effect<string, never, never>;
|
|
28
90
|
}, never, never>;
|
|
91
|
+
/**
|
|
92
|
+
* Layer providing an OpenAPI generator for Schema-backed HTTP client and HttpApi output.
|
|
93
|
+
*
|
|
94
|
+
* @category layers
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
*/
|
|
29
97
|
export declare const layerTransformerSchema: Layer.Layer<OpenApiGenerator>;
|
|
98
|
+
/**
|
|
99
|
+
* Layer providing an OpenAPI generator for type-only HTTP client output.
|
|
100
|
+
*
|
|
101
|
+
* @category layers
|
|
102
|
+
* @since 4.0.0
|
|
103
|
+
*/
|
|
30
104
|
export declare const layerTransformerTs: Layer.Layer<OpenApiGenerator>;
|
|
31
105
|
export {};
|
|
32
106
|
//# sourceMappingURL=OpenApiGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiGenerator.d.ts","sourceRoot":"","sources":["../src/OpenApiGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"OpenApiGenerator.d.ts","sourceRoot":"","sources":["../src/OpenApiGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,EAAyB,WAAW,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;;uBAiBzF,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,sBAAsB,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;;AATpG;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,qBAGf;CAAG;AAE1B;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,YAAY,GAAG,sBAAsB,GAAG,SAAS,CAAA;AAEtF;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GACnC,0BAA0B,GAC1B,yBAAyB,GACzB,uBAAuB,GACvB,0BAA0B,GAC1B,oCAAoC,GACpC,2BAA2B,GAC3B,yBAAyB,GACzB,qCAAqC,GACrC,kBAAkB,CAAA;AAEtB;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAA;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE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