@goast/kotlin 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultKotlinOkHttp3ClientsGeneratorConfig = void 0;
4
4
  const config_1 = require("../../../config");
5
- exports.defaultKotlinOkHttp3ClientsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.client', infrastructurePackageName: 'com.openapi.client.infrastructure' });
5
+ exports.defaultKotlinOkHttp3ClientsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api.client', infrastructurePackageName: { mode: 'append-full-package-name', value: '.infrastructure' } });
@@ -10,15 +10,14 @@ const utils_1 = require("../../../utils");
10
10
  const file_generator_1 = require("../../file-generator");
11
11
  class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator {
12
12
  generate(ctx) {
13
- const packageName = this.getPackageName(ctx);
14
13
  const typeName = this.getApiClientName(ctx);
15
- const filePath = this.getFilePath(ctx, packageName);
14
+ const filePath = this.getFilePath(ctx);
16
15
  (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(filePath));
17
16
  console.log(`Generating client for service ${ctx.service.name} to ${filePath}...`);
18
- const builder = new file_builder_1.KotlinFileBuilder(packageName, ctx.config);
17
+ const builder = new file_builder_1.KotlinFileBuilder(ctx.packageName, ctx.config);
19
18
  this.generateApiClientFileContent(ctx, builder);
20
19
  (0, fs_1.writeFileSync)(filePath, builder.toString());
21
- return { typeName, packageName };
20
+ return { typeName, packageName: ctx.packageName };
22
21
  }
23
22
  generateApiClientFileContent(ctx, builder) {
24
23
  builder
@@ -39,7 +38,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
39
38
  .appendLine('basePath: String = defaultBasePath,')
40
39
  .appendLine('client: OkHttpClient = ApiClient.defaultClient')
41
40
  .addImport('OkHttpClient', 'okhttp3')
42
- .addImport('ApiClient', ctx.config.infrastructurePackageName))
41
+ .addImport('ApiClient', ctx.infrastructurePackageName))
43
42
  .append(' : ')
44
43
  .append('ApiClient(basePath, client)');
45
44
  }
@@ -70,7 +69,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
70
69
  .append('val defaultBasePath: String by lazy ')
71
70
  .parenthesizeMultiline('{}', (builder) => builder
72
71
  .appendLine(`System.getProperties().getProperty(ApiClient.baseUrlKey, ${this.toStringLiteral(ctx, this.getBasePath(ctx))})`)
73
- .addImport('ApiClient', ctx.config.infrastructurePackageName));
72
+ .addImport('ApiClient', ctx.infrastructurePackageName));
74
73
  }
75
74
  generateApiClientMethod(ctx, builder, endpoint) {
76
75
  builder
@@ -102,9 +101,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
102
101
  .appendLine(' */');
103
102
  }
104
103
  generateApiClientMethodAnnotations(ctx, builder, endpoint) {
105
- const responseSchema = this.getResponseSchema(ctx, endpoint);
106
104
  builder
107
- .applyIf(responseSchema !== undefined, (builder) => builder.appendAnnotation('Supress', undefined, ['"UNCHECKED_CAST"']))
108
105
  .appendAnnotation('Throws', undefined, [
109
106
  'IllegalStateException::class',
110
107
  'IOException::class',
@@ -113,8 +110,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
113
110
  'ServerException::class',
114
111
  ])
115
112
  .addImport('IOException', 'java.io')
116
- .addImport('ClientException', ctx.config.infrastructurePackageName)
117
- .addImport('ServerException', ctx.config.infrastructurePackageName);
113
+ .addImport('ClientException', ctx.infrastructurePackageName)
114
+ .addImport('ServerException', ctx.infrastructurePackageName);
118
115
  }
119
116
  generateApiClientMethodSignature(ctx, builder, endpoint) {
120
117
  builder
@@ -133,7 +130,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
133
130
  generateApiClientMethodContent(ctx, builder, endpoint) {
134
131
  const responseSchema = this.getResponseSchema(ctx, endpoint);
135
132
  builder
136
- .append(`val localVarResponse = ${(0, core_1.toCasing)(endpoint.name, 'camel')}HttpInfo`)
133
+ .append(`val localVarResponse = ${(0, core_1.toCasing)(endpoint.name, 'camel')}WithHttpInfo`)
137
134
  .parenthesize('()', (builder) => this.generateParams(ctx, builder, endpoint, false))
138
135
  .appendLine()
139
136
  .appendLine()
@@ -142,13 +139,13 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
142
139
  .append('ResponseType.Success -> ')
143
140
  .applyIfElse(responseSchema === undefined, (builder) => builder.append('Unit'), (builder) => builder
144
141
  .append('(localVarResponse as Success<*>).data as ')
145
- .addImport('Success', ctx.config.infrastructurePackageName)
142
+ .addImport('Success', ctx.infrastructurePackageName)
146
143
  .apply((builder) => this.generateTypeUsage(ctx, builder, responseSchema)))
147
144
  .ensureCurrentLineEmpty()
148
145
  .appendLine(responseErrorHandlingCode)
149
- .addImport('ClientError', ctx.config.infrastructurePackageName)
150
- .addImport('ServerError', ctx.config.infrastructurePackageName)
151
- .addImport('ResponseType', ctx.config.infrastructurePackageName));
146
+ .addImport('ClientError', ctx.infrastructurePackageName)
147
+ .addImport('ServerError', ctx.infrastructurePackageName)
148
+ .addImport('ResponseType', ctx.infrastructurePackageName));
152
149
  }
