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