@kubb/plugin-oas 3.16.1 → 3.16.3
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/Oas-CuqAnIw-.js +60 -0
- package/dist/Oas-CuqAnIw-.js.map +1 -0
- package/dist/Oas-Cv_pyXRM.cjs +78 -0
- package/dist/Oas-Cv_pyXRM.cjs.map +1 -0
- package/dist/OperationGenerator-CgbXErhW.d.cts +900 -0
- package/dist/OperationGenerator-OtLcGk2y.d.ts +900 -0
- package/dist/Schema-DJshqHto.d.cts +38 -0
- package/dist/Schema-DOXGUW1m.d.ts +38 -0
- package/dist/SchemaGenerator-8205BXCp.cjs +942 -0
- package/dist/SchemaGenerator-8205BXCp.cjs.map +1 -0
- package/dist/SchemaGenerator-B8Io6kky.js +930 -0
- package/dist/SchemaGenerator-B8Io6kky.js.map +1 -0
- package/dist/SchemaMapper-BaZQKrQB.js +54 -0
- package/dist/SchemaMapper-BaZQKrQB.js.map +1 -0
- package/dist/SchemaMapper-BiagBQN4.d.cts +388 -0
- package/dist/SchemaMapper-C2J2d3o4.d.ts +388 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs +66 -0
- package/dist/SchemaMapper-D8J0V9Pj.cjs.map +1 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/components.cjs +4 -19
- package/dist/components.d.cts +42 -35
- package/dist/components.d.ts +42 -35
- package/dist/components.js +3 -3
- package/dist/generators-BhLMlRNk.js +137 -0
- package/dist/generators-BhLMlRNk.js.map +1 -0
- package/dist/generators-DLH2kvlh.cjs +155 -0
- package/dist/generators-DLH2kvlh.cjs.map +1 -0
- package/dist/generators.cjs +4 -13
- package/dist/generators.d.cts +5 -7
- package/dist/generators.d.ts +5 -7
- package/dist/generators.js +5 -5
- package/dist/getFooter-BChY2kC1.cjs +43 -0
- package/dist/getFooter-BChY2kC1.cjs.map +1 -0
- package/dist/getFooter-T7_pZ6f8.js +31 -0
- package/dist/getFooter-T7_pZ6f8.js.map +1 -0
- package/dist/getSchemas-D8mP129c.cjs +67 -0
- package/dist/getSchemas-D8mP129c.cjs.map +1 -0
- package/dist/getSchemas-WoSBIxG8.js +55 -0
- package/dist/getSchemas-WoSBIxG8.js.map +1 -0
- package/dist/hooks.cjs +213 -195
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +91 -86
- package/dist/hooks.d.ts +91 -86
- package/dist/hooks.js +212 -193
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +280 -344
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -10
- package/dist/index.d.ts +7 -10
- package/dist/index.js +274 -318
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +802 -737
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +12 -11
- package/dist/mocks.d.ts +12 -11
- package/dist/mocks.js +802 -735
- package/dist/mocks.js.map +1 -1
- package/dist/parseFromConfig-CMNGsef2.cjs +33 -0
- package/dist/parseFromConfig-CMNGsef2.cjs.map +1 -0
- package/dist/parseFromConfig-yAiFK03V.js +27 -0
- package/dist/parseFromConfig-yAiFK03V.js.map +1 -0
- package/dist/utils.cjs +58 -74
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +96 -42
- package/dist/utils.d.ts +96 -42
- package/dist/utils.js +47 -46
- package/dist/utils.js.map +1 -1
- package/package.json +28 -36
- package/src/SchemaGenerator.ts +6 -1
- package/src/components/Operation.tsx +1 -2
- package/src/mocks/schemas.ts +39 -0
- package/src/utils/getBanner.ts +5 -5
- package/src/utils/getFooter.ts +4 -4
- package/dist/OperationGenerator-C7NPZtOM.d.ts +0 -288
- package/dist/OperationGenerator-DJE2XQ83.d.cts +0 -288
- package/dist/Schema-AjebpeVY.d.ts +0 -32
- package/dist/Schema-M6983FL1.d.cts +0 -32
- package/dist/SchemaMapper-B21ZmWag.d.cts +0 -275
- package/dist/SchemaMapper-B21ZmWag.d.ts +0 -275
- package/dist/chunk-6S7YFY6F.js +0 -33
- package/dist/chunk-6S7YFY6F.js.map +0 -1
- package/dist/chunk-76E35IZ2.js +0 -56
- package/dist/chunk-76E35IZ2.js.map +0 -1
- package/dist/chunk-7RFNM43R.cjs +0 -41
- package/dist/chunk-7RFNM43R.cjs.map +0 -1
- package/dist/chunk-DTD4ZUDA.cjs +0 -36
- package/dist/chunk-DTD4ZUDA.cjs.map +0 -1
- package/dist/chunk-G3FDK7YW.js +0 -35
- package/dist/chunk-G3FDK7YW.js.map +0 -1
- package/dist/chunk-JNN4JPWK.js +0 -28
- package/dist/chunk-JNN4JPWK.js.map +0 -1
- package/dist/chunk-MBX66JAT.js +0 -93
- package/dist/chunk-MBX66JAT.js.map +0 -1
- package/dist/chunk-NFLZLRQS.cjs +0 -869
- package/dist/chunk-NFLZLRQS.cjs.map +0 -1
- package/dist/chunk-P2VXWGXZ.js +0 -862
- package/dist/chunk-P2VXWGXZ.js.map +0 -1
- package/dist/chunk-PORSNYI5.js +0 -47
- package/dist/chunk-PORSNYI5.js.map +0 -1
- package/dist/chunk-QJMOOF2A.cjs +0 -97
- package/dist/chunk-QJMOOF2A.cjs.map +0 -1
- package/dist/chunk-YWMMI3MO.cjs +0 -59
- package/dist/chunk-YWMMI3MO.cjs.map +0 -1
- package/dist/chunk-Z2NREI4X.cjs +0 -32
- package/dist/chunk-Z2NREI4X.cjs.map +0 -1
- package/dist/chunk-ZVFL3NXX.cjs +0 -50
- package/dist/chunk-ZVFL3NXX.cjs.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,324 +1,280 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import transformers, { camelCase } from '@kubb/core/transformers';
|
|
12
|
-
import pLimit from 'p-limit';
|
|
13
|
-
import path from 'path';
|
|
1
|
+
import { SchemaGenerator, pLimit } from "./SchemaGenerator-B8Io6kky.js";
|
|
2
|
+
import "./Oas-CuqAnIw-.js";
|
|
3
|
+
import { createGenerator, createReactGenerator, jsonGenerator } from "./generators-BhLMlRNk.js";
|
|
4
|
+
import "./getFooter-T7_pZ6f8.js";
|
|
5
|
+
import { isKeyword, schemaKeywords } from "./SchemaMapper-BaZQKrQB.js";
|
|
6
|
+
import "./getSchemas-WoSBIxG8.js";
|
|
7
|
+
import { parseFromConfig } from "./parseFromConfig-yAiFK03V.js";
|
|
8
|
+
import { BaseGenerator, FileManager, createPlugin } from "@kubb/core";
|
|
9
|
+
import transformers, { camelCase } from "@kubb/core/transformers";
|
|
10
|
+
import path from "node:path";
|
|
14
11
|
|
|
12
|
+
//#region src/OperationGenerator.ts
|
|
15
13
|
var OperationGenerator = class extends BaseGenerator {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const options = this.#getOptions(operation, method);
|
|
176
|
-
const result = await generator.operation?.({
|
|
177
|
-
instance: this,
|
|
178
|
-
operation,
|
|
179
|
-
options: { ...this.options, ...options }
|
|
180
|
-
});
|
|
181
|
-
return result ?? [];
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
const operationResults = await Promise.all(operationTasks);
|
|
185
|
-
const opResultsFlat = operationResults.flat();
|
|
186
|
-
const operationsResult = await generator.operations?.({
|
|
187
|
-
instance: this,
|
|
188
|
-
operations: operations.map((op) => op.operation),
|
|
189
|
-
options: this.options
|
|
190
|
-
});
|
|
191
|
-
return [...opResultsFlat, ...operationsResult ?? []];
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
const nestedResults = await Promise.all(writeTasks);
|
|
195
|
-
return nestedResults.flat();
|
|
196
|
-
}
|
|
14
|
+
#getOptions(operation, method) {
|
|
15
|
+
const { override = [] } = this.context;
|
|
16
|
+
const operationId = operation.getOperationId({ friendlyCase: true });
|
|
17
|
+
const contentType = operation.getContentType();
|
|
18
|
+
return override.find(({ pattern, type }) => {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "tag": return operation.getTags().some((tag) => tag.name.match(pattern));
|
|
21
|
+
case "operationId": return !!operationId.match(pattern);
|
|
22
|
+
case "path": return !!operation.path.match(pattern);
|
|
23
|
+
case "method": return !!method.match(pattern);
|
|
24
|
+
case "contentType": return !!contentType.match(pattern);
|
|
25
|
+
default: return false;
|
|
26
|
+
}
|
|
27
|
+
})?.options || {};
|
|
28
|
+
}
|
|
29
|
+
#isExcluded(operation, method) {
|
|
30
|
+
const { exclude = [] } = this.context;
|
|
31
|
+
const operationId = operation.getOperationId({ friendlyCase: true });
|
|
32
|
+
const contentType = operation.getContentType();
|
|
33
|
+
return exclude.some(({ pattern, type }) => {
|
|
34
|
+
switch (type) {
|
|
35
|
+
case "tag": return operation.getTags().some((tag) => tag.name.match(pattern));
|
|
36
|
+
case "operationId": return !!operationId.match(pattern);
|
|
37
|
+
case "path": return !!operation.path.match(pattern);
|
|
38
|
+
case "method": return !!method.match(pattern);
|
|
39
|
+
case "contentType": return !!contentType.match(pattern);
|
|
40
|
+
default: return false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
#isIncluded(operation, method) {
|
|
45
|
+
const { include = [] } = this.context;
|
|
46
|
+
const operationId = operation.getOperationId({ friendlyCase: true });
|
|
47
|
+
const contentType = operation.getContentType();
|
|
48
|
+
return include.some(({ pattern, type }) => {
|
|
49
|
+
switch (type) {
|
|
50
|
+
case "tag": return operation.getTags().some((tag) => tag.name.match(pattern));
|
|
51
|
+
case "operationId": return !!operationId.match(pattern);
|
|
52
|
+
case "path": return !!operation.path.match(pattern);
|
|
53
|
+
case "method": return !!method.match(pattern);
|
|
54
|
+
case "contentType": return !!contentType.match(pattern);
|
|
55
|
+
default: return false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getSchemas(operation, { resolveName = (name) => name } = {}) {
|
|
60
|
+
const operationId = operation.getOperationId({ friendlyCase: true });
|
|
61
|
+
const method = operation.method;
|
|
62
|
+
const operationName = transformers.pascalCase(operationId);
|
|
63
|
+
const resolveKeys = (schema) => schema?.properties ? Object.keys(schema.properties) : void 0;
|
|
64
|
+
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
65
|
+
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
66
|
+
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
67
|
+
const requestSchema = this.context.oas.getRequestSchema(operation);
|
|
68
|
+
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
69
|
+
const name = statusCode === "default" ? "error" : statusCode;
|
|
70
|
+
const schema = this.context.oas.getResponseSchema(operation, statusCode);
|
|
71
|
+
const keys = resolveKeys(schema);
|
|
72
|
+
return {
|
|
73
|
+
name: resolveName(transformers.pascalCase(`${operationId} ${name}`)),
|
|
74
|
+
description: operation.getResponseByStatusCode(statusCode)?.description,
|
|
75
|
+
schema,
|
|
76
|
+
operation,
|
|
77
|
+
operationName,
|
|
78
|
+
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
79
|
+
keys,
|
|
80
|
+
keysToOmit: keys?.filter((key) => (schema?.properties?.[key])?.writeOnly)
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const successful = statusCodes.filter((item) => item.statusCode?.toString().startsWith("2"));
|
|
84
|
+
const errors = statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5"));
|
|
85
|
+
return {
|
|
86
|
+
pathParams: pathParamsSchema ? {
|
|
87
|
+
name: resolveName(transformers.pascalCase(`${operationId} PathParams`)),
|
|
88
|
+
operation,
|
|
89
|
+
operationName,
|
|
90
|
+
schema: pathParamsSchema,
|
|
91
|
+
keys: resolveKeys(pathParamsSchema)
|
|
92
|
+
} : void 0,
|
|
93
|
+
queryParams: queryParamsSchema ? {
|
|
94
|
+
name: resolveName(transformers.pascalCase(`${operationId} QueryParams`)),
|
|
95
|
+
operation,
|
|
96
|
+
operationName,
|
|
97
|
+
schema: queryParamsSchema,
|
|
98
|
+
keys: resolveKeys(queryParamsSchema) || []
|
|
99
|
+
} : void 0,
|
|
100
|
+
headerParams: headerParamsSchema ? {
|
|
101
|
+
name: resolveName(transformers.pascalCase(`${operationId} HeaderParams`)),
|
|
102
|
+
operation,
|
|
103
|
+
operationName,
|
|
104
|
+
schema: headerParamsSchema,
|
|
105
|
+
keys: resolveKeys(headerParamsSchema)
|
|
106
|
+
} : void 0,
|
|
107
|
+
request: requestSchema ? {
|
|
108
|
+
name: resolveName(transformers.pascalCase(`${operationId} ${method === "get" ? "queryRequest" : "mutationRequest"}`)),
|
|
109
|
+
description: operation.schema.requestBody?.description,
|
|
110
|
+
operation,
|
|
111
|
+
operationName,
|
|
112
|
+
schema: requestSchema,
|
|
113
|
+
keys: resolveKeys(requestSchema),
|
|
114
|
+
keysToOmit: resolveKeys(requestSchema)?.filter((key) => (requestSchema.properties?.[key])?.readOnly)
|
|
115
|
+
} : void 0,
|
|
116
|
+
response: {
|
|
117
|
+
name: resolveName(transformers.pascalCase(`${operationId} ${method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
118
|
+
operation,
|
|
119
|
+
operationName,
|
|
120
|
+
schema: { oneOf: successful.map((item) => ({
|
|
121
|
+
...item.schema,
|
|
122
|
+
$ref: item.name
|
|
123
|
+
})) || void 0 }
|
|
124
|
+
},
|
|
125
|
+
responses: successful,
|
|
126
|
+
errors,
|
|
127
|
+
statusCodes
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async getOperations() {
|
|
131
|
+
const { oas } = this.context;
|
|
132
|
+
const paths = oas.getPaths();
|
|
133
|
+
return Object.entries(paths).flatMap(([path$1, methods]) => Object.entries(methods).map((values) => {
|
|
134
|
+
const [method, operation] = values;
|
|
135
|
+
if (this.#isExcluded(operation, method)) return null;
|
|
136
|
+
if (this.context.include && !this.#isIncluded(operation, method)) return null;
|
|
137
|
+
return operation ? {
|
|
138
|
+
path: path$1,
|
|
139
|
+
method,
|
|
140
|
+
operation
|
|
141
|
+
} : null;
|
|
142
|
+
}).filter(Boolean));
|
|
143
|
+
}
|
|
144
|
+
async build(...generators) {
|
|
145
|
+
const operations = await this.getOperations();
|
|
146
|
+
const generatorLimit = pLimit(1);
|
|
147
|
+
const operationLimit = pLimit(10);
|
|
148
|
+
const writeTasks = generators.map((generator) => generatorLimit(async () => {
|
|
149
|
+
const operationTasks = operations.map(({ operation, method }) => operationLimit(async () => {
|
|
150
|
+
const options = this.#getOptions(operation, method);
|
|
151
|
+
const result = await generator.operation?.({
|
|
152
|
+
instance: this,
|
|
153
|
+
operation,
|
|
154
|
+
options: {
|
|
155
|
+
...this.options,
|
|
156
|
+
...options
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return result ?? [];
|
|
160
|
+
}));
|
|
161
|
+
const operationResults = await Promise.all(operationTasks);
|
|
162
|
+
const opResultsFlat = operationResults.flat();
|
|
163
|
+
const operationsResult = await generator.operations?.({
|
|
164
|
+
instance: this,
|
|
165
|
+
operations: operations.map((op) => op.operation),
|
|
166
|
+
options: this.options
|
|
167
|
+
});
|
|
168
|
+
return [...opResultsFlat, ...operationsResult ?? []];
|
|
169
|
+
}));
|
|
170
|
+
const nestedResults = await Promise.all(writeTasks);
|
|
171
|
+
return nestedResults.flat();
|
|
172
|
+
}
|
|
197
173
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
mode: "split",
|
|
301
|
-
output: output.path
|
|
302
|
-
}
|
|
303
|
-
);
|
|
304
|
-
const schemaFiles = await schemaGenerator.build(...generators);
|
|
305
|
-
await this.addFile(...schemaFiles);
|
|
306
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
307
|
-
oas: oas2,
|
|
308
|
-
pluginManager: this.pluginManager,
|
|
309
|
-
plugin: this.plugin,
|
|
310
|
-
contentType,
|
|
311
|
-
exclude: void 0,
|
|
312
|
-
include: void 0,
|
|
313
|
-
override: void 0,
|
|
314
|
-
mode: "split"
|
|
315
|
-
});
|
|
316
|
-
const operationFiles = await operationGenerator.build(...generators);
|
|
317
|
-
await this.addFile(...operationFiles);
|
|
318
|
-
}
|
|
319
|
-
};
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/plugin.ts
|
|
177
|
+
const pluginOasName = "plugin-oas";
|
|
178
|
+
const pluginOas = createPlugin((options) => {
|
|
179
|
+
const { output = { path: "schemas" }, group, validate = true, generators = [jsonGenerator], serverIndex, contentType, oasClass, discriminator = "strict" } = options;
|
|
180
|
+
let oas;
|
|
181
|
+
const getOas = async ({ config, logger }) => {
|
|
182
|
+
oas = await parseFromConfig(config, oasClass);
|
|
183
|
+
oas.setOptions({
|
|
184
|
+
contentType,
|
|
185
|
+
discriminator
|
|
186
|
+
});
|
|
187
|
+
try {
|
|
188
|
+
if (validate) await oas.valdiate();
|
|
189
|
+
} catch (e) {
|
|
190
|
+
const error = e;
|
|
191
|
+
logger.emit("warning", error?.message);
|
|
192
|
+
}
|
|
193
|
+
return oas;
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
name: pluginOasName,
|
|
197
|
+
options: {
|
|
198
|
+
output,
|
|
199
|
+
validate,
|
|
200
|
+
discriminator,
|
|
201
|
+
...options
|
|
202
|
+
},
|
|
203
|
+
context() {
|
|
204
|
+
const { config, logger } = this;
|
|
205
|
+
return {
|
|
206
|
+
getOas() {
|
|
207
|
+
return getOas({
|
|
208
|
+
config,
|
|
209
|
+
logger
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
async getBaseURL() {
|
|
213
|
+
const oasInstance = await this.getOas();
|
|
214
|
+
if (serverIndex) return oasInstance.api.servers?.at(serverIndex)?.url;
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
resolvePath(baseName, pathMode, options$1) {
|
|
220
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
221
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
222
|
+
if (mode === "single")
|
|
223
|
+
/**
|
|
224
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
225
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
226
|
+
*/
|
|
227
|
+
return path.resolve(root, output.path);
|
|
228
|
+
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
229
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
230
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
231
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
232
|
+
};
|
|
233
|
+
return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
234
|
+
}
|
|
235
|
+
return path.resolve(root, output.path, baseName);
|
|
236
|
+
},
|
|
237
|
+
async buildStart() {
|
|
238
|
+
if (!output) return;
|
|
239
|
+
const oas$1 = await getOas({
|
|
240
|
+
config: this.config,
|
|
241
|
+
logger: this.logger
|
|
242
|
+
});
|
|
243
|
+
await oas$1.dereference();
|
|
244
|
+
const schemaGenerator = new SchemaGenerator({
|
|
245
|
+
unknownType: "unknown",
|
|
246
|
+
emptySchemaType: "unknown",
|
|
247
|
+
dateType: "date",
|
|
248
|
+
transformers: {},
|
|
249
|
+
...this.plugin.options
|
|
250
|
+
}, {
|
|
251
|
+
oas: oas$1,
|
|
252
|
+
pluginManager: this.pluginManager,
|
|
253
|
+
plugin: this.plugin,
|
|
254
|
+
contentType,
|
|
255
|
+
include: void 0,
|
|
256
|
+
override: void 0,
|
|
257
|
+
mode: "split",
|
|
258
|
+
output: output.path
|
|
259
|
+
});
|
|
260
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
261
|
+
await this.addFile(...schemaFiles);
|
|
262
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
263
|
+
oas: oas$1,
|
|
264
|
+
pluginManager: this.pluginManager,
|
|
265
|
+
plugin: this.plugin,
|
|
266
|
+
contentType,
|
|
267
|
+
exclude: void 0,
|
|
268
|
+
include: void 0,
|
|
269
|
+
override: void 0,
|
|
270
|
+
mode: "split"
|
|
271
|
+
});
|
|
272
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
273
|
+
await this.addFile(...operationFiles);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
320
276
|
});
|
|
321
277
|
|
|
322
|
-
|
|
323
|
-
|
|
278
|
+
//#endregion
|
|
279
|
+
export { OperationGenerator, SchemaGenerator, createGenerator, createReactGenerator, isKeyword, pluginOas, pluginOasName, schemaKeywords };
|
|
324
280
|
//# sourceMappingURL=index.js.map
|