@goast/kotlin 0.3.3 → 0.3.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/cjs/index.js +3 -2
- package/cjs/lib/ast/references/java.js +5 -4
- package/cjs/lib/ast/references/reactor.js +2 -1
- package/cjs/lib/ast/references/spring.js +15 -12
- package/cjs/lib/generators/models/model-generator.js +4 -0
- package/cjs/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +94 -33
- package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +67 -24
- package/cjs/lib/types.js +2 -0
- package/esm/index.js +3 -2
- package/esm/lib/ast/references/java.js +4 -3
- package/esm/lib/ast/references/reactor.js +1 -0
- package/esm/lib/ast/references/spring.js +14 -11
- package/esm/lib/generators/models/model-generator.js +4 -0
- package/esm/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +95 -34
- package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +68 -25
- package/esm/lib/types.js +1 -0
- package/package.json +1 -1
- package/types/index.d.ts +3 -2
- package/types/lib/ast/references/java.d.ts +16 -3
- package/types/lib/ast/references/reactor.d.ts +16 -0
- package/types/lib/ast/references/spring.d.ts +44 -18
- package/types/lib/generators/services/okhttp3-clients/args.d.ts +9 -0
- package/types/lib/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +6 -2
- package/types/lib/generators/services/spring-controllers/args.d.ts +3 -2
- package/types/lib/generators/services/spring-controllers/spring-controller-generator.d.ts +4 -2
- package/types/lib/types.d.ts +7 -0
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/ast"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./lib/common-results"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/config"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./lib/generators"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./lib/file-builder"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/generators"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./lib/import-collection"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/types"), exports);
|
|
9
11
|
tslib_1.__exportStar(require("./lib/utils"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./lib/ast"), exports);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.optional = exports.offsetDateTime = exports.
|
|
3
|
+
exports.optional = exports.offsetDateTime = exports.unsupportedOperationException = exports.system = exports.illegalStateException = exports.ioException = exports.file = void 0;
|
|
4
4
|
const reference_1 = require("../nodes/reference");
|
|
5
|
+
// java.io
|
|
6
|
+
exports.file = reference_1.ktReference.factory('File', 'java.io');
|
|
7
|
+
exports.ioException = reference_1.ktReference.factory('IOException', 'java.io');
|
|
5
8
|
// java.lang
|
|
6
|
-
exports.system = reference_1.ktReference.factory('System', 'java.lang');
|
|
7
9
|
exports.illegalStateException = reference_1.ktReference.factory('IllegalStateException', 'java.lang');
|
|
10
|
+
exports.system = reference_1.ktReference.factory('System', 'java.lang');
|
|
8
11
|
exports.unsupportedOperationException = reference_1.ktReference.factory('UnsupportedOperationException', 'java.lang');
|
|
9
|
-
// java.io
|
|
10
|
-
exports.ioException = reference_1.ktReference.factory('IOException', 'java.io');
|
|
11
12
|
// java.time
|
|
12
13
|
exports.offsetDateTime = reference_1.ktReference.factory('OffsetDateTime', 'java.time');
|
|
13
14
|
// java.util
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flux = void 0;
|
|
3
|
+
exports.mono = exports.flux = void 0;
|
|
4
4
|
const reference_1 = require("../nodes/reference");
|
|
5
5
|
// reactor.core.publisher
|
|
6
6
|
exports.flux = reference_1.ktReference.genericFactory('Flux', 'reactor.core.publisher');
|
|
7
|
+
exports.mono = reference_1.ktReference.genericFactory('Mono', 'reactor.core.publisher');
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.nativeWebRequest = exports.requestPart = exports.requestParam = exports.requestMethod = exports.requestMapping = exports.requestBody = exports.pathVariable = exports.validated = exports.controller = exports.filePart = exports.responseEntity = exports.httpStatus = exports.autowired = void 0;
|
|
4
4
|
const reference_1 = require("../nodes/reference");
|
|
5
|
-
// org.springframework.web.bind.annotation
|
|
6
|
-
exports.requestMapping = reference_1.ktReference.factory('RequestMapping', 'org.springframework.web.bind.annotation');
|
|
7
|
-
exports.requestBody = reference_1.ktReference.factory('RequestBody', 'org.springframework.web.bind.annotation');
|
|
8
|
-
exports.requestParam = reference_1.ktReference.factory('RequestParam', 'org.springframework.web.bind.annotation');
|
|
9
|
-
exports.requestMethod = reference_1.ktReference.factory('RequestMethod', 'org.springframework.web.bind.annotation');
|
|
10
|
-
exports.pathVariable = reference_1.ktReference.factory('PathVariable', 'org.springframework.web.bind.annotation');
|
|
11
|
-
// org.springframework.web.context.request
|
|
12
|
-
exports.nativeWebRequest = reference_1.ktReference.factory('NativeWebRequest', 'org.springframework.web.context.request');
|
|
13
5
|
// org.springframework.beans.factory.annotation
|
|
14
6
|
exports.autowired = reference_1.ktReference.factory('Autowired', 'org.springframework.beans.factory.annotation');
|
|
15
|
-
// org.springframework.validation.annotation
|
|
16
|
-
exports.validated = reference_1.ktReference.factory('Validated', 'org.springframework.validation.annotation');
|
|
17
7
|
// org.springframework.http
|
|
18
|
-
exports.responseEntity = reference_1.ktReference.genericFactory('ResponseEntity', 'org.springframework.http');
|
|
19
8
|
exports.httpStatus = reference_1.ktReference.factory('HttpStatus', 'org.springframework.http');
|
|
9
|
+
exports.responseEntity = reference_1.ktReference.genericFactory('ResponseEntity', 'org.springframework.http');
|
|
10
|
+
// org.springframework.http.codec.multipart
|
|
11
|
+
exports.filePart = reference_1.ktReference.factory('FilePart', 'org.springframework.http.codec.multipart');
|
|
20
12
|
// org.springframework.stereotype
|
|
21
13
|
exports.controller = reference_1.ktReference.factory('Controller', 'org.springframework.stereotype');
|
|
14
|
+
// org.springframework.validation.annotation
|
|
15
|
+
exports.validated = reference_1.ktReference.factory('Validated', 'org.springframework.validation.annotation');
|
|
16
|
+
// org.springframework.web.bind.annotation
|
|
17
|
+
exports.pathVariable = reference_1.ktReference.factory('PathVariable', 'org.springframework.web.bind.annotation');
|
|
18
|
+
exports.requestBody = reference_1.ktReference.factory('RequestBody', 'org.springframework.web.bind.annotation');
|
|
19
|
+
exports.requestMapping = reference_1.ktReference.factory('RequestMapping', 'org.springframework.web.bind.annotation');
|
|
20
|
+
exports.requestMethod = reference_1.ktReference.factory('RequestMethod', 'org.springframework.web.bind.annotation');
|
|
21
|
+
exports.requestParam = reference_1.ktReference.factory('RequestParam', 'org.springframework.web.bind.annotation');
|
|
22
|
+
exports.requestPart = reference_1.ktReference.factory('RequestPart', 'org.springframework.web.bind.annotation');
|
|
23
|
+
// org.springframework.web.context.request
|
|
24
|
+
exports.nativeWebRequest = reference_1.ktReference.factory('NativeWebRequest', 'org.springframework.web.context.request');
|
|
@@ -352,6 +352,10 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
352
352
|
if (!ctx.data.schemas.some((x) => x.id === schema.id)) {
|
|
353
353
|
return false;
|
|
354
354
|
}
|
|
355
|
+
// multipart schemas should not have its own type declaration
|
|
356
|
+
if (schema.$src.path.endsWith('/requestBody/content/multipart/form-data/schema')) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
355
359
|
return true;
|
|
356
360
|
}
|
|
357
361
|
getDeclarationTypeName(ctx, args) {
|
|
@@ -90,7 +90,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
90
90
|
],
|
|
91
91
|
parameters: parameters.map((p) => {
|
|
92
92
|
var _a;
|
|
93
|
-
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.
|
|
93
|
+
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
94
94
|
description: p.description,
|
|
95
95
|
default: !p.required ? ast_1.kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
96
96
|
});
|
|
@@ -148,7 +148,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
148
148
|
],
|
|
149
149
|
parameters: parameters.map((p) => {
|
|
150
150
|
var _a;
|
|
151
|
-
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.
|
|
151
|
+
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
152
152
|
description: p.description,
|
|
153
153
|
default: !p.required ? ast_1.kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
154
154
|
});
|
|
@@ -160,14 +160,13 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
getEndpointClientHttpInfoMethodBody(ctx, args) {
|
|
163
|
-
var _a;
|
|
164
163
|
const { endpoint, parameters, responseSchema } = args;
|
|
165
164
|
return (0, core_1.appendValueGroup)([
|
|
166
165
|
(0, core_1.builderTemplate) `val localVariableConfig = ${ast_1.kt.call([(0, core_1.toCasing)(endpoint.name, 'camel') + 'RequestConfig'], parameters.map((x) => x.name))}`,
|
|
167
166
|
(0, core_1.builderTemplate) `return ${ast_1.kt.call([
|
|
168
167
|
ast_1.kt.reference('request', null, {
|
|
169
168
|
generics: [
|
|
170
|
-
this.
|
|
169
|
+
this.getRequestBodyType(ctx, { endpoint }),
|
|
171
170
|
this.getTypeUsage(ctx, { schema: responseSchema, fallback: ast_1.kt.refs.unit() }),
|
|
172
171
|
],
|
|
173
172
|
}),
|
|
@@ -175,33 +174,43 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
175
174
|
], '\n');
|
|
176
175
|
}
|
|
177
176
|
getEndpointClientRequestConfigMethod(ctx, args) {
|
|
178
|
-
var _a;
|
|
179
177
|
const { endpoint, parameters } = args;
|
|
180
178
|
const operationName = (0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing);
|
|
181
|
-
const requestSchema = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema;
|
|
182
179
|
return ast_1.kt.function((0, core_1.toCasing)(args.endpoint.name, ctx.config.functionNameCasing) + 'RequestConfig', {
|
|
183
180
|
accessModifier: 'private',
|
|
184
181
|
doc: ast_1.kt.doc(`To obtain the request config of the operation ${operationName}`),
|
|
185
182
|
annotations: [endpoint.deprecated ? ast_1.kt.annotation(ast_1.kt.refs.deprecated(), [ast_1.kt.argument(ast_1.kt.string(''))]) : null],
|
|
186
183
|
parameters: parameters.map((p) => {
|
|
187
184
|
var _a;
|
|
188
|
-
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.
|
|
185
|
+
return ast_1.kt.parameter((0, core_1.toCasing)(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
189
186
|
description: p.description,
|
|
190
187
|
default: !p.required ? ast_1.kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
191
188
|
});
|
|
192
189
|
}),
|
|
193
|
-
returnType: ctx.refs.requestConfig([this.
|
|
194
|
-
body: this.getEndpointClientRequestConfigMethodBody(ctx, { endpoint }),
|
|
190
|
+
returnType: ctx.refs.requestConfig([this.getRequestBodyType(ctx, { endpoint })]),
|
|
191
|
+
body: this.getEndpointClientRequestConfigMethodBody(ctx, { endpoint, parameters }),
|
|
195
192
|
});
|
|
196
193
|
}
|
|
197
194
|
getEndpointClientRequestConfigMethodBody(ctx, args) {
|
|
198
|
-
var _a, _b;
|
|
199
|
-
const { endpoint } = args;
|
|
200
|
-
const queryParameters =
|
|
195
|
+
var _a, _b, _c;
|
|
196
|
+
const { endpoint, parameters } = args;
|
|
197
|
+
const queryParameters = parameters.filter((x) => x.target === 'query');
|
|
201
198
|
const result = (0, core_1.appendValueGroup)([], '\n');
|
|
202
199
|
if (endpoint.requestBody) {
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
if (((_a = endpoint.requestBody.content[0]) === null || _a === void 0 ? void 0 : _a.type) === 'multipart/form-data') {
|
|
201
|
+
const partConfigs = parameters
|
|
202
|
+
.filter((x) => x.multipart)
|
|
203
|
+
.map((param) => {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
const paramName = (0, core_1.toCasing)(param.name, ctx.config.parameterNameCasing);
|
|
206
|
+
return (0, core_1.builderTemplate) `"${(_b = (_a = param.multipart) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''}" to ${ctx.refs.partConfig.infer()}(body = ${paramName})`;
|
|
207
|
+
});
|
|
208
|
+
result.values.push((0, core_1.builderTemplate) `val localVariableBody = ${ast_1.kt.call(ast_1.kt.refs.mapOf([ast_1.kt.refs.string(), ctx.refs.partConfig(['*'])]), partConfigs)}`);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const bodyParamName = (0, core_1.toCasing)(this.getRequestBodyParamName(ctx, { endpoint }), ctx.config.parameterNameCasing);
|
|
212
|
+
result.values.push(`val localVariableBody = ${bodyParamName}`);
|
|
213
|
+
}
|
|
205
214
|
}
|
|
206
215
|
result.values.push((0, core_1.builderTemplate) `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${ast_1.kt.call([ast_1.kt.refs.mutableMapOf([ast_1.kt.refs.string(), ast_1.kt.refs.list([ast_1.kt.refs.string()])])], [])}${queryParameters.length === 0
|
|
207
216
|
? ''
|
|
@@ -220,8 +229,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
220
229
|
}), '\n')}`}
|
|
221
230
|
}`}`);
|
|
222
231
|
result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
|
|
223
|
-
if (((
|
|
224
|
-
result.values.push(`localVariableHeaders["Content-Type"] = "${(
|
|
232
|
+
if (((_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0]) !== undefined) {
|
|
233
|
+
result.values.push(`localVariableHeaders["Content-Type"] = "${(_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content[0].type}"`);
|
|
225
234
|
}
|
|
226
235
|
result.values.push((0, core_1.builderTemplate) `return ${ast_1.kt.call([ctx.refs.requestConfig.infer()], [
|
|
227
236
|
ast_1.kt.argument.named('method', ast_1.kt.call([ctx.refs.requestMethod(), endpoint.method.toUpperCase()])),
|
|
@@ -244,6 +253,25 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
244
253
|
}),
|
|
245
254
|
];
|
|
246
255
|
}
|
|
256
|
+
getParameterType(ctx, args) {
|
|
257
|
+
var _a;
|
|
258
|
+
const { parameter } = args;
|
|
259
|
+
if ((_a = parameter.multipart) === null || _a === void 0 ? void 0 : _a.isFile) {
|
|
260
|
+
return ast_1.kt.refs.java.file();
|
|
261
|
+
}
|
|
262
|
+
return this.getTypeUsage(ctx, {
|
|
263
|
+
schema: parameter.schema,
|
|
264
|
+
nullable: !parameter.required,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
getRequestBodyType(ctx, args) {
|
|
268
|
+
var _a;
|
|
269
|
+
const { endpoint } = args;
|
|
270
|
+
const content = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0];
|
|
271
|
+
return (content === null || content === void 0 ? void 0 : content.type) === 'multipart/form-data'
|
|
272
|
+
? ast_1.kt.refs.map([ast_1.kt.refs.string(), ctx.refs.partConfig(['*'])])
|
|
273
|
+
: this.getTypeUsage(ctx, { schema: content === null || content === void 0 ? void 0 : content.schema, fallback: ast_1.kt.refs.unit() });
|
|
274
|
+
}
|
|
247
275
|
getTypeUsage(ctx, args) {
|
|
248
276
|
const { schema, nullable, fallback } = args;
|
|
249
277
|
const type = this.getSchemaType(ctx, { schema });
|
|
@@ -275,26 +303,43 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
275
303
|
return schema && ctx.input.kotlin.models[schema.id].type;
|
|
276
304
|
}
|
|
277
305
|
getAllParameters(ctx, args) {
|
|
306
|
+
var _a, _b;
|
|
278
307
|
const { endpoint } = args;
|
|
279
308
|
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' || parameter.target === 'path');
|
|
280
309
|
if (endpoint.requestBody) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
310
|
+
const content = endpoint.requestBody.content[0];
|
|
311
|
+
let schema = content.schema;
|
|
312
|
+
if (content.type === 'multipart/form-data') {
|
|
313
|
+
if (schema && schema.kind === 'object') {
|
|
314
|
+
schema = (_a = (0, core_1.resolveAnyOfAndAllOf)(schema, true)) !== null && _a !== void 0 ? _a : schema;
|
|
315
|
+
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
316
|
+
for (const [name, property] of properties.entries()) {
|
|
317
|
+
parameters.push(Object.assign(this.createApiParameter({
|
|
318
|
+
id: `multipart-${name}`,
|
|
319
|
+
name,
|
|
320
|
+
target: 'body',
|
|
321
|
+
schema: property.schema,
|
|
322
|
+
required: schema.required.has(name),
|
|
323
|
+
description: property.schema.description,
|
|
324
|
+
}), {
|
|
325
|
+
multipart: {
|
|
326
|
+
name,
|
|
327
|
+
isFile: property.schema.kind === 'string' && property.schema.format === 'binary',
|
|
328
|
+
},
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
parameters.push(this.createApiParameter({
|
|
335
|
+
id: 'body',
|
|
336
|
+
name: this.getRequestBodyParamName(ctx, { endpoint }),
|
|
337
|
+
target: 'body',
|
|
338
|
+
schema,
|
|
339
|
+
required: endpoint.requestBody.required,
|
|
340
|
+
description: endpoint.requestBody.description,
|
|
341
|
+
}));
|
|
342
|
+
}
|
|
298
343
|
}
|
|
299
344
|
return parameters.sort((a, b) => (a.required === b.required ? 0 : a.required ? -1 : 1));
|
|
300
345
|
}
|
|
@@ -320,5 +365,21 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
320
365
|
getApiClientName(ctx, args) {
|
|
321
366
|
return (0, core_1.toCasing)(ctx.service.name, ctx.config.typeNameCasing) + 'ApiClient';
|
|
322
367
|
}
|
|
368
|
+
createApiParameter(data) {
|
|
369
|
+
return {
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
371
|
+
$src: undefined,
|
|
372
|
+
$ref: undefined,
|
|
373
|
+
schema: undefined,
|
|
374
|
+
required: false,
|
|
375
|
+
description: undefined,
|
|
376
|
+
allowEmptyValue: undefined,
|
|
377
|
+
allowReserved: undefined,
|
|
378
|
+
deprecated: false,
|
|
379
|
+
explode: undefined,
|
|
380
|
+
style: undefined,
|
|
381
|
+
...data,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
323
384
|
}
|
|
324
385
|
exports.DefaultKotlinOkHttp3Generator = DefaultKotlinOkHttp3Generator;
|
|
@@ -107,6 +107,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
107
107
|
const result = ast_1.kt.parameter((0, core_1.toCasing)(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }), {});
|
|
108
108
|
if (ctx.config.addSwaggerAnnotations) {
|
|
109
109
|
const annotation = ast_1.kt.annotation(ast_1.kt.refs.swagger.parameter(), [
|
|
110
|
+
parameter.multipart ? ast_1.kt.argument.named('name', ast_1.kt.string(parameter.multipart.name)) : null,
|
|
110
111
|
parameter.description ? ast_1.kt.argument.named('description', ast_1.kt.string((_a = parameter.description) === null || _a === void 0 ? void 0 : _a.trim())) : null,
|
|
111
112
|
ast_1.kt.argument.named('required', parameter.required),
|
|
112
113
|
]);
|
|
@@ -119,7 +120,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
119
120
|
if (!isCorePackage && ctx.config.addJakartaValidationAnnotations) {
|
|
120
121
|
result.annotations.push(ast_1.kt.annotation(ast_1.kt.refs.jakarta.valid()));
|
|
121
122
|
}
|
|
122
|
-
if (parameter.target === 'body') {
|
|
123
|
+
if (parameter.target === 'body' && !parameter.multipart) {
|
|
123
124
|
result.annotations.push(ast_1.kt.annotation(ast_1.kt.refs.spring.requestBody()));
|
|
124
125
|
}
|
|
125
126
|
if (parameter.target === 'query') {
|
|
@@ -135,6 +136,12 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
135
136
|
if (parameter.target === 'path') {
|
|
136
137
|
result.annotations.push(ast_1.kt.annotation(ast_1.kt.refs.spring.pathVariable(), [ast_1.kt.string(parameter.name)]));
|
|
137
138
|
}
|
|
139
|
+
if (parameter.multipart) {
|
|
140
|
+
result.annotations.push(ast_1.kt.annotation(ast_1.kt.refs.spring.requestPart(), [
|
|
141
|
+
ast_1.kt.argument.named('value', ast_1.kt.string(parameter.multipart.name)),
|
|
142
|
+
ast_1.kt.argument.named('required', parameter.required),
|
|
143
|
+
]));
|
|
144
|
+
}
|
|
138
145
|
return result;
|
|
139
146
|
}
|
|
140
147
|
getApiInterfaceEndpointMethodBody(ctx, endpoint, parameters) {
|
|
@@ -259,11 +266,14 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
259
266
|
}
|
|
260
267
|
// #endregion
|
|
261
268
|
getParameterType(ctx, args) {
|
|
262
|
-
var _a;
|
|
269
|
+
var _a, _b;
|
|
263
270
|
const { parameter } = args;
|
|
271
|
+
if ((_a = parameter.multipart) === null || _a === void 0 ? void 0 : _a.isFile) {
|
|
272
|
+
return ast_1.kt.refs.reactor.mono([ast_1.kt.refs.spring.filePart()]);
|
|
273
|
+
}
|
|
264
274
|
const type = this.getTypeUsage(ctx, {
|
|
265
275
|
schema: parameter.schema,
|
|
266
|
-
nullable: (!parameter.required && ((
|
|
276
|
+
nullable: (!parameter.required && ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.default) === undefined) || undefined,
|
|
267
277
|
});
|
|
268
278
|
return parameter.target === 'body' ? listToFlux(type) : type;
|
|
269
279
|
}
|
|
@@ -330,33 +340,66 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
330
340
|
return (0, core_1.toCasing)(ctx.service.name + '_ApiDelegate', ctx.config.typeNameCasing);
|
|
331
341
|
}
|
|
332
342
|
getAllParameters(ctx, args) {
|
|
343
|
+
var _a, _b;
|
|
333
344
|
const { endpoint } = args;
|
|
334
345
|
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' || parameter.target === 'path');
|
|
335
346
|
if (endpoint.requestBody) {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
347
|
+
const content = endpoint.requestBody.content[0];
|
|
348
|
+
let schema = content.schema;
|
|
349
|
+
if (content.type === 'multipart/form-data') {
|
|
350
|
+
if (schema && schema.kind === 'object') {
|
|
351
|
+
schema = (_a = (0, core_1.resolveAnyOfAndAllOf)(schema, true)) !== null && _a !== void 0 ? _a : schema;
|
|
352
|
+
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
353
|
+
for (const [name, property] of properties.entries()) {
|
|
354
|
+
parameters.push(Object.assign(this.createApiParameter({
|
|
355
|
+
id: `multipart-${name}`,
|
|
356
|
+
name,
|
|
357
|
+
target: 'body',
|
|
358
|
+
schema: property.schema,
|
|
359
|
+
required: schema.required.has(name),
|
|
360
|
+
description: property.schema.description,
|
|
361
|
+
}), {
|
|
362
|
+
multipart: {
|
|
363
|
+
name,
|
|
364
|
+
isFile: property.schema.kind === 'string' && property.schema.format === 'binary',
|
|
365
|
+
},
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
const schemaType = this.getSchemaType(ctx, { schema });
|
|
372
|
+
const name = !schemaType || /^Any\??$/.test(schemaType.name)
|
|
373
|
+
? 'body'
|
|
374
|
+
: core_1.SourceBuilder.build((b) => ast_1.kt.reference.write(b, schemaType));
|
|
375
|
+
parameters.push(this.createApiParameter({
|
|
376
|
+
id: 'body',
|
|
377
|
+
name,
|
|
378
|
+
target: 'body',
|
|
379
|
+
schema,
|
|
380
|
+
required: endpoint.requestBody.required,
|
|
381
|
+
description: endpoint.requestBody.description,
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
357
384
|
}
|
|
358
385
|
return parameters;
|
|
359
386
|
}
|
|
387
|
+
createApiParameter(data) {
|
|
388
|
+
return {
|
|
389
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
390
|
+
$src: undefined,
|
|
391
|
+
$ref: undefined,
|
|
392
|
+
schema: undefined,
|
|
393
|
+
required: false,
|
|
394
|
+
description: undefined,
|
|
395
|
+
allowEmptyValue: undefined,
|
|
396
|
+
allowReserved: undefined,
|
|
397
|
+
deprecated: false,
|
|
398
|
+
explode: undefined,
|
|
399
|
+
style: undefined,
|
|
400
|
+
...data,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
360
403
|
}
|
|
361
404
|
exports.DefaultKotlinSpringControllerGenerator = DefaultKotlinSpringControllerGenerator;
|
|
362
405
|
function listToFlux(type) {
|
package/cjs/lib/types.js
ADDED
package/esm/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './lib/ast';
|
|
1
2
|
export * from './lib/common-results';
|
|
2
3
|
export * from './lib/config';
|
|
3
|
-
export * from './lib/generators';
|
|
4
4
|
export * from './lib/file-builder';
|
|
5
|
+
export * from './lib/generators';
|
|
5
6
|
export * from './lib/import-collection';
|
|
7
|
+
export * from './lib/types';
|
|
6
8
|
export * from './lib/utils';
|
|
7
|
-
export * from './lib/ast';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ktReference } from '../nodes/reference';
|
|
2
|
+
// java.io
|
|
3
|
+
export const file = ktReference.factory('File', 'java.io');
|
|
4
|
+
export const ioException = ktReference.factory('IOException', 'java.io');
|
|
2
5
|
// java.lang
|
|
3
|
-
export const system = ktReference.factory('System', 'java.lang');
|
|
4
6
|
export const illegalStateException = ktReference.factory('IllegalStateException', 'java.lang');
|
|
7
|
+
export const system = ktReference.factory('System', 'java.lang');
|
|
5
8
|
export const unsupportedOperationException = ktReference.factory('UnsupportedOperationException', 'java.lang');
|
|
6
|
-
// java.io
|
|
7
|
-
export const ioException = ktReference.factory('IOException', 'java.io');
|
|
8
9
|
// java.time
|
|
9
10
|
export const offsetDateTime = ktReference.factory('OffsetDateTime', 'java.time');
|
|
10
11
|
// java.util
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { ktReference } from '../nodes/reference';
|
|
2
|
-
// org.springframework.web.bind.annotation
|
|
3
|
-
export const requestMapping = ktReference.factory('RequestMapping', 'org.springframework.web.bind.annotation');
|
|
4
|
-
export const requestBody = ktReference.factory('RequestBody', 'org.springframework.web.bind.annotation');
|
|
5
|
-
export const requestParam = ktReference.factory('RequestParam', 'org.springframework.web.bind.annotation');
|
|
6
|
-
export const requestMethod = ktReference.factory('RequestMethod', 'org.springframework.web.bind.annotation');
|
|
7
|
-
export const pathVariable = ktReference.factory('PathVariable', 'org.springframework.web.bind.annotation');
|
|
8
|
-
// org.springframework.web.context.request
|
|
9
|
-
export const nativeWebRequest = ktReference.factory('NativeWebRequest', 'org.springframework.web.context.request');
|
|
10
2
|
// org.springframework.beans.factory.annotation
|
|
11
3
|
export const autowired = ktReference.factory('Autowired', 'org.springframework.beans.factory.annotation');
|
|
12
|
-
// org.springframework.validation.annotation
|
|
13
|
-
export const validated = ktReference.factory('Validated', 'org.springframework.validation.annotation');
|
|
14
4
|
// org.springframework.http
|
|
15
|
-
export const responseEntity = ktReference.genericFactory('ResponseEntity', 'org.springframework.http');
|
|
16
5
|
export const httpStatus = ktReference.factory('HttpStatus', 'org.springframework.http');
|
|
6
|
+
export const responseEntity = ktReference.genericFactory('ResponseEntity', 'org.springframework.http');
|
|
7
|
+
// org.springframework.http.codec.multipart
|
|
8
|
+
export const filePart = ktReference.factory('FilePart', 'org.springframework.http.codec.multipart');
|
|
17
9
|
// org.springframework.stereotype
|
|
18
10
|
export const controller = ktReference.factory('Controller', 'org.springframework.stereotype');
|
|
11
|
+
// org.springframework.validation.annotation
|
|
12
|
+
export const validated = ktReference.factory('Validated', 'org.springframework.validation.annotation');
|
|
13
|
+
// org.springframework.web.bind.annotation
|
|
14
|
+
export const pathVariable = ktReference.factory('PathVariable', 'org.springframework.web.bind.annotation');
|
|
15
|
+
export const requestBody = ktReference.factory('RequestBody', 'org.springframework.web.bind.annotation');
|
|
16
|
+
export const requestMapping = ktReference.factory('RequestMapping', 'org.springframework.web.bind.annotation');
|
|
17
|
+
export const requestMethod = ktReference.factory('RequestMethod', 'org.springframework.web.bind.annotation');
|
|
18
|
+
export const requestParam = ktReference.factory('RequestParam', 'org.springframework.web.bind.annotation');
|
|
19
|
+
export const requestPart = ktReference.factory('RequestPart', 'org.springframework.web.bind.annotation');
|
|
20
|
+
// org.springframework.web.context.request
|
|
21
|
+
export const nativeWebRequest = ktReference.factory('NativeWebRequest', 'org.springframework.web.context.request');
|
|
@@ -349,6 +349,10 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
349
349
|
if (!ctx.data.schemas.some((x) => x.id === schema.id)) {
|
|
350
350
|
return false;
|
|
351
351
|
}
|
|
352
|
+
// multipart schemas should not have its own type declaration
|
|
353
|
+
if (schema.$src.path.endsWith('/requestBody/content/multipart/form-data/schema')) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
352
356
|
return true;
|
|
353
357
|
}
|
|
354
358
|
getDeclarationTypeName(ctx, args) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { writeFileSync } from 'fs';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
import { ensureDirSync } from 'fs-extra';
|
|
5
|
-
import { SourceBuilder, appendValueGroup, builderTemplate as s, createOverwriteProxy, toCasing, } from '@goast/core';
|
|
5
|
+
import { SourceBuilder, appendValueGroup, builderTemplate as s, createOverwriteProxy, toCasing, resolveAnyOfAndAllOf, } from '@goast/core';
|
|
6
6
|
import { kt } from '../../../ast';
|
|
7
7
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
8
8
|
import { modifyString } from '../../../utils';
|
|
@@ -87,7 +87,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
87
87
|
],
|
|
88
88
|
parameters: parameters.map((p) => {
|
|
89
89
|
var _a;
|
|
90
|
-
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.
|
|
90
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
91
91
|
description: p.description,
|
|
92
92
|
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
93
93
|
});
|
|
@@ -145,7 +145,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
145
145
|
],
|
|
146
146
|
parameters: parameters.map((p) => {
|
|
147
147
|
var _a;
|
|
148
|
-
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.
|
|
148
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
149
149
|
description: p.description,
|
|
150
150
|
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
151
151
|
});
|
|
@@ -157,14 +157,13 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
getEndpointClientHttpInfoMethodBody(ctx, args) {
|
|
160
|
-
var _a;
|
|
161
160
|
const { endpoint, parameters, responseSchema } = args;
|
|
162
161
|
return appendValueGroup([
|
|
163
162
|
s `val localVariableConfig = ${kt.call([toCasing(endpoint.name, 'camel') + 'RequestConfig'], parameters.map((x) => x.name))}`,
|
|
164
163
|
s `return ${kt.call([
|
|
165
164
|
kt.reference('request', null, {
|
|
166
165
|
generics: [
|
|
167
|
-
this.
|
|
166
|
+
this.getRequestBodyType(ctx, { endpoint }),
|
|
168
167
|
this.getTypeUsage(ctx, { schema: responseSchema, fallback: kt.refs.unit() }),
|
|
169
168
|
],
|
|
170
169
|
}),
|
|
@@ -172,33 +171,43 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
172
171
|
], '\n');
|
|
173
172
|
}
|
|
174
173
|
getEndpointClientRequestConfigMethod(ctx, args) {
|
|
175
|
-
var _a;
|
|
176
174
|
const { endpoint, parameters } = args;
|
|
177
175
|
const operationName = toCasing(endpoint.name, ctx.config.functionNameCasing);
|
|
178
|
-
const requestSchema = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema;
|
|
179
176
|
return kt.function(toCasing(args.endpoint.name, ctx.config.functionNameCasing) + 'RequestConfig', {
|
|
180
177
|
accessModifier: 'private',
|
|
181
178
|
doc: kt.doc(`To obtain the request config of the operation ${operationName}`),
|
|
182
179
|
annotations: [endpoint.deprecated ? kt.annotation(kt.refs.deprecated(), [kt.argument(kt.string(''))]) : null],
|
|
183
180
|
parameters: parameters.map((p) => {
|
|
184
181
|
var _a;
|
|
185
|
-
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.
|
|
182
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter: p }), {
|
|
186
183
|
description: p.description,
|
|
187
184
|
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
188
185
|
});
|
|
189
186
|
}),
|
|
190
|
-
returnType: ctx.refs.requestConfig([this.
|
|
191
|
-
body: this.getEndpointClientRequestConfigMethodBody(ctx, { endpoint }),
|
|
187
|
+
returnType: ctx.refs.requestConfig([this.getRequestBodyType(ctx, { endpoint })]),
|
|
188
|
+
body: this.getEndpointClientRequestConfigMethodBody(ctx, { endpoint, parameters }),
|
|
192
189
|
});
|
|
193
190
|
}
|
|
194
191
|
getEndpointClientRequestConfigMethodBody(ctx, args) {
|
|
195
|
-
var _a, _b;
|
|
196
|
-
const { endpoint } = args;
|
|
197
|
-
const queryParameters =
|
|
192
|
+
var _a, _b, _c;
|
|
193
|
+
const { endpoint, parameters } = args;
|
|
194
|
+
const queryParameters = parameters.filter((x) => x.target === 'query');
|
|
198
195
|
const result = appendValueGroup([], '\n');
|
|
199
196
|
if (endpoint.requestBody) {
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
if (((_a = endpoint.requestBody.content[0]) === null || _a === void 0 ? void 0 : _a.type) === 'multipart/form-data') {
|
|
198
|
+
const partConfigs = parameters
|
|
199
|
+
.filter((x) => x.multipart)
|
|
200
|
+
.map((param) => {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
const paramName = toCasing(param.name, ctx.config.parameterNameCasing);
|
|
203
|
+
return s `"${(_b = (_a = param.multipart) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''}" to ${ctx.refs.partConfig.infer()}(body = ${paramName})`;
|
|
204
|
+
});
|
|
205
|
+
result.values.push(s `val localVariableBody = ${kt.call(kt.refs.mapOf([kt.refs.string(), ctx.refs.partConfig(['*'])]), partConfigs)}`);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const bodyParamName = toCasing(this.getRequestBodyParamName(ctx, { endpoint }), ctx.config.parameterNameCasing);
|
|
209
|
+
result.values.push(`val localVariableBody = ${bodyParamName}`);
|
|
210
|
+
}
|
|
202
211
|
}
|
|
203
212
|
result.values.push(s `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${kt.call([kt.refs.mutableMapOf([kt.refs.string(), kt.refs.list([kt.refs.string()])])], [])}${queryParameters.length === 0
|
|
204
213
|
? ''
|
|
@@ -217,8 +226,8 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
217
226
|
}), '\n')}`}
|
|
218
227
|
}`}`);
|
|
219
228
|
result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
|
|
220
|
-
if (((
|
|
221
|
-
result.values.push(`localVariableHeaders["Content-Type"] = "${(
|
|
229
|
+
if (((_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0]) !== undefined) {
|
|
230
|
+
result.values.push(`localVariableHeaders["Content-Type"] = "${(_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content[0].type}"`);
|
|
222
231
|
}
|
|
223
232
|
result.values.push(s `return ${kt.call([ctx.refs.requestConfig.infer()], [
|
|
224
233
|
kt.argument.named('method', kt.call([ctx.refs.requestMethod(), endpoint.method.toUpperCase()])),
|
|
@@ -241,6 +250,25 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
241
250
|
}),
|
|
242
251
|
];
|
|
243
252
|
}
|
|
253
|
+
getParameterType(ctx, args) {
|
|
254
|
+
var _a;
|
|
255
|
+
const { parameter } = args;
|
|
256
|
+
if ((_a = parameter.multipart) === null || _a === void 0 ? void 0 : _a.isFile) {
|
|
257
|
+
return kt.refs.java.file();
|
|
258
|
+
}
|
|
259
|
+
return this.getTypeUsage(ctx, {
|
|
260
|
+
schema: parameter.schema,
|
|
261
|
+
nullable: !parameter.required,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
getRequestBodyType(ctx, args) {
|
|
265
|
+
var _a;
|
|
266
|
+
const { endpoint } = args;
|
|
267
|
+
const content = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0];
|
|
268
|
+
return (content === null || content === void 0 ? void 0 : content.type) === 'multipart/form-data'
|
|
269
|
+
? kt.refs.map([kt.refs.string(), ctx.refs.partConfig(['*'])])
|
|
270
|
+
: this.getTypeUsage(ctx, { schema: content === null || content === void 0 ? void 0 : content.schema, fallback: kt.refs.unit() });
|
|
271
|
+
}
|
|
244
272
|
getTypeUsage(ctx, args) {
|
|
245
273
|
const { schema, nullable, fallback } = args;
|
|
246
274
|
const type = this.getSchemaType(ctx, { schema });
|
|
@@ -272,26 +300,43 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
272
300
|
return schema && ctx.input.kotlin.models[schema.id].type;
|
|
273
301
|
}
|
|
274
302
|
getAllParameters(ctx, args) {
|
|
303
|
+
var _a, _b;
|
|
275
304
|
const { endpoint } = args;
|
|
276
305
|
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' || parameter.target === 'path');
|
|
277
306
|
if (endpoint.requestBody) {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
307
|
+
const content = endpoint.requestBody.content[0];
|
|
308
|
+
let schema = content.schema;
|
|
309
|
+
if (content.type === 'multipart/form-data') {
|
|
310
|
+
if (schema && schema.kind === 'object') {
|
|
311
|
+
schema = (_a = resolveAnyOfAndAllOf(schema, true)) !== null && _a !== void 0 ? _a : schema;
|
|
312
|
+
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
313
|
+
for (const [name, property] of properties.entries()) {
|
|
314
|
+
parameters.push(Object.assign(this.createApiParameter({
|
|
315
|
+
id: `multipart-${name}`,
|
|
316
|
+
name,
|
|
317
|
+
target: 'body',
|
|
318
|
+
schema: property.schema,
|
|
319
|
+
required: schema.required.has(name),
|
|
320
|
+
description: property.schema.description,
|
|
321
|
+
}), {
|
|
322
|
+
multipart: {
|
|
323
|
+
name,
|
|
324
|
+
isFile: property.schema.kind === 'string' && property.schema.format === 'binary',
|
|
325
|
+
},
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
parameters.push(this.createApiParameter({
|
|
332
|
+
id: 'body',
|
|
333
|
+
name: this.getRequestBodyParamName(ctx, { endpoint }),
|
|
334
|
+
target: 'body',
|
|
335
|
+
schema,
|
|
336
|
+
required: endpoint.requestBody.required,
|
|
337
|
+
description: endpoint.requestBody.description,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
295
340
|
}
|
|
296
341
|
return parameters.sort((a, b) => (a.required === b.required ? 0 : a.required ? -1 : 1));
|
|
297
342
|
}
|
|
@@ -317,4 +362,20 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
317
362
|
getApiClientName(ctx, args) {
|
|
318
363
|
return toCasing(ctx.service.name, ctx.config.typeNameCasing) + 'ApiClient';
|
|
319
364
|
}
|
|
365
|
+
createApiParameter(data) {
|
|
366
|
+
return {
|
|
367
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
368
|
+
$src: undefined,
|
|
369
|
+
$ref: undefined,
|
|
370
|
+
schema: undefined,
|
|
371
|
+
required: false,
|
|
372
|
+
description: undefined,
|
|
373
|
+
allowEmptyValue: undefined,
|
|
374
|
+
allowReserved: undefined,
|
|
375
|
+
deprecated: false,
|
|
376
|
+
explode: undefined,
|
|
377
|
+
style: undefined,
|
|
378
|
+
...data,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
320
381
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable unused-imports/no-unused-vars */
|
|
2
2
|
import { ensureDirSync, writeFileSync } from 'fs-extra';
|
|
3
|
-
import { SourceBuilder, appendValueGroup, builderTemplate as s, createOverwriteProxy, notNullish, toCasing, } from '@goast/core';
|
|
3
|
+
import { SourceBuilder, appendValueGroup, builderTemplate as s, createOverwriteProxy, notNullish, toCasing, resolveAnyOfAndAllOf, } from '@goast/core';
|
|
4
4
|
import { kt } from '../../../ast';
|
|
5
5
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
6
6
|
import { modifyString } from '../../../utils';
|
|
@@ -103,6 +103,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
103
103
|
const result = kt.parameter(toCasing(parameter.name, ctx.config.parameterNameCasing), this.getParameterType(ctx, { endpoint, parameter }), {});
|
|
104
104
|
if (ctx.config.addSwaggerAnnotations) {
|
|
105
105
|
const annotation = kt.annotation(kt.refs.swagger.parameter(), [
|
|
106
|
+
parameter.multipart ? kt.argument.named('name', kt.string(parameter.multipart.name)) : null,
|
|
106
107
|
parameter.description ? kt.argument.named('description', kt.string((_a = parameter.description) === null || _a === void 0 ? void 0 : _a.trim())) : null,
|
|
107
108
|
kt.argument.named('required', parameter.required),
|
|
108
109
|
]);
|
|
@@ -115,7 +116,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
115
116
|
if (!isCorePackage && ctx.config.addJakartaValidationAnnotations) {
|
|
116
117
|
result.annotations.push(kt.annotation(kt.refs.jakarta.valid()));
|
|
117
118
|
}
|
|
118
|
-
if (parameter.target === 'body') {
|
|
119
|
+
if (parameter.target === 'body' && !parameter.multipart) {
|
|
119
120
|
result.annotations.push(kt.annotation(kt.refs.spring.requestBody()));
|
|
120
121
|
}
|
|
121
122
|
if (parameter.target === 'query') {
|
|
@@ -131,6 +132,12 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
131
132
|
if (parameter.target === 'path') {
|
|
132
133
|
result.annotations.push(kt.annotation(kt.refs.spring.pathVariable(), [kt.string(parameter.name)]));
|
|
133
134
|
}
|
|
135
|
+
if (parameter.multipart) {
|
|
136
|
+
result.annotations.push(kt.annotation(kt.refs.spring.requestPart(), [
|
|
137
|
+
kt.argument.named('value', kt.string(parameter.multipart.name)),
|
|
138
|
+
kt.argument.named('required', parameter.required),
|
|
139
|
+
]));
|
|
140
|
+
}
|
|
134
141
|
return result;
|
|
135
142
|
}
|
|
136
143
|
getApiInterfaceEndpointMethodBody(ctx, endpoint, parameters) {
|
|
@@ -255,11 +262,14 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
255
262
|
}
|
|
256
263
|
// #endregion
|
|
257
264
|
getParameterType(ctx, args) {
|
|
258
|
-
var _a;
|
|
265
|
+
var _a, _b;
|
|
259
266
|
const { parameter } = args;
|
|
267
|
+
if ((_a = parameter.multipart) === null || _a === void 0 ? void 0 : _a.isFile) {
|
|
268
|
+
return kt.refs.reactor.mono([kt.refs.spring.filePart()]);
|
|
269
|
+
}
|
|
260
270
|
const type = this.getTypeUsage(ctx, {
|
|
261
271
|
schema: parameter.schema,
|
|
262
|
-
nullable: (!parameter.required && ((
|
|
272
|
+
nullable: (!parameter.required && ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.default) === undefined) || undefined,
|
|
263
273
|
});
|
|
264
274
|
return parameter.target === 'body' ? listToFlux(type) : type;
|
|
265
275
|
}
|
|
@@ -326,33 +336,66 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
326
336
|
return toCasing(ctx.service.name + '_ApiDelegate', ctx.config.typeNameCasing);
|
|
327
337
|
}
|
|
328
338
|
getAllParameters(ctx, args) {
|
|
339
|
+
var _a, _b;
|
|
329
340
|
const { endpoint } = args;
|
|
330
341
|
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' || parameter.target === 'path');
|
|
331
342
|
if (endpoint.requestBody) {
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
343
|
+
const content = endpoint.requestBody.content[0];
|
|
344
|
+
let schema = content.schema;
|
|
345
|
+
if (content.type === 'multipart/form-data') {
|
|
346
|
+
if (schema && schema.kind === 'object') {
|
|
347
|
+
schema = (_a = resolveAnyOfAndAllOf(schema, true)) !== null && _a !== void 0 ? _a : schema;
|
|
348
|
+
const properties = (_b = schema.properties) !== null && _b !== void 0 ? _b : {};
|
|
349
|
+
for (const [name, property] of properties.entries()) {
|
|
350
|
+
parameters.push(Object.assign(this.createApiParameter({
|
|
351
|
+
id: `multipart-${name}`,
|
|
352
|
+
name,
|
|
353
|
+
target: 'body',
|
|
354
|
+
schema: property.schema,
|
|
355
|
+
required: schema.required.has(name),
|
|
356
|
+
description: property.schema.description,
|
|
357
|
+
}), {
|
|
358
|
+
multipart: {
|
|
359
|
+
name,
|
|
360
|
+
isFile: property.schema.kind === 'string' && property.schema.format === 'binary',
|
|
361
|
+
},
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
const schemaType = this.getSchemaType(ctx, { schema });
|
|
368
|
+
const name = !schemaType || /^Any\??$/.test(schemaType.name)
|
|
369
|
+
? 'body'
|
|
370
|
+
: SourceBuilder.build((b) => kt.reference.write(b, schemaType));
|
|
371
|
+
parameters.push(this.createApiParameter({
|
|
372
|
+
id: 'body',
|
|
373
|
+
name,
|
|
374
|
+
target: 'body',
|
|
375
|
+
schema,
|
|
376
|
+
required: endpoint.requestBody.required,
|
|
377
|
+
description: endpoint.requestBody.description,
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
353
380
|
}
|
|
354
381
|
return parameters;
|
|
355
382
|
}
|
|
383
|
+
createApiParameter(data) {
|
|
384
|
+
return {
|
|
385
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
386
|
+
$src: undefined,
|
|
387
|
+
$ref: undefined,
|
|
388
|
+
schema: undefined,
|
|
389
|
+
required: false,
|
|
390
|
+
description: undefined,
|
|
391
|
+
allowEmptyValue: undefined,
|
|
392
|
+
allowReserved: undefined,
|
|
393
|
+
deprecated: false,
|
|
394
|
+
explode: undefined,
|
|
395
|
+
style: undefined,
|
|
396
|
+
...data,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
356
399
|
}
|
|
357
400
|
export function listToFlux(type) {
|
|
358
401
|
return kt.refs.list.matches(type) ? kt.refs.reactor.flux([type.generics[0]]) : type;
|
package/esm/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export * from './lib/ast';
|
|
1
2
|
export * from './lib/common-results';
|
|
2
3
|
export * from './lib/config';
|
|
3
|
-
export * from './lib/generators';
|
|
4
4
|
export * from './lib/file-builder';
|
|
5
|
+
export * from './lib/generators';
|
|
5
6
|
export * from './lib/import-collection';
|
|
7
|
+
export * from './lib/types';
|
|
6
8
|
export * from './lib/utils';
|
|
7
|
-
export * from './lib/ast';
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const file: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
2
|
+
name: string;
|
|
3
|
+
packageName?: import("@goast/core").Nullable<string>;
|
|
4
|
+
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
5
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
6
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
7
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
8
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
9
|
+
}, "name" | "packageName">>) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
10
|
+
refName: string;
|
|
11
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
12
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
13
|
+
};
|
|
14
|
+
export declare const ioException: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
2
15
|
name: string;
|
|
3
16
|
packageName?: import("@goast/core").Nullable<string>;
|
|
4
17
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -24,7 +37,7 @@ export declare const illegalStateException: (<TBuilder extends import("@goast/co
|
|
|
24
37
|
packageName: import("@goast/core").Nullable<string>;
|
|
25
38
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
26
39
|
};
|
|
27
|
-
export declare const
|
|
40
|
+
export declare const system: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
28
41
|
name: string;
|
|
29
42
|
packageName?: import("@goast/core").Nullable<string>;
|
|
30
43
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -37,7 +50,7 @@ export declare const unsupportedOperationException: (<TBuilder extends import("@
|
|
|
37
50
|
packageName: import("@goast/core").Nullable<string>;
|
|
38
51
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
39
52
|
};
|
|
40
|
-
export declare const
|
|
53
|
+
export declare const unsupportedOperationException: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
41
54
|
name: string;
|
|
42
55
|
packageName?: import("@goast/core").Nullable<string>;
|
|
43
56
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -14,3 +14,19 @@ export declare const flux: (<TBuilder extends import("@goast/core").SourceBuilde
|
|
|
14
14
|
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>;
|
|
15
15
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
16
16
|
};
|
|
17
|
+
export declare const mono: (<TBuilder extends import("@goast/core").SourceBuilder>(generics: [import("../_index").Type<TBuilder>], options?: {
|
|
18
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
19
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
20
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
21
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
22
|
+
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
23
|
+
refName: string;
|
|
24
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
25
|
+
infer: <TBuilder extends import("@goast/core").SourceBuilder>(options?: {
|
|
26
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
27
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
28
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
29
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
30
|
+
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>;
|
|
31
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
32
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const autowired: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
2
2
|
name: string;
|
|
3
3
|
packageName?: import("@goast/core").Nullable<string>;
|
|
4
4
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -11,7 +11,7 @@ export declare const requestMapping: (<TBuilder extends import("@goast/core").So
|
|
|
11
11
|
packageName: import("@goast/core").Nullable<string>;
|
|
12
12
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
13
13
|
};
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const httpStatus: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
15
15
|
name: string;
|
|
16
16
|
packageName?: import("@goast/core").Nullable<string>;
|
|
17
17
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -24,7 +24,23 @@ export declare const requestBody: (<TBuilder extends import("@goast/core").Sourc
|
|
|
24
24
|
packageName: import("@goast/core").Nullable<string>;
|
|
25
25
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
26
26
|
};
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const responseEntity: (<TBuilder extends import("@goast/core").SourceBuilder>(generics: [import("../_index").Type<TBuilder>], options?: {
|
|
28
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
29
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
30
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
31
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
32
|
+
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
33
|
+
refName: string;
|
|
34
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
35
|
+
infer: <TBuilder extends import("@goast/core").SourceBuilder>(options?: {
|
|
36
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
37
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
38
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
39
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
40
|
+
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>;
|
|
41
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
42
|
+
};
|
|
43
|
+
export declare const filePart: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
28
44
|
name: string;
|
|
29
45
|
packageName?: import("@goast/core").Nullable<string>;
|
|
30
46
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -37,7 +53,7 @@ export declare const requestParam: (<TBuilder extends import("@goast/core").Sour
|
|
|
37
53
|
packageName: import("@goast/core").Nullable<string>;
|
|
38
54
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
39
55
|
};
|
|
40
|
-
export declare const
|
|
56
|
+
export declare const controller: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
41
57
|
name: string;
|
|
42
58
|
packageName?: import("@goast/core").Nullable<string>;
|
|
43
59
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -50,7 +66,7 @@ export declare const requestMethod: (<TBuilder extends import("@goast/core").Sou
|
|
|
50
66
|
packageName: import("@goast/core").Nullable<string>;
|
|
51
67
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
52
68
|
};
|
|
53
|
-
export declare const
|
|
69
|
+
export declare const validated: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
54
70
|
name: string;
|
|
55
71
|
packageName?: import("@goast/core").Nullable<string>;
|
|
56
72
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -63,7 +79,7 @@ export declare const pathVariable: (<TBuilder extends import("@goast/core").Sour
|
|
|
63
79
|
packageName: import("@goast/core").Nullable<string>;
|
|
64
80
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
65
81
|
};
|
|
66
|
-
export declare const
|
|
82
|
+
export declare const pathVariable: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
67
83
|
name: string;
|
|
68
84
|
packageName?: import("@goast/core").Nullable<string>;
|
|
69
85
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -76,7 +92,7 @@ export declare const nativeWebRequest: (<TBuilder extends import("@goast/core").
|
|
|
76
92
|
packageName: import("@goast/core").Nullable<string>;
|
|
77
93
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
78
94
|
};
|
|
79
|
-
export declare const
|
|
95
|
+
export declare const requestBody: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
80
96
|
name: string;
|
|
81
97
|
packageName?: import("@goast/core").Nullable<string>;
|
|
82
98
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -89,7 +105,7 @@ export declare const autowired: (<TBuilder extends import("@goast/core").SourceB
|
|
|
89
105
|
packageName: import("@goast/core").Nullable<string>;
|
|
90
106
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
91
107
|
};
|
|
92
|
-
export declare const
|
|
108
|
+
export declare const requestMapping: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
93
109
|
name: string;
|
|
94
110
|
packageName?: import("@goast/core").Nullable<string>;
|
|
95
111
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -102,23 +118,33 @@ export declare const validated: (<TBuilder extends import("@goast/core").SourceB
|
|
|
102
118
|
packageName: import("@goast/core").Nullable<string>;
|
|
103
119
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
104
120
|
};
|
|
105
|
-
export declare const
|
|
121
|
+
export declare const requestMethod: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
122
|
+
name: string;
|
|
123
|
+
packageName?: import("@goast/core").Nullable<string>;
|
|
124
|
+
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
106
125
|
nullable?: import("@goast/core").Nullable<boolean>;
|
|
126
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
127
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
107
128
|
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
129
|
+
}, "name" | "packageName">>) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
130
|
+
refName: string;
|
|
131
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
132
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
133
|
+
};
|
|
134
|
+
export declare const requestParam: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
135
|
+
name: string;
|
|
136
|
+
packageName?: import("@goast/core").Nullable<string>;
|
|
137
|
+
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
138
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
108
139
|
classReference?: import("@goast/core").Nullable<boolean>;
|
|
109
140
|
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
110
|
-
|
|
141
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
142
|
+
}, "name" | "packageName">>) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
111
143
|
refName: string;
|
|
112
144
|
packageName: import("@goast/core").Nullable<string>;
|
|
113
|
-
infer: <TBuilder extends import("@goast/core").SourceBuilder>(options?: {
|
|
114
|
-
nullable?: import("@goast/core").Nullable<boolean>;
|
|
115
|
-
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
116
|
-
classReference?: import("@goast/core").Nullable<boolean>;
|
|
117
|
-
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
118
|
-
} | undefined) => import("../nodes/reference").KtReference<TBuilder, never>;
|
|
119
145
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
120
146
|
};
|
|
121
|
-
export declare const
|
|
147
|
+
export declare const requestPart: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
122
148
|
name: string;
|
|
123
149
|
packageName?: import("@goast/core").Nullable<string>;
|
|
124
150
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -131,7 +157,7 @@ export declare const httpStatus: (<TBuilder extends import("@goast/core").Source
|
|
|
131
157
|
packageName: import("@goast/core").Nullable<string>;
|
|
132
158
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
133
159
|
};
|
|
134
|
-
export declare const
|
|
160
|
+
export declare const nativeWebRequest: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
135
161
|
name: string;
|
|
136
162
|
packageName?: import("@goast/core").Nullable<string>;
|
|
137
163
|
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApiEndpoint, ApiParameter, ApiSchema, SourceBuilder } from '@goast/core';
|
|
2
2
|
import { kt } from '../../../ast';
|
|
3
|
+
import { ApiParameterWithMultipartInfo } from '../../../types';
|
|
3
4
|
export type GetClientFileContent = {};
|
|
4
5
|
export type GetClientClass = {};
|
|
5
6
|
export type GetClientCompanionObject = {};
|
|
@@ -33,8 +34,16 @@ export type GetEndpointClientRequestConfigMethod = {
|
|
|
33
34
|
};
|
|
34
35
|
export type GetEndpointClientRequestConfigMethodBody = {
|
|
35
36
|
endpoint: ApiEndpoint;
|
|
37
|
+
parameters: ApiParameterWithMultipartInfo[];
|
|
36
38
|
};
|
|
37
39
|
export type GetAdditionalClientMembers = {};
|
|
40
|
+
export type GetParameterType = {
|
|
41
|
+
endpoint: ApiEndpoint;
|
|
42
|
+
parameter: ApiParameterWithMultipartInfo;
|
|
43
|
+
};
|
|
44
|
+
export type GetRequestBodyType = {
|
|
45
|
+
endpoint: ApiEndpoint;
|
|
46
|
+
};
|
|
38
47
|
export type GetTypeUsage<TBuilder extends SourceBuilder> = {
|
|
39
48
|
schema: ApiSchema | undefined;
|
|
40
49
|
nullable?: boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiSchema, AppendValueGroup, SourceBuilder } from '@goast/core';
|
|
2
2
|
import { DefaultKotlinOkHttp3GeneratorArgs as Args } from '.';
|
|
3
3
|
import { KotlinOkHttp3ClientGeneratorContext, KotlinOkHttp3ClientGeneratorOutput } from './models';
|
|
4
4
|
import { kt } from '../../../ast';
|
|
5
5
|
import { KotlinImport } from '../../../common-results';
|
|
6
6
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
7
|
+
import { ApiParameterWithMultipartInfo } from '../../../types';
|
|
7
8
|
import { KotlinFileGenerator } from '../../file-generator';
|
|
8
9
|
type Context = KotlinOkHttp3ClientGeneratorContext;
|
|
9
10
|
type Output = KotlinOkHttp3ClientGeneratorOutput;
|
|
@@ -24,16 +25,19 @@ export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<C
|
|
|
24
25
|
protected getEndpointClientRequestConfigMethod(ctx: Context, args: Args.GetEndpointClientRequestConfigMethod): kt.Function<Builder>;
|
|
25
26
|
protected getEndpointClientRequestConfigMethodBody(ctx: Context, args: Args.GetEndpointClientRequestConfigMethodBody): AppendValueGroup<Builder>;
|
|
26
27
|
protected getAdditionalClientMembers(ctx: Context, args: Args.GetAdditionalClientMembers): kt.ClassMember<Builder>[];
|
|
28
|
+
protected getParameterType(ctx: Context, args: Args.GetParameterType): kt.Type<Builder>;
|
|
29
|
+
protected getRequestBodyType(ctx: Context, args: Args.GetRequestBodyType): kt.Type<Builder>;
|
|
27
30
|
protected getTypeUsage(ctx: Context, args: Args.GetTypeUsage<Builder>): kt.Type<Builder>;
|
|
28
31
|
protected getPackageName(ctx: Context, args: Args.GetPackageName): string;
|
|
29
32
|
protected getPathWithInterpolation(ctx: Context, args: Args.GetPathWithInterpolation): string;
|
|
30
33
|
protected getResponseSchema(ctx: Context, args: Args.GetResponseSchema): ApiSchema | undefined;
|
|
31
34
|
protected getSchemaType(ctx: Context, args: Args.GetSchemaType): kt.Reference<SourceBuilder<never>, never> | undefined;
|
|
32
|
-
protected getAllParameters(ctx: Context, args: Args.GetAllParameters):
|
|
35
|
+
protected getAllParameters(ctx: Context, args: Args.GetAllParameters): ApiParameterWithMultipartInfo[];
|
|
33
36
|
protected getRequestBodyParamName(ctx: Context, args: Args.GetRequestBodyParamName): string;
|
|
34
37
|
protected getBasePath(ctx: Context, args: Args.GetBasePath): string;
|
|
35
38
|
protected getEndpointPath(ctx: Context, args: Args.GetEndpointPath): string;
|
|
36
39
|
protected getFilePath(ctx: Context, args: Args.GetFilePath): string;
|
|
37
40
|
protected getApiClientName(ctx: Context, args: Args.GetApiClientName): string;
|
|
41
|
+
private createApiParameter;
|
|
38
42
|
}
|
|
39
43
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ApiEndpoint,
|
|
1
|
+
import { ApiEndpoint, ApiSchema, SourceBuilder } from '@goast/core';
|
|
2
2
|
import { kt } from '../../../ast';
|
|
3
|
+
import { ApiParameterWithMultipartInfo } from '../../../types';
|
|
3
4
|
export type GenerateApiInterfaceFile = {
|
|
4
5
|
dirPath: string;
|
|
5
6
|
packageName: string;
|
|
@@ -38,7 +39,7 @@ export type GetApiDelegateInterfaceEndpointMethod = {
|
|
|
38
39
|
};
|
|
39
40
|
export type GetParameterType = {
|
|
40
41
|
endpoint: ApiEndpoint;
|
|
41
|
-
parameter:
|
|
42
|
+
parameter: ApiParameterWithMultipartInfo;
|
|
42
43
|
};
|
|
43
44
|
export type GetResponseType = {
|
|
44
45
|
endpoint: ApiEndpoint;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppendValueGroup, SourceBuilder } from '@goast/core';
|
|
2
2
|
import { DefaultKotlinSpringControllerGeneratorArgs as Args } from '.';
|
|
3
3
|
import { KotlinServiceGeneratorContext, KotlinServiceGeneratorOutput } from './models';
|
|
4
4
|
import { kt } from '../../../ast';
|
|
5
5
|
import { KotlinImport } from '../../../common-results';
|
|
6
6
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
7
|
+
import { ApiParameterWithMultipartInfo } from '../../../types';
|
|
7
8
|
import { KotlinFileGenerator } from '../../file-generator';
|
|
8
9
|
type Context = KotlinServiceGeneratorContext;
|
|
9
10
|
type Output = KotlinServiceGeneratorOutput;
|
|
@@ -45,7 +46,8 @@ export declare class DefaultKotlinSpringControllerGenerator extends KotlinFileGe
|
|
|
45
46
|
protected getApiInterfaceName(ctx: Context, args: Args.GetApiInterfaceName): string;
|
|
46
47
|
protected getApiControllerName(ctx: Context, args: Args.GetApiControllerName): string;
|
|
47
48
|
protected getApiDelegateInterfaceName(ctx: Context, args: Args.GetApiDelegateInterfaceName): string;
|
|
48
|
-
protected getAllParameters(ctx: Context, args: Args.GetAllParameters):
|
|
49
|
+
protected getAllParameters(ctx: Context, args: Args.GetAllParameters): ApiParameterWithMultipartInfo[];
|
|
50
|
+
private createApiParameter;
|
|
49
51
|
}
|
|
50
52
|
export declare function listToFlux<T>(type: T): T;
|
|
51
53
|
export {};
|