@goast/kotlin 0.1.10 → 0.1.12
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 +7 -3
- 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 +7 -3
- 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 +1 -0
- 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
|
}
|
|
@@ -147,7 +147,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
147
147
|
const { params, properties } = this.classifyClassProperties(ctx, schema);
|
|
148
148
|
builder
|
|
149
149
|
.append((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
150
|
-
.append(params.length === 0 ? 'class' : 'data class ')
|
|
150
|
+
.append(params.length === 0 ? 'class' : 'data class', ' ')
|
|
151
151
|
.append(this.getDeclarationTypeName(ctx, schema))
|
|
152
152
|
.parenthesizeIf(params.length > 0, '()', (builder) => builder.forEach(this.sortProperties(ctx, schema, params), (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true })
|
|
153
153
|
.if(inheritedSchemas.length > 0, (builder) => builder
|
|
@@ -382,6 +382,10 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
382
382
|
.appendLine(' */');
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
+
getPackageName(ctx, schema) {
|
|
386
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(schema);
|
|
387
|
+
return ctx.config.packageName + packageSuffix;
|
|
388
|
+
}
|
|
385
389
|
shouldGenerateTypeDeclaration(ctx, schema) {
|
|
386
390
|
// All enum types should have its own type declaration
|
|
387
391
|
if (schema.enum !== undefined && schema.enum.length > 0) {
|
|
@@ -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
|
}
|
|
@@ -144,7 +144,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
144
144
|
const { params, properties } = this.classifyClassProperties(ctx, schema);
|
|
145
145
|
builder
|
|
146
146
|
.append((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
147
|
-
.append(params.length === 0 ? 'class' : 'data class ')
|
|
147
|
+
.append(params.length === 0 ? 'class' : 'data class', ' ')
|
|
148
148
|
.append(this.getDeclarationTypeName(ctx, schema))
|
|
149
149
|
.parenthesizeIf(params.length > 0, '()', (builder) => builder.forEach(this.sortProperties(ctx, schema, params), (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true })
|
|
150
150
|
.if(inheritedSchemas.length > 0, (builder) => builder
|
|
@@ -379,6 +379,10 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
379
379
|
.appendLine(' */');
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
+
getPackageName(ctx, schema) {
|
|
383
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(schema);
|
|
384
|
+
return ctx.config.packageName + packageSuffix;
|
|
385
|
+
}
|
|
382
386
|
shouldGenerateTypeDeclaration(ctx, schema) {
|
|
383
387
|
// All enum types should have its own type declaration
|
|
384
388
|
if (schema.enum !== undefined && schema.enum.length > 0) {
|
|
@@ -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,6 +32,7 @@ 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>[];
|
|
@@ -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;
|