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