153
150
  generateApiClientHttpInfoMethod(ctx, builder, endpoint) {
154
151
  builder
@@ -187,7 +184,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
187
184
  generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint) {
188
185
  builder
189
186
  .append('fun ')
190
- .append((0, core_1.toCasing)(endpoint.name, 'camel'), 'HttpInfo')
187
+ .append((0, core_1.toCasing)(endpoint.name, 'camel'), 'WithHttpInfo')
191
188
  .parenthesize('()', (builder) => this.generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint))
192
189
  .append(': ')
193
190
  .apply((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint));
@@ -198,8 +195,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
198
195
  generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint) {
199
196
  builder
200
197
  .append('ApiResponse')
201
- .addImport('ApiResponse', ctx.config.infrastructurePackageName)
202
- .parenthesize('<>', (builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit'));
198
+ .addImport('ApiResponse', ctx.infrastructurePackageName)
199
+ .parenthesize('<>', (builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit', true));
203
200
  }
204
201
  generateApiClientHttpInfoMethodContent(ctx, builder, endpoint) {
205
202
  builder
@@ -250,29 +247,34 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
250
247
  generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint) {
251
248
  builder
252
249
  .append('RequestConfig')
253
- .addImport('RequestConfig', ctx.config.infrastructurePackageName)
250
+ .addImport('RequestConfig', ctx.infrastructurePackageName)
254
251
  .parenthesize('<>', (builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); });
255
252
  }
256
253
  generateApiClientRequestConfigMethodContent(ctx, builder, endpoint) {
257
254
  var _a, _b;
255
+ const queryParameters = endpoint.parameters.filter((x) => x.target === 'query');
258
256
  builder
259
- .appendLine(`val localVariableBody = ${this.getRequestBodyParamName(ctx, endpoint)}`)
260
- .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf()')
261
- .addImport('MultiValueMap', ctx.config.infrastructurePackageName)
262
- .forEach(endpoint.parameters.filter((x) => x.target === 'query'), (builder, param) => builder.appendLine(`localVariableQuery["${param.name}"] = ${(0, core_1.toCasing)(param.name, 'camel')}`))
257
+ .appendLineIf(!!endpoint.requestBody, `val localVariableBody = ${(0, core_1.toCasing)(this.getRequestBodyParamName(ctx, endpoint), 'camel')}`)
258
+ .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf<String, List<String>>()')
259
+ .addImport('MultiValueMap', ctx.infrastructurePackageName)
260
+ .applyIf(queryParameters.length > 0, (builder) => builder.indent((builder) => builder.append('.apply ').parenthesizeMultiline('{}', (builder) => builder.forEach(queryParameters, (builder, param) => builder
261
+ .appendIf(!param.required, `if (${(0, core_1.toCasing)(param.name, 'camel')} != null) `)
262
+ .parenthesizeMultilineIf(!param.required, '{}', (builder) => builder.appendLine(`put(${this.toStringLiteral(ctx, (0, core_1.toCasing)(param.name, 'camel'))}, listOf(${(0, core_1.toCasing)(param.name, 'camel')}.toString()))`))
263
+ .appendLine()))))
264
+ .ensureCurrentLineEmpty()
263
265
  .appendLine('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()')
264
266
  .appendLineIf(((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) !== undefined, `localVariableHeaders["Content-Type"] = "${(_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0].type}"`)
265
267
  .appendLine()
266
268
  .append('return RequestConfig')
267
- .addImport('RequestConfig', ctx.config.infrastructurePackageName)
269
+ .addImport('RequestConfig', ctx.infrastructurePackageName)
268
270
  .parenthesizeMultiline('()', (builder) => builder
269
271
  .appendLine(`method = RequestMethod.${endpoint.method.toUpperCase()},`)
270
- .addImport('RequestMethod', ctx.config.infrastructurePackageName)
272
+ .addImport('RequestMethod', ctx.infrastructurePackageName)
271
273
  .appendLine(`path = "${this.getPathWithInterpolation(ctx, endpoint)}",`)
272
274
  .appendLine('query = localVariableQuery,')
273
275
  .appendLine('headers = localVariableHeaders,')
274
276
  .appendLine('requiresAuthentication = false,')
275
- .appendLine('body = localVariableBody'));
277
+ .appendLineIf(!!endpoint.requestBody, 'body = localVariableBody'));
276
278
  }
277
279
  generateAdditionalMethods(ctx, builder) {
278
280
  this.generateEncodeUriComponentMethod(ctx, builder);
@@ -294,21 +296,26 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
294
296
  .apply((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
295
297
  .appendIf(!parameter.required, '? = ', this.getDefaultValue(ctx, parameter.schema))));
296
298
  }
297
- generateTypeUsage(ctx, builder, schema, fallback) {
299
+ generateTypeUsage(ctx, builder, schema, fallback, nullable) {
298
300
  if (schema && schema.kind === 'array') {
299
301
  const schemaInfo = this.getSchemaInfo(ctx, schema.items);
300
- builder.append(`List<${schemaInfo.typeName}>`);
302
+ builder.append(this.getTypeNameWithNullability(`List<${schemaInfo.typeName}>`, nullable));
301
303
  builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
302
304
  }
303
305
  else if (schema || !fallback) {
304
306
  const schemaInfo = this.getSchemaInfo(ctx, schema);
305
- builder.append(schemaInfo.typeName);
307
+ builder.append(this.getTypeNameWithNullability(schemaInfo.typeName, nullable));
306
308
  builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
307
309
  }
308
310
  else {
309
- builder.append(fallback);
311
+ builder.append(this.getTypeNameWithNullability(fallback, nullable));
310
312
  }
311
313
  }
314
+ getTypeNameWithNullability(typeName, nullable) {
315
+ if (nullable === undefined)
316
+ return typeName;
317
+ return nullable ? `${typeName}?` : typeName.match(/^(.*?)\??$/)[1];
318
+ }
312
319
  getDefaultValue(ctx, schema) {
313
320
  if (!(schema === null || schema === void 0 ? void 0 : schema.default)) {
314
321
  return 'null';
@@ -324,7 +331,7 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
324
331
  }
325
332
  }
326
333
  getPathWithInterpolation(ctx, endpoint) {
327
- let path = endpoint.path;
334
+ let path = this.getEndpointPath(ctx, endpoint);
328
335
  endpoint.parameters
329
336
  .filter((x) => x.target === 'path')
330
337
  .forEach((parameter) => {
@@ -370,13 +377,13 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
370
377
  }
371
378
  getBasePath(ctx) {
372
379
  var _a, _b, _c, _d, _e, _f;
373
- return (_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/';
380
+ return (0, utils_1.modifyString)((_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/', ctx.config.basePath, ctx.service);
374
381
  }
375
- getFilePath(ctx, packageName) {
376
- return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
382
+ getEndpointPath(ctx, endpoint) {
383
+ return (0, utils_1.modifyString)(endpoint.path, ctx.config.pathModifier, endpoint);
377
384
  }
378
- getPackageName(ctx) {
379
- return ctx.config.packageName + ctx.config.packageSuffix;
385
+ getFilePath(ctx) {
386
+ return `${ctx.config.outputDir}/${ctx.packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
380
387
  }
381
388
  getApiClientName(ctx) {
382
389
  return (0, core_1.toCasing)(ctx.service.name, 'pascal') + 'ApiClient';
@@ -30,17 +30,37 @@ class KotlinOkHttp3ClientsGenerator extends core_1.OpenApiServicesGenerationProv
30
30
  }
31
31
  buildContext(context, config) {
32
32
  context.data.services = context.data.services.filter((x) => x.name !== 'exclude-from-generation');
33
- return this.getProviderContext(context, config, models_1.defaultKotlinOkHttp3ClientsGeneratorConfig);
33
+ const providerContext = this.getProviderContext(context, config, models_1.defaultKotlinOkHttp3ClientsGeneratorConfig);
34
+ return Object.assign(providerContext, {
35
+ packageName: this.getPackageName(providerContext.config),
36
+ infrastructurePackageName: this.getInfrastructurePackageName(providerContext.config),
37
+ });
38
+ }
39
+ getInfrastructurePackageName(config) {
40
+ console.log(config);
41
+ if (typeof config.infrastructurePackageName === 'string') {
42
+ return config.infrastructurePackageName;
43
+ }
44
+ if (config.infrastructurePackageName.mode === 'append-package-name') {
45
+ return config.packageName + config.infrastructurePackageName.value;
46
+ }
47
+ if (config.infrastructurePackageName.mode === 'append-full-package-name') {
48
+ return this.getPackageName(config) + config.infrastructurePackageName.value;
49
+ }
50
+ return config.infrastructurePackageName.value;
51
+ }
52
+ getPackageName(config) {
53
+ return config.packageName + config.packageSuffix;
34
54
  }
35
55
  copyInfrastructureFiles(ctx) {
36
56
  const sourceDir = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@goast/kotlin')), '../assets/client/okhttp3');
37
- const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.config.infrastructurePackageName.replace(/\./g, '/'));
57
+ const targetDir = (0, path_1.resolve)(ctx.config.outputDir, ctx.infrastructurePackageName.replace(/\./g, '/'));
38
58
  (0, fs_extra_1.ensureDirSync)(targetDir);
39
59
  const files = (0, fs_extra_1.readdirSync)(sourceDir);
40
60
  for (const file of files) {
41
61
  const fileContent = (0, fs_extra_1.readFileSync)((0, path_1.resolve)(sourceDir, file))
42
62
  .toString()
43
- .replace(/@PACKAGE_NAME@/g, ctx.config.infrastructurePackageName);
63
+ .replace(/@PACKAGE_NAME@/g, ctx.infrastructurePackageName);
44
64
  (0, fs_1.writeFileSync)((0, path_1.resolve)(targetDir, file), fileContent);
45
65
  }
46
66
  }
@@ -4,6 +4,7 @@ exports.DefaultKotlinSpringControllerGenerator = void 0;
4
4
  const fs_extra_1 = require("fs-extra");
5
5
  const core_1 = require("@goast/core");
6
6
  const file_builder_1 = require("../../../file-builder");
7
+ const utils_1 = require("../../../utils");
7
8
  const file_generator_1 = require("../../file-generator");
8
9
  class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFileGenerator {
9
10
  generate(ctx) {
@@ -88,7 +89,7 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
88
89
  ])
89
90
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
90
91
  ['method', '[RequestMethod.' + endpoint.method.toUpperCase() + ']'],
91
- ['value', '[' + this.toStringLiteral(ctx, endpoint.path) + ']'],
92
+ ['value', '[' + this.toStringLiteral(ctx, this.getEndpointPath(ctx, endpoint)) + ']'],
92
93
  [
93
94
  'consumes',
94
95
  '[' + ((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
@@ -330,11 +331,17 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
330
331
  }
331
332
  }
332
333
  getControllerRequestMapping(ctx, prefix) {
333
- var _a, _b, _c, _d, _e, _f;
334
- const basePath = (_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/';
334
+ const basePath = this.getBasePath(ctx);
335
335
  prefix !== null && prefix !== void 0 ? prefix : (prefix = `openapi.${(0, core_1.toCasing)(ctx.service.name, 'camel')}`);
336
336
  return this.toStringLiteral(ctx, `\${${prefix}.base-path:${basePath}}`);
337
337
  }
338
+ getBasePath(ctx) {
339
+ var _a, _b, _c, _d, _e, _f;
340
+ return (0, utils_1.modifyString)((_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/', ctx.config.basePath, ctx.service);
341
+ }
342
+ getEndpointPath(ctx, endpoint) {
343
+ return (0, utils_1.modifyString)(endpoint.path, ctx.config.pathModifier, endpoint);
344
+ }
338
345
  getDirectoryPath(ctx, packageName) {
339
346
  return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}`;
340
347
  }
package/cjs/lib/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toKotlinPropertyName = exports.toKotlinStringLiteral = void 0;
3
+ exports.modifyString = exports.toKotlinPropertyName = exports.toKotlinStringLiteral = void 0;
4
4
  function toKotlinStringLiteral(value) {
5
5
  if (!value) {
6
6
  return '""';
@@ -20,3 +20,18 @@ function toKotlinPropertyName(value) {
20
20
  return `\`${value}\``;
21
21
  }
22
22
  exports.toKotlinPropertyName = toKotlinPropertyName;
23
+ function modifyString(value, modifier, ...args) {
24
+ var _a;
25
+ if (typeof modifier === 'string') {
26
+ return modifier;
27
+ }
28
+ if (modifier instanceof RegExp) {
29
+ const match = value.match(modifier);
30
+ return (_a = match === null || match === void 0 ? void 0 : match[0]) !== null && _a !== void 0 ? _a : value;
31
+ }
32
+ if (typeof modifier === 'function') {
33
+ return modifier(value, ...args);
34
+ }
35
+ return value;
36
+ }
37
+ exports.modifyString = modifyString;
@@ -1,2 +1,2 @@
1
1
  import { defaultKotlinGeneratorConfig } from '../../../config';
2
- export const defaultKotlinOkHttp3ClientsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.client', infrastructurePackageName: 'com.openapi.client.infrastructure' });
2
+ export const defaultKotlinOkHttp3ClientsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api.client', infrastructurePackageName: { mode: 'append-full-package-name', value: '.infrastructure' } });
@@ -3,19 +3,18 @@ import { dirname } from 'path';
3
3
  import { ensureDirSync } from 'fs-extra';
4
4
  import { toCasing } from '@goast/core';
5
5
  import { KotlinFileBuilder } from '../../../file-builder';
6
- import { toKotlinStringLiteral } from '../../../utils';
6
+ import { modifyString, toKotlinStringLiteral } from '../../../utils';
7
7
  import { KotlinFileGenerator } from '../../file-generator';
8
8
  export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
9
9
  generate(ctx) {
10
- const packageName = this.getPackageName(ctx);
11
10
  const typeName = this.getApiClientName(ctx);
12
- const filePath = this.getFilePath(ctx, packageName);
11
+ const filePath = this.getFilePath(ctx);
13
12
  ensureDirSync(dirname(filePath));
14
13
  console.log(`Generating client for service ${ctx.service.name} to ${filePath}...`);
15
- const builder = new KotlinFileBuilder(packageName, ctx.config);
14
+ const builder = new KotlinFileBuilder(ctx.packageName, ctx.config);
16
15
  this.generateApiClientFileContent(ctx, builder);
17
16
  writeFileSync(filePath, builder.toString());
18
- return { typeName, packageName };
17
+ return { typeName, packageName: ctx.packageName };
19
18
  }
20
19
  generateApiClientFileContent(ctx, builder) {
21
20
  builder
@@ -36,7 +35,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
36
35
  .appendLine('basePath: String = defaultBasePath,')
37
36
  .appendLine('client: OkHttpClient = ApiClient.defaultClient')
38
37
  .addImport('OkHttpClient', 'okhttp3')
39
- .addImport('ApiClient', ctx.config.infrastructurePackageName))
38
+ .addImport('ApiClient', ctx.infrastructurePackageName))
40
39
  .append(' : ')
41
40
  .append('ApiClient(basePath, client)');
42
41
  }
@@ -67,7 +66,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
67
66
  .append('val defaultBasePath: String by lazy ')
68
67
  .parenthesizeMultiline('{}', (builder) => builder
69
68
  .appendLine(`System.getProperties().getProperty(ApiClient.baseUrlKey, ${this.toStringLiteral(ctx, this.getBasePath(ctx))})`)
70
- .addImport('ApiClient', ctx.config.infrastructurePackageName));
69
+ .addImport('ApiClient', ctx.infrastructurePackageName));
71
70
  }
72
71
  generateApiClientMethod(ctx, builder, endpoint) {
73
72
  builder
@@ -99,9 +98,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
99
98
  .appendLine(' */');
100
99
  }
101
100
  generateApiClientMethodAnnotations(ctx, builder, endpoint) {
102
- const responseSchema = this.getResponseSchema(ctx, endpoint);
103
101
  builder
104
- .applyIf(responseSchema !== undefined, (builder) => builder.appendAnnotation('Supress', undefined, ['"UNCHECKED_CAST"']))
105
102
  .appendAnnotation('Throws', undefined, [
106
103
  'IllegalStateException::class',
107
104
  'IOException::class',
@@ -110,8 +107,8 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
110
107
  'ServerException::class',
111
108
  ])
112
109
  .addImport('IOException', 'java.io')
113
- .addImport('ClientException', ctx.config.infrastructurePackageName)
114
- .addImport('ServerException', ctx.config.infrastructurePackageName);
110
+ .addImport('ClientException', ctx.infrastructurePackageName)
111
+ .addImport('ServerException', ctx.infrastructurePackageName);
115
112
  }
116
113
  generateApiClientMethodSignature(ctx, builder, endpoint) {
117
114
  builder
@@ -130,7 +127,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
130
127
  generateApiClientMethodContent(ctx, builder, endpoint) {
131
128
  const responseSchema = this.getResponseSchema(ctx, endpoint);
132
129
  builder
133
- .append(`val localVarResponse = ${toCasing(endpoint.name, 'camel')}HttpInfo`)
130
+ .append(`val localVarResponse = ${toCasing(endpoint.name, 'camel')}WithHttpInfo`)
134
131
  .parenthesize('()', (builder) => this.generateParams(ctx, builder, endpoint, false))
135
132
  .appendLine()
136
133
  .appendLine()
@@ -139,13 +136,13 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
139
136
  .append('ResponseType.Success -> ')
140
137
  .applyIfElse(responseSchema === undefined, (builder) => builder.append('Unit'), (builder) => builder
141
138
  .append('(localVarResponse as Success<*>).data as ')
142
- .addImport('Success', ctx.config.infrastructurePackageName)
139
+ .addImport('Success', ctx.infrastructurePackageName)
143
140
  .apply((builder) => this.generateTypeUsage(ctx, builder, responseSchema)))
144
141
  .ensureCurrentLineEmpty()
145
142
  .appendLine(responseErrorHandlingCode)
146
- .addImport('ClientError', ctx.config.infrastructurePackageName)
147
- .addImport('ServerError', ctx.config.infrastructurePackageName)
148
- .addImport('ResponseType', ctx.config.infrastructurePackageName));
143
+ .addImport('ClientError', ctx.infrastructurePackageName)
144
+ .addImport('ServerError', ctx.infrastructurePackageName)
145
+ .addImport('ResponseType', ctx.infrastructurePackageName));
149
146
  }
150
147
  generateApiClientHttpInfoMethod(ctx, builder, endpoint) {
151
148
  builder
@@ -184,7 +181,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
184
181
  generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint) {
185
182
  builder
186
183
  .append('fun ')
187
- .append(toCasing(endpoint.name, 'camel'), 'HttpInfo')
184
+ .append(toCasing(endpoint.name, 'camel'), 'WithHttpInfo')
188
185
  .parenthesize('()', (builder) => this.generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint))
189
186
  .append(': ')
190
187
  .apply((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint));
@@ -195,8 +192,8 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
195
192
  generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint) {
196
193
  builder
197
194
  .append('ApiResponse')
198
- .addImport('ApiResponse', ctx.config.infrastructurePackageName)
199
- .parenthesize('<>', (builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit'));
195
+ .addImport('ApiResponse', ctx.infrastructurePackageName)
196
+ .parenthesize('<>', (builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit', true));
200
197
  }
201
198
  generateApiClientHttpInfoMethodContent(ctx, builder, endpoint) {
202
199
  builder
@@ -247,29 +244,34 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
247
244
  generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint) {
248
245
  builder
249
246
  .append('RequestConfig')
250
- .addImport('RequestConfig', ctx.config.infrastructurePackageName)
247
+ .addImport('RequestConfig', ctx.infrastructurePackageName)
251
248
  .parenthesize('<>', (builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); });
252
249
  }
253
250
  generateApiClientRequestConfigMethodContent(ctx, builder, endpoint) {
254
251
  var _a, _b;
252
+ const queryParameters = endpoint.parameters.filter((x) => x.target === 'query');
255
253
  builder
256
- .appendLine(`val localVariableBody = ${this.getRequestBodyParamName(ctx, endpoint)}`)
257
- .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf()')
258
- .addImport('MultiValueMap', ctx.config.infrastructurePackageName)
259
- .forEach(endpoint.parameters.filter((x) => x.target === 'query'), (builder, param) => builder.appendLine(`localVariableQuery["${param.name}"] = ${toCasing(param.name, 'camel')}`))
254
+ .appendLineIf(!!endpoint.requestBody, `val localVariableBody = ${toCasing(this.getRequestBodyParamName(ctx, endpoint), 'camel')}`)
255
+ .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf<String, List<String>>()')
256
+ .addImport('MultiValueMap', ctx.infrastructurePackageName)
257
+ .applyIf(queryParameters.length > 0, (builder) => builder.indent((builder) => builder.append('.apply ').parenthesizeMultiline('{}', (builder) => builder.forEach(queryParameters, (builder, param) => builder
258
+ .appendIf(!param.required, `if (${toCasing(param.name, 'camel')} != null) `)
259
+ .parenthesizeMultilineIf(!param.required, '{}', (builder) => builder.appendLine(`put(${this.toStringLiteral(ctx, toCasing(param.name, 'camel'))}, listOf(${toCasing(param.name, 'camel')}.toString()))`))
260
+ .appendLine()))))
261
+ .ensureCurrentLineEmpty()
260
262
  .appendLine('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()')
261
263
  .appendLineIf(((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) !== undefined, `localVariableHeaders["Content-Type"] = "${(_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0].type}"`)
262
264
  .appendLine()
263
265
  .append('return RequestConfig')
264
- .addImport('RequestConfig', ctx.config.infrastructurePackageName)
266
+ .addImport('RequestConfig', ctx.infrastructurePackageName)
265
267
  .parenthesizeMultiline('()', (builder) => builder
266
268
  .appendLine(`method = RequestMethod.${endpoint.method.toUpperCase()},`)
267
- .addImport('RequestMethod', ctx.config.infrastructurePackageName)
269
+ .addImport('RequestMethod', ctx.infrastructurePackageName)
268
270
  .appendLine(`path = "${this.getPathWithInterpolation(ctx, endpoint)}",`)
269
271
  .appendLine('query = localVariableQuery,')
270
272
  .appendLine('headers = localVariableHeaders,')
271
273
  .appendLine('requiresAuthentication = false,')
272
- .appendLine('body = localVariableBody'));
274
+ .appendLineIf(!!endpoint.requestBody, 'body = localVariableBody'));
273
275
  }
274
276
  generateAdditionalMethods(ctx, builder) {
275
277
  this.generateEncodeUriComponentMethod(ctx, builder);
@@ -291,21 +293,26 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
291
293
  .apply((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
292
294
  .appendIf(!parameter.required, '? = ', this.getDefaultValue(ctx, parameter.schema))));
293
295
  }
294
- generateTypeUsage(ctx, builder, schema, fallback) {
296
+ generateTypeUsage(ctx, builder, schema, fallback, nullable) {
295
297
  if (schema && schema.kind === 'array') {
296
298
  const schemaInfo = this.getSchemaInfo(ctx, schema.items);
297
- builder.append(`List<${schemaInfo.typeName}>`);
299
+ builder.append(this.getTypeNameWithNullability(`List<${schemaInfo.typeName}>`, nullable));
298
300
  builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
299
301
  }
300
302
  else if (schema || !fallback) {
301
303
  const schemaInfo = this.getSchemaInfo(ctx, schema);
302
- builder.append(schemaInfo.typeName);
304
+ builder.append(this.getTypeNameWithNullability(schemaInfo.typeName, nullable));
303
305
  builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
304
306
  }
305
307
  else {
306
- builder.append(fallback);
308
+ builder.append(this.getTypeNameWithNullability(fallback, nullable));
307
309
  }
308
310
  }
311
+ getTypeNameWithNullability(typeName, nullable) {
312
+ if (nullable === undefined)
313
+ return typeName;
314
+ return nullable ? `${typeName}?` : typeName.match(/^(.*?)\??$/)[1];
315
+ }
309
316
  getDefaultValue(ctx, schema) {
310
317
  if (!(schema === null || schema === void 0 ? void 0 : schema.default)) {
311
318
  return 'null';
@@ -321,7 +328,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
321
328
  }
322
329
  }
323
330
  getPathWithInterpolation(ctx, endpoint) {
324
- let path = endpoint.path;
331
+ let path = this.getEndpointPath(ctx, endpoint);
325
332
  endpoint.parameters
326
333
  .filter((x) => x.target === 'path')
327
334
  .forEach((parameter) => {
@@ -367,13 +374,13 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
367
374
  }
368
375
  getBasePath(ctx) {
369
376
  var _a, _b, _c, _d, _e, _f;
370
- return (_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/';
377
+ return modifyString((_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/', ctx.config.basePath, ctx.service);
371
378
  }
372
- getFilePath(ctx, packageName) {
373
- return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
379
+ getEndpointPath(ctx, endpoint) {
380
+ return modifyString(endpoint.path, ctx.config.pathModifier, endpoint);
374
381
  }
375
- getPackageName(ctx) {
376
- return ctx.config.packageName + ctx.config.packageSuffix;
382
+ getFilePath(ctx) {
383
+ return `${ctx.config.outputDir}/${ctx.packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
377
384
  }
378
385
  getApiClientName(ctx) {
379
386
  return toCasing(ctx.service.name, 'pascal') + 'ApiClient';
@@ -27,17 +27,37 @@ export class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProv
27
27
  }
28
28
  buildContext(context, config) {
29
29
  context.data.services = context.data.services.filter((x) => x.name !== 'exclude-from-generation');
30
- return this.getProviderContext(context, config, defaultKotlinOkHttp3ClientsGeneratorConfig);
30
+ const providerContext = this.getProviderContext(context, config, defaultKotlinOkHttp3ClientsGeneratorConfig);
31
+ return Object.assign(providerContext, {
32
+ packageName: this.getPackageName(providerContext.config),
33
+ infrastructurePackageName: this.getInfrastructurePackageName(providerContext.config),
34
+ });
35
+ }
36
+ getInfrastructurePackageName(config) {
37
+ console.log(config);
38
+ if (typeof config.infrastructurePackageName === 'string') {
39
+ return config.infrastructurePackageName;
40
+ }
41
+ if (config.infrastructurePackageName.mode === 'append-package-name') {
42
+ return config.packageName + config.infrastructurePackageName.value;
43
+ }
44
+ if (config.infrastructurePackageName.mode === 'append-full-package-name') {
45
+ return this.getPackageName(config) + config.infrastructurePackageName.value;
46
+ }
47
+ return config.infrastructurePackageName.value;
48
+ }
49
+ getPackageName(config) {
50
+ return config.packageName + config.packageSuffix;
31
51
  }
32
52
  copyInfrastructureFiles(ctx) {
33
53
  const sourceDir = resolve(dirname(require.resolve('@goast/kotlin')), '../assets/client/okhttp3');
34
- const targetDir = resolve(ctx.config.outputDir, ctx.config.infrastructurePackageName.replace(/\./g, '/'));
54
+ const targetDir = resolve(ctx.config.outputDir, ctx.infrastructurePackageName.replace(/\./g, '/'));
35
55
  ensureDirSync(targetDir);
36
56
  const files = readdirSync(sourceDir);
37
57
  for (const file of files) {
38
58
  const fileContent = readFileSync(resolve(sourceDir, file))
39
59
  .toString()
40
- .replace(/@PACKAGE_NAME@/g, ctx.config.infrastructurePackageName);
60
+ .replace(/@PACKAGE_NAME@/g, ctx.infrastructurePackageName);
41
61
  writeFileSync(resolve(targetDir, file), fileContent);
42
62
  }
43
63
  }
@@ -1,6 +1,7 @@
1
1
  import { ensureDirSync, writeFileSync } from 'fs-extra';
2
2
  import { toCasing } from '@goast/core';
3
3
  import { KotlinFileBuilder } from '../../../file-builder';
4
+ import { modifyString } from '../../../utils';
4
5
  import { KotlinFileGenerator } from '../../file-generator';
5
6
  export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator {
6
7
  generate(ctx) {
@@ -85,7 +86,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
85
86
  ])
86
87
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
87
88
  ['method', '[RequestMethod.' + endpoint.method.toUpperCase() + ']'],
88
- ['value', '[' + this.toStringLiteral(ctx, endpoint.path) + ']'],
89
+ ['value', '[' + this.toStringLiteral(ctx, this.getEndpointPath(ctx, endpoint)) + ']'],
89
90
  [
90
91
  'consumes',
91
92
  '[' + ((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
@@ -327,11 +328,17 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
327
328
  }
328
329
  }
329
330
  getControllerRequestMapping(ctx, prefix) {
330
- var _a, _b, _c, _d, _e, _f;
331
- const basePath = (_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/';
331
+ const basePath = this.getBasePath(ctx);
332
332
  prefix !== null && prefix !== void 0 ? prefix : (prefix = `openapi.${toCasing(ctx.service.name, 'camel')}`);
333
333
  return this.toStringLiteral(ctx, `\${${prefix}.base-path:${basePath}}`);
334
334
  }
335
+ getBasePath(ctx) {
336
+ var _a, _b, _c, _d, _e, _f;
337
+ return modifyString((_f = (_e = (_d = (_c = ((_a = ctx.service.$src) !== null && _a !== void 0 ? _a : (_b = ctx.service.endpoints[0]) === null || _b === void 0 ? void 0 : _b.$src)) === null || _c === void 0 ? void 0 : _c.document.servers) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '/', ctx.config.basePath, ctx.service);
338
+ }
339
+ getEndpointPath(ctx, endpoint) {
340
+ return modifyString(endpoint.path, ctx.config.pathModifier, endpoint);
341
+ }
335
342
  getDirectoryPath(ctx, packageName) {
336
343
  return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}`;
337
344
  }
package/esm/lib/utils.js CHANGED
@@ -15,3 +15,17 @@ export function toKotlinPropertyName(value) {
15
15
  }
16
16
  return `\`${value}\``;
17
17
  }
18
+ export function modifyString(value, modifier, ...args) {
19
+ var _a;
20
+ if (typeof modifier === 'string') {
21
+ return modifier;
22
+ }
23
+ if (modifier instanceof RegExp) {
24
+ const match = value.match(modifier);
25
+ return (_a = match === null || match === void 0 ? void 0 : match[0]) !== null && _a !== void 0 ? _a : value;
26
+ }
27
+ if (typeof modifier === 'function') {
28
+ return modifier(value, ...args);
29
+ }
30
+ return value;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/kotlin",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -1,11 +1,16 @@
1
- import { ApiService, DefaultGenerationProviderConfig, OpenApiServicesGenerationProviderContext } from '@goast/core';
1
+ import { ApiEndpoint, ApiService, DefaultGenerationProviderConfig, OpenApiServicesGenerationProviderContext } from '@goast/core';
2
2
  import { KotlinImport } from '../../../common-results';
3
3
  import { KotlinGeneratorConfig } from '../../../config';
4
4
  import { KotlinModelsGeneratorOutput } from '../../models';
5
5
  export type KotlinOkHttp3ClientsGeneratorConfig = KotlinGeneratorConfig & {
6
6
  packageName: string;
7
7
  packageSuffix: string;
8
- infrastructurePackageName: string;
8
+ infrastructurePackageName: string | {
9
+ mode: 'append-package-name' | 'append-full-package-name' | 'replace';
10
+ value: string;
11
+ };
12
+ basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
13
+ pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
9
14
  };
10
15
  export declare const defaultKotlinOkHttp3ClientsGeneratorConfig: DefaultGenerationProviderConfig<KotlinOkHttp3ClientsGeneratorConfig>;
11
16
  export type KotlinOkHttp3ClientsGeneratorInput = KotlinModelsGeneratorOutput;
@@ -15,7 +20,10 @@ export type KotlinOkHttp3ClientsGeneratorOutput = {
15
20
  };
16
21
  };
17
22
  export type KotlinOkHttp3ClientGeneratorOutput = KotlinImport;
18
- export type KotlinOkHttp3ClientsGeneratorContext = OpenApiServicesGenerationProviderContext<KotlinOkHttp3ClientsGeneratorInput, KotlinOkHttp3ClientsGeneratorOutput, KotlinOkHttp3ClientsGeneratorConfig, KotlinOkHttp3ClientGeneratorOutput>;
23
+ export type KotlinOkHttp3ClientsGeneratorContext = OpenApiServicesGenerationProviderContext<KotlinOkHttp3ClientsGeneratorInput, KotlinOkHttp3ClientsGeneratorOutput, KotlinOkHttp3ClientsGeneratorConfig, KotlinOkHttp3ClientGeneratorOutput> & {
24
+ packageName: string;
25
+ infrastructurePackageName: string;
26
+ };
19
27
  export type KotlinOkHttp3ClientGeneratorContext = KotlinOkHttp3ClientsGeneratorContext & {
20
28
  service: ApiService;
21
29
  };
@@ -44,7 +44,8 @@ export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<C
44
44
  protected generateEncodeUriComponentMethod(ctx: Context, builder: Builder): void;
45
45
  protected generateParamDocEntries(ctx: Context, builder: Builder, endpoint: ApiEndpoint): void;
46
46
  protected generateParams(ctx: Context, builder: Builder, endpoint: ApiEndpoint, includeTypeDefinition: boolean): void;
47
- protected generateTypeUsage(ctx: Context, builder: Builder, schema: ApiSchema | undefined, fallback?: string): void;
47
+ protected generateTypeUsage(ctx: Context, builder: Builder, schema: ApiSchema | undefined, fallback?: string, nullable?: boolean): void;
48
+ protected getTypeNameWithNullability(typeName: string, nullable: boolean | undefined): string;
48
49
  protected getDefaultValue(ctx: Context, schema: ApiSchema | undefined): string;
49
50
  protected getPathWithInterpolation(ctx: Context, endpoint: ApiEndpoint): string;
50
51
  protected getResponseSchema(ctx: Context, endpoint: ApiEndpoint): ApiSchema | undefined;
@@ -52,8 +53,8 @@ export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<C
52
53
  protected getAllParameters(ctx: Context, endpoint: ApiEndpoint): ApiParameter[];
53
54
  protected getRequestBodyParamName(ctx: Context, endpoint: ApiEndpoint): string;
54
55
  protected getBasePath(ctx: Context): string;
55
- protected getFilePath(ctx: Context, packageName: string): string;
56
- protected getPackageName(ctx: Context): string;
56
+ protected getEndpointPath(ctx: Context, endpoint: ApiEndpoint): string;
57
+ protected getFilePath(ctx: Context): string;
57
58
  protected getApiClientName(ctx: Context): string;
58
59
  }
59
60
  export {};
@@ -15,6 +15,8 @@ export declare class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenera
15
15
  protected generateService(ctx: Context, service: ApiService): ServiceOutput;
16
16
  protected addServiceResult(ctx: Context, service: ApiService, result: ServiceOutput): void;
17
17
  protected buildContext(context: OpenApiGeneratorContext<KotlinServicesGeneratorInput>, config?: Partial<Config> | undefined): Context;
18
+ protected getInfrastructurePackageName(config: Config): string;
19
+ protected getPackageName(config: Config): string;
18
20
  private copyInfrastructureFiles;
19
21
  }
20
22
  export {};
@@ -1,10 +1,12 @@
1
- import { OpenApiServicesGenerationProviderContext, ApiService, DefaultGenerationProviderConfig } from '@goast/core';
1
+ import { OpenApiServicesGenerationProviderContext, ApiService, DefaultGenerationProviderConfig, ApiEndpoint } from '@goast/core';
2
2
  import { KotlinImport } from '../../../common-results';
3
3
  import { KotlinGeneratorConfig } from '../../../config';
4
4
  import { KotlinModelsGeneratorOutput } from '../../models';
5
5
  export type KotlinServicesGeneratorConfig = KotlinGeneratorConfig & {
6
6
  packageName: string;
7
7
  packageSuffix: string;
8
+ basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
9
+ pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
8
10
  };
9
11
  export declare const defaultKotlinServicesGeneratorConfig: DefaultGenerationProviderConfig<KotlinServicesGeneratorConfig>;
10
12
  export type KotlinServicesGeneratorInput = KotlinModelsGeneratorOutput;
@@ -51,6 +51,8 @@ export declare class DefaultKotlinSpringControllerGenerator extends KotlinFileGe
51
51
  protected generateResponseEntityType(ctx: Context, builder: Builder, schema: ApiSchema | undefined): void;
52
52
  protected generateTypeUsage(ctx: Context, builder: Builder, schema: ApiSchema | undefined, fallback?: string): void;
53
53
  protected getControllerRequestMapping(ctx: Context, prefix?: string): string;
54
+ protected getBasePath(ctx: Context): string;
55
+ protected getEndpointPath(ctx: Context, endpoint: ApiEndpoint): string;
54
56
  protected getDirectoryPath(ctx: Context, packageName: string): string;
55
57
  protected getPackageName(ctx: Context): string;
56
58
  protected getApiInterfaceName(ctx: Context): string;
@@ -1,3 +1,4 @@
1
1
  import { Nullable } from '@goast/core';
2
2
  export declare function toKotlinStringLiteral(value: Nullable<string>): string;
3
3
  export declare function toKotlinPropertyName(value: string): string;
4
+ export declare function modifyString<TArgs extends any[]>(value: string, modifier: string | RegExp | ((value: string, ...args: TArgs) => string) | undefined, ...args: TArgs): string;