@goast/kotlin 0.4.21 → 0.4.23
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/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +1 -1
- package/esm/src/generators/services/spring-controllers/models.d.ts +1 -0
- package/esm/src/generators/services/spring-controllers/models.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/models.js +1 -0
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +120 -41
- package/esm/src/generators/services/spring-controllers/spring-controllers-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controllers-generator.js +4 -2
- package/package.json +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +1 -1
- package/script/src/generators/services/spring-controllers/models.d.ts +1 -0
- package/script/src/generators/services/spring-controllers/models.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/models.js +1 -0
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.js +120 -41
- package/script/src/generators/services/spring-controllers/spring-controllers-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controllers-generator.js +4 -2
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +1 -1
- package/src/src/generators/services/spring-controllers/models.ts +6 -1
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +418 -151
- package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +37 -11
|
@@ -17,9 +17,18 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
17
17
|
fs_extra_1.default.ensureDirSync(dirPath);
|
|
18
18
|
console.log(`Generating service ${ctx.service.id} to ${dirPath}...`);
|
|
19
19
|
return {
|
|
20
|
-
apiInterface: this.generateApiInterfaceFile(ctx, {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
apiInterface: this.generateApiInterfaceFile(ctx, {
|
|
21
|
+
dirPath,
|
|
22
|
+
packageName,
|
|
23
|
+
}),
|
|
24
|
+
apiController: this.generateApiControllerFile(ctx, {
|
|
25
|
+
dirPath,
|
|
26
|
+
packageName,
|
|
27
|
+
}),
|
|
28
|
+
apiDelegate: this.generateApiDelegateInterfaceFile(ctx, {
|
|
29
|
+
dirPath,
|
|
30
|
+
packageName,
|
|
31
|
+
}),
|
|
23
32
|
};
|
|
24
33
|
}
|
|
25
34
|
// #region API Interface
|
|
@@ -84,7 +93,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
84
93
|
const { endpoint } = args;
|
|
85
94
|
const parameters = this.getAllParameters(ctx, { endpoint });
|
|
86
95
|
return index_js_1.kt.function((0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing), {
|
|
87
|
-
suspend:
|
|
96
|
+
suspend: ctx.config.suspendingFunctions,
|
|
88
97
|
annotations: this.getApiInterfaceEndpointMethodAnnnotations(ctx, endpoint),
|
|
89
98
|
parameters: parameters.map((parameter) => this.getApiInterfaceEndpointMethodParameter(ctx, endpoint, parameter)),
|
|
90
99
|
returnType: index_js_1.kt.refs.spring.responseEntity(['*']),
|
|
@@ -98,7 +107,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
98
107
|
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.swagger.operation(), [
|
|
99
108
|
endpoint.summary ? index_js_1.kt.argument.named('summary', index_js_1.kt.string((_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())) : null,
|
|
100
109
|
index_js_1.kt.argument.named('operationId', index_js_1.kt.string(endpoint.name)),
|
|
101
|
-
endpoint.description
|
|
110
|
+
endpoint.description
|
|
111
|
+
? index_js_1.kt.argument.named('description', index_js_1.kt.string((_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
112
|
+
: null,
|
|
102
113
|
endpoint.deprecated !== undefined ? index_js_1.kt.argument.named('deprecated', index_js_1.kt.toNode(endpoint.deprecated)) : null,
|
|
103
114
|
]));
|
|
104
115
|
if (endpoint.responses.length > 0) {
|
|
@@ -114,7 +125,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
114
125
|
? [{ schema: undefined, type: undefined }]
|
|
115
126
|
: response.contentOptions).map((content) => {
|
|
116
127
|
var _a;
|
|
117
|
-
let schemaType = (_a = this.getSchemaType(ctx, {
|
|
128
|
+
let schemaType = (_a = this.getSchemaType(ctx, {
|
|
129
|
+
schema: content.schema,
|
|
130
|
+
})) !== null && _a !== void 0 ? _a : index_js_1.kt.refs.any();
|
|
118
131
|
let isArray = false;
|
|
119
132
|
if (index_js_1.kt.refs.list.matches(schemaType)) {
|
|
120
133
|
isArray = true;
|
|
@@ -129,8 +142,12 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
129
142
|
]);
|
|
130
143
|
}
|
|
131
144
|
return index_js_1.kt.call(index_js_1.kt.refs.swagger.content(), [
|
|
132
|
-
content.type
|
|
133
|
-
|
|
145
|
+
content.type
|
|
146
|
+
? index_js_1.kt.argument.named('mediaType', index_js_1.kt.string(content.type))
|
|
147
|
+
: null,
|
|
148
|
+
content.schema
|
|
149
|
+
? index_js_1.kt.argument.named(isArray ? 'array' : 'schema', ktSchema)
|
|
150
|
+
: null,
|
|
134
151
|
]);
|
|
135
152
|
}))),
|
|
136
153
|
]);
|
|
@@ -139,7 +156,12 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
139
156
|
}
|
|
140
157
|
}
|
|
141
158
|
const requestMapping = index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestMapping(), [
|
|
142
|
-
index_js_1.kt.argument.named('method', index_js_1.kt.collectionLiteral([
|
|
159
|
+
index_js_1.kt.argument.named('method', index_js_1.kt.collectionLiteral([
|
|
160
|
+
index_js_1.kt.call([
|
|
161
|
+
index_js_1.kt.refs.spring.requestMethod(),
|
|
162
|
+
endpoint.method.toUpperCase(),
|
|
163
|
+
]),
|
|
164
|
+
])),
|
|
143
165
|
index_js_1.kt.argument.named('value', index_js_1.kt.collectionLiteral([this.getPathConstantName(ctx, { endpoint })])),
|
|
144
166
|
]);
|
|
145
167
|
if (endpoint.requestBody && endpoint.requestBody.content.length > 0) {
|
|
@@ -150,11 +172,17 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
150
172
|
}
|
|
151
173
|
getApiInterfaceEndpointMethodParameter(ctx, endpoint, parameter) {
|
|
152
174
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
153
|
-
const isEnumSchema = ((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.kind) === 'string' &&
|
|
154
|
-
|
|
175
|
+
const isEnumSchema = ((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.kind) === 'string' &&
|
|
176
|
+
((_b = parameter.schema.enum) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
177
|
+
this.getSchemaType(ctx, { schema: parameter.schema }) &&
|
|
178
|
+
!parameter.multipart;
|
|
155
179
|
const actualType = this.getSchemaType(ctx, { schema: parameter.schema });
|
|
156
180
|
const schemaType = isEnumSchema ? index_js_1.kt.refs.string({ nullable: actualType === null || actualType === void 0 ? void 0 : actualType.nullable }) : actualType;
|
|
157
|
-
const result = index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, {
|
|
181
|
+
const result = index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, {
|
|
182
|
+
endpoint,
|
|
183
|
+
parameter,
|
|
184
|
+
type: isEnumSchema ? schemaType : undefined,
|
|
185
|
+
}), {
|
|
158
186
|
default: parameter.multipart && ((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.default) !== undefined
|
|
159
187
|
? index_js_1.kt.toNode((_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default)
|
|
160
188
|
: null,
|
|
@@ -162,7 +190,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
162
190
|
if (ctx.config.addSwaggerAnnotations) {
|
|
163
191
|
const annotation = index_js_1.kt.annotation(index_js_1.kt.refs.swagger.parameter(), [
|
|
164
192
|
parameter.multipart ? index_js_1.kt.argument.named('name', index_js_1.kt.string(parameter.multipart.name)) : null,
|
|
165
|
-
parameter.description
|
|
193
|
+
parameter.description
|
|
194
|
+
? index_js_1.kt.argument.named('description', index_js_1.kt.string((_e = parameter.description) === null || _e === void 0 ? void 0 : _e.trim()))
|
|
195
|
+
: null,
|
|
166
196
|
index_js_1.kt.argument.named('required', parameter.required),
|
|
167
197
|
parameter.target === 'header' ? index_js_1.kt.argument.named('hidden', index_js_1.kt.toNode(true)) : null,
|
|
168
198
|
]);
|
|
@@ -178,7 +208,8 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
178
208
|
}
|
|
179
209
|
result.annotations.push(annotation);
|
|
180
210
|
}
|
|
181
|
-
const isCorePackage = !(schemaType === null || schemaType === void 0 ? void 0 : schemaType.packageName) ||
|
|
211
|
+
const isCorePackage = !(schemaType === null || schemaType === void 0 ? void 0 : schemaType.packageName) ||
|
|
212
|
+
/^(kotlin|java)(\..*|$)/.test(schemaType.packageName);
|
|
182
213
|
if (!isCorePackage && ctx.config.addJakartaValidationAnnotations) {
|
|
183
214
|
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.jakarta.valid()));
|
|
184
215
|
}
|
|
@@ -196,10 +227,14 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
196
227
|
result.annotations.push(annotation);
|
|
197
228
|
}
|
|
198
229
|
if (parameter.target === 'path') {
|
|
199
|
-
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.pathVariable(), [
|
|
230
|
+
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.pathVariable(), [
|
|
231
|
+
index_js_1.kt.string(parameter.name),
|
|
232
|
+
]));
|
|
200
233
|
}
|
|
201
234
|
if (parameter.target === 'header') {
|
|
202
|
-
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestHeader(), [
|
|
235
|
+
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestHeader(), [
|
|
236
|
+
index_js_1.kt.string(parameter.name),
|
|
237
|
+
]));
|
|
203
238
|
}
|
|
204
239
|
if (parameter.multipart) {
|
|
205
240
|
result.annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestPart(), [
|
|
@@ -214,15 +249,20 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
214
249
|
parameters.forEach((x) => {
|
|
215
250
|
var _a, _b;
|
|
216
251
|
const paramName = (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing);
|
|
217
|
-
if (((_a = x.schema) === null || _a === void 0 ? void 0 : _a.kind) === 'string' &&
|
|
252
|
+
if (((_a = x.schema) === null || _a === void 0 ? void 0 : _a.kind) === 'string' &&
|
|
253
|
+
((_b = x.schema.enum) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
254
|
+
!x.multipart) {
|
|
218
255
|
const type = this.getSchemaType(ctx, { schema: x.schema });
|
|
219
256
|
if (type) {
|
|
220
|
-
body.values.push((0, core_1.builderTemplate) `val ${paramName} = ${paramName}${type.nullable || !x.required && !x.schema.default ? '?' : ''}.let { ${type}.fromValue(it) ?: return ${index_js_1.kt.refs.spring.responseEntity.infer()}.status(${index_js_1.kt.refs.spring.httpStatus()}.BAD_REQUEST).body(${index_js_1.kt.string(`Invalid value for parameter ${x.name}`)}) }`);
|
|
257
|
+
body.values.push((0, core_1.builderTemplate) `val ${paramName} = ${paramName}${type.nullable || (!x.required && !x.schema.default) ? '?' : ''}.let { ${type}.fromValue(it) ?: return ${index_js_1.kt.refs.spring.responseEntity.infer()}.status(${index_js_1.kt.refs.spring.httpStatus()}.BAD_REQUEST).body(${index_js_1.kt.string(`Invalid value for parameter ${x.name}`)}) }`);
|
|
221
258
|
}
|
|
222
259
|
}
|
|
223
260
|
});
|
|
224
261
|
body.values.push((0, core_1.builderTemplate) `try {${core_1.builderTemplate.indent `
|
|
225
|
-
return ${index_js_1.kt.call([
|
|
262
|
+
return ${index_js_1.kt.call([
|
|
263
|
+
index_js_1.kt.call(index_js_1.kt.reference('getDelegate'), []),
|
|
264
|
+
(0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing),
|
|
265
|
+
], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`}
|
|
226
266
|
} catch (e: ${index_js_1.kt.refs.throwable()}) {${core_1.builderTemplate.indent `
|
|
227
267
|
return getExceptionHandler()?.handleApiException(e) ?: throw e`}
|
|
228
268
|
}`);
|
|
@@ -237,11 +277,17 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
237
277
|
primaryConstructor: index_js_1.kt.constructor([
|
|
238
278
|
index_js_1.kt.parameter.class('body', index_js_1.kt.reference('T')),
|
|
239
279
|
index_js_1.kt.parameter.class('rawStatus', index_js_1.kt.refs.int()),
|
|
240
|
-
index_js_1.kt.parameter.class('headers', index_js_1.kt.refs.spring.multiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()], {
|
|
280
|
+
index_js_1.kt.parameter.class('headers', index_js_1.kt.refs.spring.multiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()], {
|
|
281
|
+
nullable: true,
|
|
282
|
+
}), { default: index_js_1.kt.toNode(null) }),
|
|
241
283
|
], null, {
|
|
242
284
|
accessModifier: endpoint.responses.length > 0 ? 'private' : null,
|
|
243
285
|
delegateTarget: 'super',
|
|
244
|
-
delegateArguments: [
|
|
286
|
+
delegateArguments: [
|
|
287
|
+
index_js_1.kt.argument('body'),
|
|
288
|
+
index_js_1.kt.argument('headers'),
|
|
289
|
+
index_js_1.kt.argument('rawStatus'),
|
|
290
|
+
],
|
|
245
291
|
}),
|
|
246
292
|
extends: index_js_1.kt.refs.spring.responseEntity([index_js_1.kt.reference('T')]),
|
|
247
293
|
companionObject: index_js_1.kt.object({
|
|
@@ -249,8 +295,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
249
295
|
...ctx.config.defaultStatusCodes,
|
|
250
296
|
501,
|
|
251
297
|
...endpoint.responses.map((x) => x.statusCode),
|
|
252
|
-
].filter(core_1.notNullish)))
|
|
253
|
-
.map((code) => {
|
|
298
|
+
].filter(core_1.notNullish))).map((code) => {
|
|
254
299
|
var _a;
|
|
255
300
|
const fnName = (0, core_1.toCasing)((0, http_status_codes_1.getReasonPhrase)(code), ctx.config.functionNameCasing);
|
|
256
301
|
const response = endpoint.responses.find((x) => x.statusCode === code);
|
|
@@ -265,7 +310,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
265
310
|
singleExpression: true,
|
|
266
311
|
body: index_js_1.kt.call([
|
|
267
312
|
index_js_1.kt.reference(this.getApiResponseEntityName(ctx, { endpoint }), null, {
|
|
268
|
-
generics: [
|
|
313
|
+
generics: [
|
|
314
|
+
hasResponseBody ? responseType : index_js_1.kt.refs.unit({ nullable: true }),
|
|
315
|
+
],
|
|
269
316
|
}),
|
|
270
317
|
], [
|
|
271
318
|
hasResponseBody ? index_js_1.kt.argument('body') : index_js_1.kt.toNode(null),
|
|
@@ -306,11 +353,21 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
306
353
|
return index_js_1.kt.class(controllerName, {
|
|
307
354
|
annotations: this.getApiControllerAnnotations(ctx),
|
|
308
355
|
primaryConstructor: index_js_1.kt.constructor([
|
|
309
|
-
index_js_1.kt.parameter.class('delegate', index_js_1.kt.reference(this.getApiDelegateInterfaceName(ctx, {}), null, {
|
|
310
|
-
|
|
356
|
+
index_js_1.kt.parameter.class('delegate', index_js_1.kt.reference(this.getApiDelegateInterfaceName(ctx, {}), null, {
|
|
357
|
+
nullable: true,
|
|
358
|
+
}), {
|
|
359
|
+
annotations: [
|
|
360
|
+
index_js_1.kt.annotation(index_js_1.kt.refs.spring.autowired(), [
|
|
361
|
+
index_js_1.kt.argument.named('required', 'false'),
|
|
362
|
+
]),
|
|
363
|
+
],
|
|
311
364
|
}),
|
|
312
365
|
index_js_1.kt.parameter.class('exceptionHandler', ctx.refs.apiExceptionHandler({ nullable: true }), {
|
|
313
|
-
annotations: [
|
|
366
|
+
annotations: [
|
|
367
|
+
index_js_1.kt.annotation(index_js_1.kt.refs.spring.autowired(), [
|
|
368
|
+
index_js_1.kt.argument.named('required', 'false'),
|
|
369
|
+
]),
|
|
370
|
+
],
|
|
314
371
|
accessModifier: 'private',
|
|
315
372
|
property: 'readonly',
|
|
316
373
|
}),
|
|
@@ -323,11 +380,15 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
323
380
|
const annotations = [];
|
|
324
381
|
if (ctx.config.addJakartaValidationAnnotations) {
|
|
325
382
|
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.jakarta.generated(), [
|
|
326
|
-
index_js_1.kt.argument.named('value', index_js_1.kt.collectionLiteral([
|
|
383
|
+
index_js_1.kt.argument.named('value', index_js_1.kt.collectionLiteral([
|
|
384
|
+
index_js_1.kt.string('com.goast.kotlin.spring-service-generator'),
|
|
385
|
+
])),
|
|
327
386
|
]));
|
|
328
387
|
}
|
|
329
388
|
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.controller()));
|
|
330
|
-
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestMapping(), [
|
|
389
|
+
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.spring.requestMapping(), [
|
|
390
|
+
this.getControllerRequestMapping(ctx, {}),
|
|
391
|
+
]));
|
|
331
392
|
return annotations;
|
|
332
393
|
}
|
|
333
394
|
getApiControllerMembers(ctx) {
|
|
@@ -359,7 +420,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
359
420
|
const filePath = `${dirPath}/${fileName}`;
|
|
360
421
|
console.log(` Generating API delegate ${typeName} to ${fileName}...`);
|
|
361
422
|
const builder = new file_builder_js_1.KotlinFileBuilder(packageName, ctx.config);
|
|
362
|
-
builder.append(this.getApiDelegateInterfaceFileContent(ctx, {
|
|
423
|
+
builder.append(this.getApiDelegateInterfaceFileContent(ctx, {
|
|
424
|
+
delegateInterfaceName: typeName,
|
|
425
|
+
}));
|
|
363
426
|
fs_extra_1.default.writeFileSync(filePath, builder.toString());
|
|
364
427
|
return { typeName, packageName };
|
|
365
428
|
}
|
|
@@ -378,7 +441,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
378
441
|
const annotations = [];
|
|
379
442
|
if (ctx.config.addJakartaValidationAnnotations) {
|
|
380
443
|
annotations.push(index_js_1.kt.annotation(index_js_1.kt.refs.jakarta.generated(), [
|
|
381
|
-
index_js_1.kt.argument.named('value', index_js_1.kt.collectionLiteral([
|
|
444
|
+
index_js_1.kt.argument.named('value', index_js_1.kt.collectionLiteral([
|
|
445
|
+
index_js_1.kt.string('com.goast.kotlin.spring-service-generator'),
|
|
446
|
+
])),
|
|
382
447
|
]));
|
|
383
448
|
}
|
|
384
449
|
return annotations;
|
|
@@ -399,7 +464,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
399
464
|
const { endpoint } = args;
|
|
400
465
|
const parameters = this.getAllParameters(ctx, { endpoint });
|
|
401
466
|
const fn = index_js_1.kt.function((0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing), {
|
|
402
|
-
suspend:
|
|
467
|
+
suspend: ctx.config.suspendingFunctions,
|
|
403
468
|
parameters: parameters.map((parameter) => {
|
|
404
469
|
return index_js_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }));
|
|
405
470
|
}),
|
|
@@ -407,14 +472,20 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
407
472
|
if (ctx.config.strictResponseEntities) {
|
|
408
473
|
const responseEntity = index_js_1.kt.reference.genericFactory(this.getApiResponseEntityName(ctx, { endpoint }), `${this.getPackageName(ctx, {})}.${this.getApiInterfaceName(ctx, {})}`);
|
|
409
474
|
fn.returnType = responseEntity(['*']);
|
|
410
|
-
fn.body = (0, core_1.appendValueGroup)([
|
|
475
|
+
fn.body = (0, core_1.appendValueGroup)([
|
|
476
|
+
(0, core_1.builderTemplate) `return ${index_js_1.kt.call([
|
|
411
477
|
responseEntity.infer(),
|
|
412
478
|
(0, core_1.toCasing)((0, http_status_codes_1.getReasonPhrase)(501), ctx.config.functionNameCasing),
|
|
413
|
-
], [])}
|
|
479
|
+
], [])}`,
|
|
480
|
+
], '\n');
|
|
414
481
|
}
|
|
415
482
|
else {
|
|
416
|
-
fn.returnType = index_js_1.kt.refs.spring.responseEntity([
|
|
417
|
-
|
|
483
|
+
fn.returnType = index_js_1.kt.refs.spring.responseEntity([
|
|
484
|
+
this.getResponseType(ctx, { endpoint }),
|
|
485
|
+
]);
|
|
486
|
+
fn.body = (0, core_1.appendValueGroup)([
|
|
487
|
+
(0, core_1.builderTemplate) `return ${index_js_1.kt.refs.spring.responseEntity.infer()}(${index_js_1.kt.refs.spring.httpStatus()}.NOT_IMPLEMENTED)`,
|
|
488
|
+
], '\n');
|
|
418
489
|
}
|
|
419
490
|
return fn;
|
|
420
491
|
}
|
|
@@ -427,7 +498,8 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
427
498
|
}
|
|
428
499
|
const type = this.getTypeUsage(ctx, {
|
|
429
500
|
schema: parameter.schema,
|
|
430
|
-
nullable: (!parameter.required && ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.default) === undefined) ||
|
|
501
|
+
nullable: (!parameter.required && ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.default) === undefined) ||
|
|
502
|
+
undefined,
|
|
431
503
|
type: args.type,
|
|
432
504
|
});
|
|
433
505
|
return parameter.target === 'body' ? adjustListType(ctx, type) : type;
|
|
@@ -440,10 +512,14 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
440
512
|
.filter((x, i, a) => a.findIndex((y) => {
|
|
441
513
|
const xType = this.getSchemaType(ctx, { schema: x });
|
|
442
514
|
const yType = this.getSchemaType(ctx, { schema: y });
|
|
443
|
-
return (xType === null || xType === void 0 ? void 0 : xType.name) === (yType === null || yType === void 0 ? void 0 : yType.name) &&
|
|
515
|
+
return ((xType === null || xType === void 0 ? void 0 : xType.name) === (yType === null || yType === void 0 ? void 0 : yType.name) &&
|
|
516
|
+
(xType === null || xType === void 0 ? void 0 : xType.packageName) === (yType === null || yType === void 0 ? void 0 : yType.packageName));
|
|
444
517
|
}) === i);
|
|
445
518
|
if (responseSchemas.length === 1) {
|
|
446
|
-
return adjustListType(ctx, this.getTypeUsage(ctx, {
|
|
519
|
+
return adjustListType(ctx, this.getTypeUsage(ctx, {
|
|
520
|
+
schema: responseSchemas[0],
|
|
521
|
+
fallback: index_js_1.kt.refs.unit(),
|
|
522
|
+
}));
|
|
447
523
|
}
|
|
448
524
|
else if (responseSchemas.length === 0) {
|
|
449
525
|
return index_js_1.kt.refs.unit();
|
|
@@ -508,7 +584,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
508
584
|
getAllParameters(ctx, args) {
|
|
509
585
|
var _a, _b;
|
|
510
586
|
const { endpoint } = args;
|
|
511
|
-
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' ||
|
|
587
|
+
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' ||
|
|
588
|
+
parameter.target === 'path' ||
|
|
589
|
+
parameter.target === 'header');
|
|
512
590
|
if (endpoint.requestBody) {
|
|
513
591
|
const content = endpoint.requestBody.content[0];
|
|
514
592
|
let schema = content.schema;
|
|
@@ -527,7 +605,8 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
|
|
|
527
605
|
}), {
|
|
528
606
|
multipart: {
|
|
529
607
|
name,
|
|
530
|
-
isFile: property.schema.kind === 'string' &&
|
|
608
|
+
isFile: property.schema.kind === 'string' &&
|
|
609
|
+
property.schema.format === 'binary',
|
|
531
610
|
},
|
|
532
611
|
}));
|
|
533
612
|
}
|
package/script/src/generators/services/spring-controllers/spring-controllers-generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-controllers-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-controllers/spring-controllers-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,gBAAgB,EAErB,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,qCAAqC,EACtC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AAErB,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,kCAAkC,CAAC;AAE1C,KAAK,KAAK,GAAG,4BAA4B,CAAC;AAC1C,KAAK,MAAM,GAAG,6BAA6B,CAAC;AAC5C,KAAK,MAAM,GAAG,6BAA6B,CAAC;AAC5C,KAAK,aAAa,GAAG,4BAA4B,CAAC;AAClD,KAAK,OAAO,GAAG,8BAA8B,CAAC;AAE9C,qBAAa,gCAAiC,SAAQ,qCAAqC,CACzF,KAAK,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,OAAO,CACR;IACC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,
|
|
1
|
+
{"version":3,"file":"spring-controllers-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/spring-controllers/spring-controllers-generator.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,gBAAgB,EAErB,OAAO,EACP,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,qCAAqC,EACtC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AAErB,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,kCAAkC,CAAC;AAE1C,KAAK,KAAK,GAAG,4BAA4B,CAAC;AAC1C,KAAK,MAAM,GAAG,6BAA6B,CAAC;AAC5C,KAAK,MAAM,GAAG,6BAA6B,CAAC;AAC5C,KAAK,aAAa,GAAG,4BAA4B,CAAC;AAClD,KAAK,OAAO,GAAG,8BAA8B,CAAC;AAE9C,qBAAa,gCAAiC,SAAQ,qCAAqC,CACzF,KAAK,EACL,MAAM,EACN,MAAM,EACN,aAAa,EACb,OAAO,CACR;IACC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAGvC;gBAGA,uBAAuB,CAAC,EAAE,OAAO,CAAC,+BAA+B,EAAE,EAAE,CAAC;IAOxE,SAAS,CAAC,UAAU,IAAI,MAAM;IAQ9B,SAAS,CAAC,eAAe,CACvB,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,UAAU,GAClB,YAAY,CAAC,aAAa,CAAC;IAQ9B,SAAS,CAAC,gBAAgB,CACxB,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,GACpB,IAAI;IAIP,SAAS,CAAC,YAAY,CACpB,OAAO,EAAE,uBAAuB,CAAC,4BAA4B,CAAC,EAC9D,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,SAAS,GACnC,OAAO;cAcS,uBAAuB,CACxC,GAAG,EAAE,8BAA8B,GAClC,IAAI;IAIP,SAAS,CAAC,2BAA2B,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI;IAYzD,SAAS,CAAC,iCAAiC,CACzC,GAAG,EAAE,OAAO,GACX,gBAAgB,CAAC,iBAAiB,CAAC;IAItC,SAAS,CAAC,+BAA+B,CACvC,GAAG,EAAE,OAAO,GACX,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC;CAkBnC"}
|
|
@@ -65,8 +65,10 @@ class KotlinSpringControllersGenerator extends core_1.OpenApiServicesGenerationP
|
|
|
65
65
|
return index_js_1.kt.interface(ctx.refs.apiExceptionHandler.refName, {
|
|
66
66
|
members: [
|
|
67
67
|
index_js_1.kt.function('handleApiException', {
|
|
68
|
-
doc: index_js_1.kt.doc('Handler for API exceptions.', [
|
|
69
|
-
|
|
68
|
+
doc: index_js_1.kt.doc('Handler for API exceptions.', [
|
|
69
|
+
index_js_1.kt.docTag('return', 'Response entity.'),
|
|
70
|
+
]),
|
|
71
|
+
suspend: ctx.config.suspendingFunctions,
|
|
70
72
|
parameters: [
|
|
71
73
|
index_js_1.kt.parameter('exception', index_js_1.kt.refs.throwable(), {
|
|
72
74
|
description: 'Exception that has been thrown by the API.',
|
|
@@ -349,7 +349,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context,
|
|
|
349
349
|
queryParameters.map((param) => {
|
|
350
350
|
const paramName = toCasing(param.name, ctx.config.parameterNameCasing);
|
|
351
351
|
const toString = this.getParameterToString(ctx, { endpoint, parameter: param });
|
|
352
|
-
const put = s<Builder>`put(${kt.string(
|
|
352
|
+
const put = s<Builder>`put(${kt.string(param.name)}, listOf(${paramName}${toString}))`;
|
|
353
353
|
return param.required ? put : s<Builder>`if (${paramName} != null) {${s.indent`
|
|
354
354
|
${put}`}
|
|
355
355
|
}`;
|
|
@@ -14,12 +14,16 @@ export type KotlinServicesGeneratorConfig = KotlinGeneratorConfig & {
|
|
|
14
14
|
packageName: string;
|
|
15
15
|
packageSuffix: string | ((service: ApiService | null) => string);
|
|
16
16
|
|
|
17
|
-
basePath?:
|
|
17
|
+
basePath?:
|
|
18
|
+
| string
|
|
19
|
+
| RegExp
|
|
20
|
+
| ((basePath: string, service: ApiService) => string);
|
|
18
21
|
pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
|
|
19
22
|
|
|
20
23
|
addSwaggerAnnotations: boolean;
|
|
21
24
|
addJakartaValidationAnnotations: boolean;
|
|
22
25
|
arrayType: 'list' | 'flux';
|
|
26
|
+
suspendingFunctions: boolean;
|
|
23
27
|
|
|
24
28
|
strictResponseEntities: boolean;
|
|
25
29
|
defaultStatusCodes: number[];
|
|
@@ -34,6 +38,7 @@ export const defaultKotlinServicesGeneratorConfig: DefaultGenerationProviderConf
|
|
|
34
38
|
addSwaggerAnnotations: true,
|
|
35
39
|
addJakartaValidationAnnotations: true,
|
|
36
40
|
arrayType: 'flux',
|
|
41
|
+
suspendingFunctions: true,
|
|
37
42
|
|
|
38
43
|
strictResponseEntities: false,
|
|
39
44
|
defaultStatusCodes: [400, 401, 403, 500, 501],
|