@goast/kotlin 0.1.11 → 0.1.13
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/lib/generators/models/model-generator.js +15 -12
- package/cjs/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +10 -5
- package/cjs/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +2 -2
- package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +2 -1
- package/esm/lib/generators/models/model-generator.js +15 -12
- package/esm/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +10 -5
- package/esm/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +2 -2
- package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +2 -1
- package/package.json +1 -1
- package/types/lib/generators/models/model-generator.d.ts +2 -4
- package/types/lib/generators/models/models.d.ts +1 -1
- package/types/lib/generators/services/okhttp3-clients/models.d.ts +1 -2
- package/types/lib/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +3 -2
- package/types/lib/generators/services/spring-controllers/models.d.ts +1 -1
|
@@ -32,7 +32,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
32
32
|
}
|
|
33
33
|
if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
|
|
34
34
|
const typeName = this.getDeclarationTypeName(ctx, ctx.schema);
|
|
35
|
-
const packageName = ctx
|
|
35
|
+
const packageName = this.getPackageName(ctx, ctx.schema);
|
|
36
36
|
const filePath = `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${typeName}.kt`;
|
|
37
37
|
console.log(`Generating model ${packageName}.${typeName} to ${filePath}...`);
|
|
38
38
|
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(filePath));
|
|
@@ -65,7 +65,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
65
65
|
schema = (0, core_1.getSchemaReference)(schema, ['description']);
|
|
66
66
|
if (this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
67
67
|
const name = this.getDeclarationTypeName(ctx, schema);
|
|
68
|
-
const packageName = ctx
|
|
68
|
+
const packageName = this.getPackageName(ctx, schema);
|
|
69
69
|
if (packageName) {
|
|
70
70
|
builder.addImport(name, packageName);
|
|
71
71
|
}
|
|
@@ -144,7 +144,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
144
144
|
}
|
|
145
145
|
generateObjectDataClass(ctx, builder, schema) {
|
|
146
146
|
const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
|
|
147
|
-
const
|
|
147
|
+
const params = this.getClassProperties(ctx, schema);
|
|
148
148
|
builder
|
|
149
149
|
.append((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
150
150
|
.append(params.length === 0 ? 'class' : 'data class', ' ')
|
|
@@ -156,8 +156,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
156
156
|
separator: ', ',
|
|
157
157
|
}))
|
|
158
158
|
.append(' ')
|
|
159
|
-
.parenthesizeIf(
|
|
160
|
-
.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
|
|
159
|
+
.parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
|
|
161
160
|
.if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
|
|
162
161
|
.append('val additionalProperties: Mutable')
|
|
163
162
|
.append((builder) => this.generateMapType(ctx, builder, schema))
|
|
@@ -174,8 +173,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
174
173
|
.append('fun getMap(): ')
|
|
175
174
|
.append((builder) => this.generateMapType(ctx, builder, schema))
|
|
176
175
|
.append(' ')
|
|
177
|
-
.parenthesize('{}', 'return this.additionalProperties', { multiline: true }))
|
|
178
|
-
.forEach(properties, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true });
|
|
176
|
+
.parenthesize('{}', 'return this.additionalProperties', { multiline: true })), { multiline: true });
|
|
179
177
|
}
|
|
180
178
|
generateDefaultValue(ctx, builder, schema) {
|
|
181
179
|
if (schema.default === null || schema.default === undefined) {
|
|
@@ -382,6 +380,10 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
382
380
|
.appendLine(' */');
|
|
383
381
|
}
|
|
384
382
|
}
|
|
383
|
+
getPackageName(ctx, schema) {
|
|
384
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(schema);
|
|
385
|
+
return ctx.config.packageName + packageSuffix;
|
|
386
|
+
}
|
|
385
387
|
shouldGenerateTypeDeclaration(ctx, schema) {
|
|
386
388
|
// All enum types should have its own type declaration
|
|
387
389
|
if (schema.enum !== undefined && schema.enum.length > 0) {
|
|
@@ -419,10 +421,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
419
421
|
.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
|
|
420
422
|
.filter((item, index, self) => self.indexOf(item) === index);
|
|
421
423
|
}
|
|
422
|
-
|
|
424
|
+
getClassProperties(ctx, schema) {
|
|
423
425
|
var _a;
|
|
424
426
|
const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
|
|
425
|
-
const
|
|
427
|
+
const properties = [];
|
|
428
|
+
const appendedProperties = [];
|
|
426
429
|
for (const property of schema.properties.values()) {
|
|
427
430
|
const discriminator = (_a = inheritedSchemas.find((x) => { var _a; return ((_a = x.discriminator) === null || _a === void 0 ? void 0 : _a.propertyName) === property.name; })) === null || _a === void 0 ? void 0 : _a.discriminator;
|
|
428
431
|
if (discriminator) {
|
|
@@ -432,13 +435,13 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
432
435
|
const s = (0, core_1.createOverwriteProxy)(p.schema);
|
|
433
436
|
p.schema = s;
|
|
434
437
|
s.default = schemaMappings[0][0];
|
|
435
|
-
|
|
438
|
+
appendedProperties.push(p);
|
|
436
439
|
continue;
|
|
437
440
|
}
|
|
438
441
|
}
|
|
439
|
-
|
|
442
|
+
properties.push(property);
|
|
440
443
|
}
|
|
441
|
-
return
|
|
444
|
+
return [...this.sortProperties(ctx, schema, properties), ...appendedProperties];
|
|
442
445
|
}
|
|
443
446
|
sortProperties(ctx, schema, properties) {
|
|
444
447
|
return [...properties].sort((a, b) => classify(a) - classify(b));
|
|
@@ -11,13 +11,14 @@ const file_generator_1 = require("../../file-generator");
|
|
|
11
11
|
class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator {
|
|
12
12
|
generate(ctx) {
|
|
13
13
|
const typeName = this.getApiClientName(ctx);
|
|
14
|
-
const
|
|
14
|
+
const packageName = this.getPackageName(ctx, ctx.service);
|
|
15
|
+
const filePath = this.getFilePath(ctx, packageName);
|
|
15
16
|
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(filePath));
|
|
16
17
|
console.log(`Generating client for service ${ctx.service.name} to ${filePath}...`);
|
|
17
|
-
const builder = new file_builder_1.KotlinFileBuilder(
|
|
18
|
+
const builder = new file_builder_1.KotlinFileBuilder(packageName, ctx.config);
|
|
18
19
|
this.generateApiClientFileContent(ctx, builder);
|
|
19
20
|
(0, fs_1.writeFileSync)(filePath, builder.toString());
|
|
20
|
-
return { typeName, packageName
|
|
21
|
+
return { typeName, packageName };
|
|
21
22
|
}
|
|
22
23
|
generateApiClientFileContent(ctx, builder) {
|
|
23
24
|
builder
|
|
@@ -317,6 +318,10 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
317
318
|
builder.append(this.getTypeNameWithNullability(fallback, nullable));
|
|
318
319
|
}
|
|
319
320
|
}
|
|
321
|
+
getPackageName(ctx, service) {
|
|
322
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(service);
|
|
323
|
+
return ctx.config.packageName + packageSuffix;
|
|
324
|
+
}
|
|
320
325
|
getTypeNameWithNullability(typeName, nullable) {
|
|
321
326
|
if (nullable === undefined)
|
|
322
327
|
return typeName;
|
|
@@ -388,8 +393,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_1.KotlinFileGenerator
|
|
|
388
393
|
getEndpointPath(ctx, endpoint) {
|
|
389
394
|
return (0, utils_1.modifyString)(endpoint.path, ctx.config.pathModifier, endpoint);
|
|
390
395
|
}
|
|
391
|
-
getFilePath(ctx) {
|
|
392
|
-
return `${ctx.config.outputDir}/${
|
|
396
|
+
getFilePath(ctx, packageName) {
|
|
397
|
+
return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
|
|
393
398
|
}
|
|
394
399
|
getApiClientName(ctx) {
|
|
395
400
|
return (0, core_1.toCasing)(ctx.service.name, 'pascal') + 'ApiClient';
|
|
@@ -32,7 +32,6 @@ class KotlinOkHttp3ClientsGenerator extends core_1.OpenApiServicesGenerationProv
|
|
|
32
32
|
context.data.services = context.data.services.filter((x) => x.name !== 'exclude-from-generation');
|
|
33
33
|
const providerContext = this.getProviderContext(context, config, models_1.defaultKotlinOkHttp3ClientsGeneratorConfig);
|
|
34
34
|
return Object.assign(providerContext, {
|
|
35
|
-
packageName: this.getPackageName(providerContext.config),
|
|
36
35
|
infrastructurePackageName: this.getInfrastructurePackageName(providerContext.config),
|
|
37
36
|
});
|
|
38
37
|
}
|
|
@@ -49,7 +48,8 @@ class KotlinOkHttp3ClientsGenerator extends core_1.OpenApiServicesGenerationProv
|
|
|
49
48
|
return config.infrastructurePackageName.value;
|
|
50
49
|
}
|
|
51
50
|
getPackageName(config) {
|
|
52
|
-
|
|
51
|
+
const packageSuffix = typeof config.packageSuffix === 'string' ? config.packageSuffix : config.packageSuffix();
|
|
52
|
+
return config.packageName + packageSuffix;
|
|
53
53
|
}
|
|
54
54
|
copyInfrastructureFiles(ctx) {
|
|
55
55
|
const sourceDir = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@goast/kotlin')), '../assets/client/okhttp3');
|
|
@@ -367,7 +367,8 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
367
367
|
return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}`;
|
|
368
368
|
}
|
|
369
369
|
getPackageName(ctx) {
|
|
370
|
-
|
|
370
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(ctx.service);
|
|
371
|
+
return ctx.config.packageName + packageSuffix;
|
|
371
372
|
}
|
|
372
373
|
getApiInterfaceName(ctx) {
|
|
373
374
|
return (0, core_1.toCasing)(ctx.service.name, 'pascal') + 'Api';
|
|
@@ -29,7 +29,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
29
29
|
}
|
|
30
30
|
if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
|
|
31
31
|
const typeName = this.getDeclarationTypeName(ctx, ctx.schema);
|
|
32
|
-
const packageName = ctx
|
|
32
|
+
const packageName = this.getPackageName(ctx, ctx.schema);
|
|
33
33
|
const filePath = `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${typeName}.kt`;
|
|
34
34
|
console.log(`Generating model ${packageName}.${typeName} to ${filePath}...`);
|
|
35
35
|
ensureDirSync(dirname(filePath));
|
|
@@ -62,7 +62,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
62
62
|
schema = getSchemaReference(schema, ['description']);
|
|
63
63
|
if (this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
64
64
|
const name = this.getDeclarationTypeName(ctx, schema);
|
|
65
|
-
const packageName = ctx
|
|
65
|
+
const packageName = this.getPackageName(ctx, schema);
|
|
66
66
|
if (packageName) {
|
|
67
67
|
builder.addImport(name, packageName);
|
|
68
68
|
}
|
|
@@ -141,7 +141,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
141
141
|
}
|
|
142
142
|
generateObjectDataClass(ctx, builder, schema) {
|
|
143
143
|
const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
|
|
144
|
-
const
|
|
144
|
+
const params = this.getClassProperties(ctx, schema);
|
|
145
145
|
builder
|
|
146
146
|
.append((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
147
147
|
.append(params.length === 0 ? 'class' : 'data class', ' ')
|
|
@@ -153,8 +153,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
153
153
|
separator: ', ',
|
|
154
154
|
}))
|
|
155
155
|
.append(' ')
|
|
156
|
-
.parenthesizeIf(
|
|
157
|
-
.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
|
|
156
|
+
.parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
|
|
158
157
|
.if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
|
|
159
158
|
.append('val additionalProperties: Mutable')
|
|
160
159
|
.append((builder) => this.generateMapType(ctx, builder, schema))
|
|
@@ -171,8 +170,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
171
170
|
.append('fun getMap(): ')
|
|
172
171
|
.append((builder) => this.generateMapType(ctx, builder, schema))
|
|
173
172
|
.append(' ')
|
|
174
|
-
.parenthesize('{}', 'return this.additionalProperties', { multiline: true }))
|
|
175
|
-
.forEach(properties, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true });
|
|
173
|
+
.parenthesize('{}', 'return this.additionalProperties', { multiline: true })), { multiline: true });
|
|
176
174
|
}
|
|
177
175
|
generateDefaultValue(ctx, builder, schema) {
|
|
178
176
|
if (schema.default === null || schema.default === undefined) {
|
|
@@ -379,6 +377,10 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
379
377
|
.appendLine(' */');
|
|
380
378
|
}
|
|
381
379
|
}
|
|
380
|
+
getPackageName(ctx, schema) {
|
|
381
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(schema);
|
|
382
|
+
return ctx.config.packageName + packageSuffix;
|
|
383
|
+
}
|
|
382
384
|
shouldGenerateTypeDeclaration(ctx, schema) {
|
|
383
385
|
// All enum types should have its own type declaration
|
|
384
386
|
if (schema.enum !== undefined && schema.enum.length > 0) {
|
|
@@ -416,10 +418,11 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
416
418
|
.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
|
|
417
419
|
.filter((item, index, self) => self.indexOf(item) === index);
|
|
418
420
|
}
|
|
419
|
-
|
|
421
|
+
getClassProperties(ctx, schema) {
|
|
420
422
|
var _a;
|
|
421
423
|
const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
|
|
422
|
-
const
|
|
424
|
+
const properties = [];
|
|
425
|
+
const appendedProperties = [];
|
|
423
426
|
for (const property of schema.properties.values()) {
|
|
424
427
|
const discriminator = (_a = inheritedSchemas.find((x) => { var _a; return ((_a = x.discriminator) === null || _a === void 0 ? void 0 : _a.propertyName) === property.name; })) === null || _a === void 0 ? void 0 : _a.discriminator;
|
|
425
428
|
if (discriminator) {
|
|
@@ -429,13 +432,13 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
429
432
|
const s = createOverwriteProxy(p.schema);
|
|
430
433
|
p.schema = s;
|
|
431
434
|
s.default = schemaMappings[0][0];
|
|
432
|
-
|
|
435
|
+
appendedProperties.push(p);
|
|
433
436
|
continue;
|
|
434
437
|
}
|
|
435
438
|
}
|
|
436
|
-
|
|
439
|
+
properties.push(property);
|
|
437
440
|
}
|
|
438
|
-
return
|
|
441
|
+
return [...this.sortProperties(ctx, schema, properties), ...appendedProperties];
|
|
439
442
|
}
|
|
440
443
|
sortProperties(ctx, schema, properties) {
|
|
441
444
|
return [...properties].sort((a, b) => classify(a) - classify(b));
|
|
@@ -8,13 +8,14 @@ import { KotlinFileGenerator } from '../../file-generator';
|
|
|
8
8
|
export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
9
9
|
generate(ctx) {
|
|
10
10
|
const typeName = this.getApiClientName(ctx);
|
|
11
|
-
const
|
|
11
|
+
const packageName = this.getPackageName(ctx, ctx.service);
|
|
12
|
+
const filePath = this.getFilePath(ctx, packageName);
|
|
12
13
|
ensureDirSync(dirname(filePath));
|
|
13
14
|
console.log(`Generating client for service ${ctx.service.name} to ${filePath}...`);
|
|
14
|
-
const builder = new KotlinFileBuilder(
|
|
15
|
+
const builder = new KotlinFileBuilder(packageName, ctx.config);
|
|
15
16
|
this.generateApiClientFileContent(ctx, builder);
|
|
16
17
|
writeFileSync(filePath, builder.toString());
|
|
17
|
-
return { typeName, packageName
|
|
18
|
+
return { typeName, packageName };
|
|
18
19
|
}
|
|
19
20
|
generateApiClientFileContent(ctx, builder) {
|
|
20
21
|
builder
|
|
@@ -314,6 +315,10 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
314
315
|
builder.append(this.getTypeNameWithNullability(fallback, nullable));
|
|
315
316
|
}
|
|
316
317
|
}
|
|
318
|
+
getPackageName(ctx, service) {
|
|
319
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(service);
|
|
320
|
+
return ctx.config.packageName + packageSuffix;
|
|
321
|
+
}
|
|
317
322
|
getTypeNameWithNullability(typeName, nullable) {
|
|
318
323
|
if (nullable === undefined)
|
|
319
324
|
return typeName;
|
|
@@ -385,8 +390,8 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
385
390
|
getEndpointPath(ctx, endpoint) {
|
|
386
391
|
return modifyString(endpoint.path, ctx.config.pathModifier, endpoint);
|
|
387
392
|
}
|
|
388
|
-
getFilePath(ctx) {
|
|
389
|
-
return `${ctx.config.outputDir}/${
|
|
393
|
+
getFilePath(ctx, packageName) {
|
|
394
|
+
return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
|
|
390
395
|
}
|
|
391
396
|
getApiClientName(ctx) {
|
|
392
397
|
return toCasing(ctx.service.name, 'pascal') + 'ApiClient';
|
|
@@ -29,7 +29,6 @@ export class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProv
|
|
|
29
29
|
context.data.services = context.data.services.filter((x) => x.name !== 'exclude-from-generation');
|
|
30
30
|
const providerContext = this.getProviderContext(context, config, defaultKotlinOkHttp3ClientsGeneratorConfig);
|
|
31
31
|
return Object.assign(providerContext, {
|
|
32
|
-
packageName: this.getPackageName(providerContext.config),
|
|
33
32
|
infrastructurePackageName: this.getInfrastructurePackageName(providerContext.config),
|
|
34
33
|
});
|
|
35
34
|
}
|
|
@@ -46,7 +45,8 @@ export class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProv
|
|
|
46
45
|
return config.infrastructurePackageName.value;
|
|
47
46
|
}
|
|
48
47
|
getPackageName(config) {
|
|
49
|
-
|
|
48
|
+
const packageSuffix = typeof config.packageSuffix === 'string' ? config.packageSuffix : config.packageSuffix();
|
|
49
|
+
return config.packageName + packageSuffix;
|
|
50
50
|
}
|
|
51
51
|
copyInfrastructureFiles(ctx) {
|
|
52
52
|
const sourceDir = resolve(dirname(require.resolve('@goast/kotlin')), '../assets/client/okhttp3');
|
|
@@ -364,7 +364,8 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
364
364
|
return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}`;
|
|
365
365
|
}
|
|
366
366
|
getPackageName(ctx) {
|
|
367
|
-
|
|
367
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(ctx.service);
|
|
368
|
+
return ctx.config.packageName + packageSuffix;
|
|
368
369
|
}
|
|
369
370
|
getApiInterfaceName(ctx) {
|
|
370
371
|
return toCasing(ctx.service.name, 'pascal') + 'Api';
|
package/package.json
CHANGED
|
@@ -32,13 +32,11 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
|
|
|
32
32
|
protected generateEnum(ctx: Context, builder: Builder, schema: ApiSchema): void;
|
|
33
33
|
protected generateArrayType(ctx: Context, builder: Builder, schema: ApiSchema<'array'>): void;
|
|
34
34
|
protected generateDocumentation(ctx: Context, builder: Builder, schema: ApiSchema): void;
|
|
35
|
+
protected getPackageName(ctx: Context, schema: ApiSchema): string;
|
|
35
36
|
protected shouldGenerateTypeDeclaration(ctx: Context, schema: ApiSchema): boolean;
|
|
36
37
|
protected getDeclarationTypeName(ctx: Context, schema: ApiSchema): string;
|
|
37
38
|
protected getInheritedSchemas(ctx: KotlinModelGeneratorContext, schema: ApiSchema): ApiSchema<import("@goast/core").ApiSchemaKind>[];
|
|
38
|
-
protected
|
|
39
|
-
params: ApiSchemaProperty[];
|
|
40
|
-
properties: ApiSchemaProperty[];
|
|
41
|
-
};
|
|
39
|
+
protected getClassProperties(ctx: Context, schema: ApiSchema<'object'>): ApiSchemaProperty[];
|
|
42
40
|
protected sortProperties(ctx: Context, schema: ApiSchema, properties: Iterable<ApiSchemaProperty>): ApiSchemaProperty[];
|
|
43
41
|
private normalizeSchema;
|
|
44
42
|
private hasProperty;
|
|
@@ -3,7 +3,7 @@ import { KotlinImport } from '../../common-results';
|
|
|
3
3
|
import { KotlinGeneratorConfig } from '../../config';
|
|
4
4
|
export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
|
|
5
5
|
packageName: string;
|
|
6
|
-
packageSuffix: string;
|
|
6
|
+
packageSuffix: string | ((schema: ApiSchema) => string);
|
|
7
7
|
oneOfBehavior: 'treat-as-any-of' | 'treat-as-all-of';
|
|
8
8
|
addJacksonAnnotations: boolean;
|
|
9
9
|
addJakartaValidationAnnotations: boolean;
|
|
@@ -4,7 +4,7 @@ import { KotlinGeneratorConfig } from '../../../config';
|
|
|
4
4
|
import { KotlinModelsGeneratorOutput } from '../../models';
|
|
5
5
|
export type KotlinOkHttp3ClientsGeneratorConfig = KotlinGeneratorConfig & {
|
|
6
6
|
packageName: string;
|
|
7
|
-
packageSuffix: string;
|
|
7
|
+
packageSuffix: string | ((service?: ApiService) => string);
|
|
8
8
|
infrastructurePackageName: string | {
|
|
9
9
|
mode: 'append-package-name' | 'append-full-package-name' | 'replace';
|
|
10
10
|
value: string;
|
|
@@ -21,7 +21,6 @@ export type KotlinOkHttp3ClientsGeneratorOutput = {
|
|
|
21
21
|
};
|
|
22
22
|
export type KotlinOkHttp3ClientGeneratorOutput = KotlinImport;
|
|
23
23
|
export type KotlinOkHttp3ClientsGeneratorContext = OpenApiServicesGenerationProviderContext<KotlinOkHttp3ClientsGeneratorInput, KotlinOkHttp3ClientsGeneratorOutput, KotlinOkHttp3ClientsGeneratorConfig, KotlinOkHttp3ClientGeneratorOutput> & {
|
|
24
|
-
packageName: string;
|
|
25
24
|
infrastructurePackageName: string;
|
|
26
25
|
};
|
|
27
26
|
export type KotlinOkHttp3ClientGeneratorContext = KotlinOkHttp3ClientsGeneratorContext & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiEndpoint, ApiParameter, ApiSchema } from '@goast/core';
|
|
1
|
+
import { ApiEndpoint, ApiParameter, ApiSchema, ApiService } from '@goast/core';
|
|
2
2
|
import { KotlinOkHttp3ClientGeneratorContext, KotlinOkHttp3ClientGeneratorOutput } from './models';
|
|
3
3
|
import { KotlinImport } from '../../../common-results';
|
|
4
4
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
@@ -45,6 +45,7 @@ export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<C
|
|
|
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
47
|
protected generateTypeUsage(ctx: Context, builder: Builder, schema: ApiSchema | undefined, fallback?: string, nullable?: boolean): void;
|
|
48
|
+
protected getPackageName(ctx: Context, service: ApiService): string;
|
|
48
49
|
protected getTypeNameWithNullability(typeName: string, nullable: boolean | undefined): string;
|
|
49
50
|
protected getDefaultValue(ctx: Context, schema: ApiSchema | undefined): string;
|
|
50
51
|
protected getPathWithInterpolation(ctx: Context, endpoint: ApiEndpoint): string;
|
|
@@ -54,7 +55,7 @@ export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<C
|
|
|
54
55
|
protected getRequestBodyParamName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
55
56
|
protected getBasePath(ctx: Context): string;
|
|
56
57
|
protected getEndpointPath(ctx: Context, endpoint: ApiEndpoint): string;
|
|
57
|
-
protected getFilePath(ctx: Context): string;
|
|
58
|
+
protected getFilePath(ctx: Context, packageName: string): string;
|
|
58
59
|
protected getApiClientName(ctx: Context): string;
|
|
59
60
|
}
|
|
60
61
|
export {};
|
|
@@ -4,7 +4,7 @@ import { KotlinGeneratorConfig } from '../../../config';
|
|
|
4
4
|
import { KotlinModelsGeneratorOutput } from '../../models';
|
|
5
5
|
export type KotlinServicesGeneratorConfig = KotlinGeneratorConfig & {
|
|
6
6
|
packageName: string;
|
|
7
|
-
packageSuffix: string;
|
|
7
|
+
packageSuffix: string | ((service: ApiService) => string);
|
|
8
8
|
basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
|
|
9
9
|
pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
|
|
10
10
|
addSwaggerAnnotations: boolean;
|