@goast/kotlin 0.1.17 → 0.2.0
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 -0
- package/cjs/lib/ast/_index.js +81 -0
- package/cjs/lib/ast/common.js +2 -0
- package/cjs/lib/ast/index.js +5 -0
- package/cjs/lib/ast/node.js +10 -0
- package/cjs/lib/ast/nodes/annotation.js +39 -0
- package/cjs/lib/ast/nodes/argument.js +32 -0
- package/cjs/lib/ast/nodes/call.js +37 -0
- package/cjs/lib/ast/nodes/class.js +94 -0
- package/cjs/lib/ast/nodes/collection-literal.js +24 -0
- package/cjs/lib/ast/nodes/constructor.js +75 -0
- package/cjs/lib/ast/nodes/doc-tag.js +60 -0
- package/cjs/lib/ast/nodes/doc.js +55 -0
- package/cjs/lib/ast/nodes/enum-value.js +50 -0
- package/cjs/lib/ast/nodes/enum.js +83 -0
- package/cjs/lib/ast/nodes/function.js +105 -0
- package/cjs/lib/ast/nodes/generic-parameter.js +29 -0
- package/cjs/lib/ast/nodes/init-block.js +19 -0
- package/cjs/lib/ast/nodes/interface.js +68 -0
- package/cjs/lib/ast/nodes/lambda-type.js +44 -0
- package/cjs/lib/ast/nodes/lambda.js +36 -0
- package/cjs/lib/ast/nodes/object.js +58 -0
- package/cjs/lib/ast/nodes/parameter.js +57 -0
- package/cjs/lib/ast/nodes/property.js +142 -0
- package/cjs/lib/ast/nodes/reference.js +79 -0
- package/cjs/lib/ast/nodes/string.js +87 -0
- package/cjs/lib/ast/nodes/types.js +2 -0
- package/cjs/lib/ast/references/index.js +12 -0
- package/cjs/lib/ast/references/jackson.js +12 -0
- package/cjs/lib/ast/references/jakarta.js +10 -0
- package/cjs/lib/ast/references/java.js +14 -0
- package/cjs/lib/ast/references/kotlin.js +27 -0
- package/cjs/lib/ast/references/okhttp3.js +7 -0
- package/cjs/lib/ast/references/reactor.js +6 -0
- package/cjs/lib/ast/references/spring.js +21 -0
- package/cjs/lib/ast/references/swagger.js +11 -0
- package/cjs/lib/ast/utils/get-kotlin-builder-options.js +19 -0
- package/cjs/lib/ast/utils/to-kt-node.js +22 -0
- package/cjs/lib/ast/utils/write-kt-annotations.js +13 -0
- package/cjs/lib/ast/utils/write-kt-arguments.js +33 -0
- package/cjs/lib/ast/utils/write-kt-enum-values.js +17 -0
- package/cjs/lib/ast/utils/write-kt-generic-parameters.js +12 -0
- package/cjs/lib/ast/utils/write-kt-members.js +16 -0
- package/cjs/lib/ast/utils/write-kt-node.js +24 -0
- package/cjs/lib/ast/utils/write-kt-parameters.js +13 -0
- package/cjs/lib/config.js +15 -1
- package/cjs/lib/file-builder.js +17 -2
- package/cjs/lib/generators/models/args.js +2 -0
- package/cjs/lib/generators/models/index.js +2 -0
- package/cjs/lib/generators/models/model-generator.js +281 -322
- package/cjs/lib/generators/services/okhttp3-clients/args.js +2 -0
- package/cjs/lib/generators/services/okhttp3-clients/index.js +2 -0
- package/cjs/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +240 -348
- package/cjs/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
- package/cjs/lib/generators/services/okhttp3-clients/refs.js +34 -0
- package/cjs/lib/generators/services/spring-controllers/args.js +2 -0
- package/cjs/lib/generators/services/spring-controllers/index.js +2 -0
- package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +270 -346
- package/cjs/lib/import-collection.js +24 -15
- package/esm/index.js +3 -0
- package/esm/lib/ast/_index.js +27 -0
- package/esm/lib/ast/common.js +1 -0
- package/esm/lib/ast/index.js +2 -0
- package/esm/lib/ast/node.js +6 -0
- package/esm/lib/ast/nodes/annotation.js +35 -0
- package/esm/lib/ast/nodes/argument.js +28 -0
- package/esm/lib/ast/nodes/call.js +33 -0
- package/esm/lib/ast/nodes/class.js +90 -0
- package/esm/lib/ast/nodes/collection-literal.js +20 -0
- package/esm/lib/ast/nodes/constructor.js +71 -0
- package/esm/lib/ast/nodes/doc-tag.js +56 -0
- package/esm/lib/ast/nodes/doc.js +51 -0
- package/esm/lib/ast/nodes/enum-value.js +46 -0
- package/esm/lib/ast/nodes/enum.js +79 -0
- package/esm/lib/ast/nodes/function.js +101 -0
- package/esm/lib/ast/nodes/generic-parameter.js +25 -0
- package/esm/lib/ast/nodes/init-block.js +15 -0
- package/esm/lib/ast/nodes/interface.js +64 -0
- package/esm/lib/ast/nodes/lambda-type.js +40 -0
- package/esm/lib/ast/nodes/lambda.js +32 -0
- package/esm/lib/ast/nodes/object.js +54 -0
- package/esm/lib/ast/nodes/parameter.js +53 -0
- package/esm/lib/ast/nodes/property.js +135 -0
- package/esm/lib/ast/nodes/reference.js +75 -0
- package/esm/lib/ast/nodes/string.js +83 -0
- package/esm/lib/ast/nodes/types.js +1 -0
- package/esm/lib/ast/references/index.js +15 -0
- package/esm/lib/ast/references/jackson.js +9 -0
- package/esm/lib/ast/references/jakarta.js +7 -0
- package/esm/lib/ast/references/java.js +11 -0
- package/esm/lib/ast/references/kotlin.js +24 -0
- package/esm/lib/ast/references/okhttp3.js +4 -0
- package/esm/lib/ast/references/reactor.js +3 -0
- package/esm/lib/ast/references/spring.js +18 -0
- package/esm/lib/ast/references/swagger.js +8 -0
- package/esm/lib/ast/utils/get-kotlin-builder-options.js +15 -0
- package/esm/lib/ast/utils/to-kt-node.js +18 -0
- package/esm/lib/ast/utils/write-kt-annotations.js +9 -0
- package/esm/lib/ast/utils/write-kt-arguments.js +29 -0
- package/esm/lib/ast/utils/write-kt-enum-values.js +13 -0
- package/esm/lib/ast/utils/write-kt-generic-parameters.js +8 -0
- package/esm/lib/ast/utils/write-kt-members.js +12 -0
- package/esm/lib/ast/utils/write-kt-node.js +19 -0
- package/esm/lib/ast/utils/write-kt-parameters.js +9 -0
- package/esm/lib/config.js +15 -1
- package/esm/lib/file-builder.js +16 -2
- package/esm/lib/generators/models/args.js +1 -0
- package/esm/lib/generators/models/index.js +2 -0
- package/esm/lib/generators/models/model-generator.js +282 -323
- package/esm/lib/generators/services/okhttp3-clients/args.js +1 -0
- package/esm/lib/generators/services/okhttp3-clients/index.js +2 -0
- package/esm/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +242 -350
- package/esm/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
- package/esm/lib/generators/services/okhttp3-clients/refs.js +30 -0
- package/esm/lib/generators/services/spring-controllers/args.js +1 -0
- package/esm/lib/generators/services/spring-controllers/index.js +2 -0
- package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +269 -346
- package/esm/lib/import-collection.js +23 -14
- package/package.json +6 -6
- package/types/index.d.ts +2 -0
- package/types/lib/ast/_index.d.ts +28 -0
- package/types/lib/ast/common.d.ts +1 -0
- package/types/lib/ast/index.d.ts +1 -0
- package/types/lib/ast/node.d.ts +4 -0
- package/types/lib/ast/nodes/annotation.d.ts +23 -0
- package/types/lib/ast/nodes/argument.d.ts +22 -0
- package/types/lib/ast/nodes/call.d.ts +22 -0
- package/types/lib/ast/nodes/class.d.ts +54 -0
- package/types/lib/ast/nodes/collection-literal.d.ts +17 -0
- package/types/lib/ast/nodes/constructor.d.ts +34 -0
- package/types/lib/ast/nodes/doc-tag.d.ts +34 -0
- package/types/lib/ast/nodes/doc.d.ts +26 -0
- package/types/lib/ast/nodes/enum-value.d.ts +30 -0
- package/types/lib/ast/nodes/enum.d.ts +45 -0
- package/types/lib/ast/nodes/function.d.ts +58 -0
- package/types/lib/ast/nodes/generic-parameter.d.ts +21 -0
- package/types/lib/ast/nodes/init-block.d.ts +16 -0
- package/types/lib/ast/nodes/interface.d.ts +41 -0
- package/types/lib/ast/nodes/lambda-type.d.ts +21 -0
- package/types/lib/ast/nodes/lambda.d.ts +20 -0
- package/types/lib/ast/nodes/object.d.ts +34 -0
- package/types/lib/ast/nodes/parameter.d.ts +48 -0
- package/types/lib/ast/nodes/property.d.ts +87 -0
- package/types/lib/ast/nodes/reference.d.ts +63 -0
- package/types/lib/ast/nodes/string.d.ts +30 -0
- package/types/lib/ast/nodes/types.d.ts +10 -0
- package/types/lib/ast/references/index.d.ts +8 -0
- package/types/lib/ast/references/jackson.d.ts +77 -0
- package/types/lib/ast/references/jakarta.d.ts +33 -0
- package/types/lib/ast/references/java.d.ts +71 -0
- package/types/lib/ast/references/kotlin.d.ts +265 -0
- package/types/lib/ast/references/okhttp3.d.ts +22 -0
- package/types/lib/ast/references/reactor.d.ts +16 -0
- package/types/lib/ast/references/spring.d.ts +126 -0
- package/types/lib/ast/references/swagger.d.ts +44 -0
- package/types/lib/ast/utils/get-kotlin-builder-options.d.ts +3 -0
- package/types/lib/ast/utils/to-kt-node.d.ts +7 -0
- package/types/lib/ast/utils/write-kt-annotations.d.ts +5 -0
- package/types/lib/ast/utils/write-kt-arguments.d.ts +3 -0
- package/types/lib/ast/utils/write-kt-enum-values.d.ts +3 -0
- package/types/lib/ast/utils/write-kt-generic-parameters.d.ts +3 -0
- package/types/lib/ast/utils/write-kt-members.d.ts +5 -0
- package/types/lib/ast/utils/write-kt-node.d.ts +7 -0
- package/types/lib/ast/utils/write-kt-parameters.d.ts +3 -0
- package/types/lib/config.d.ts +4 -0
- package/types/lib/file-builder.d.ts +10 -3
- package/types/lib/generators/models/args.d.ts +99 -0
- package/types/lib/generators/models/index.d.ts +1 -0
- package/types/lib/generators/models/model-generator.d.ts +35 -32
- package/types/lib/generators/models/models.d.ts +4 -4
- package/types/lib/generators/services/okhttp3-clients/args.d.ts +66 -0
- package/types/lib/generators/services/okhttp3-clients/index.d.ts +1 -0
- package/types/lib/generators/services/okhttp3-clients/models.d.ts +2 -0
- package/types/lib/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +25 -47
- package/types/lib/generators/services/okhttp3-clients/refs.d.ts +235 -0
- package/types/lib/generators/services/spring-controllers/args.d.ts +70 -0
- package/types/lib/generators/services/spring-controllers/index.d.ts +1 -0
- package/types/lib/generators/services/spring-controllers/spring-controller-generator.d.ts +37 -51
- package/types/lib/import-collection.d.ts +7 -1
|
@@ -1,345 +1,250 @@
|
|
|
1
|
+
/* eslint-disable unused-imports/no-unused-vars */
|
|
1
2
|
import { writeFileSync } from 'fs';
|
|
2
3
|
import { dirname } from 'path';
|
|
3
4
|
import { ensureDirSync } from 'fs-extra';
|
|
4
|
-
import { toCasing } from '@goast/core';
|
|
5
|
+
import { SourceBuilder, appendValueGroup, builderTemplate as s, createOverwriteProxy, toCasing, } from '@goast/core';
|
|
6
|
+
import { kt } from '../../../ast';
|
|
5
7
|
import { KotlinFileBuilder } from '../../../file-builder';
|
|
6
|
-
import { modifyString
|
|
8
|
+
import { modifyString } from '../../../utils';
|
|
7
9
|
import { KotlinFileGenerator } from '../../file-generator';
|
|
8
10
|
export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
9
11
|
generate(ctx) {
|
|
10
|
-
const typeName = this.getApiClientName(ctx);
|
|
11
|
-
const packageName = this.getPackageName(ctx,
|
|
12
|
-
const filePath = this.getFilePath(ctx, packageName);
|
|
12
|
+
const typeName = this.getApiClientName(ctx, {});
|
|
13
|
+
const packageName = this.getPackageName(ctx, {});
|
|
14
|
+
const filePath = this.getFilePath(ctx, { packageName });
|
|
13
15
|
ensureDirSync(dirname(filePath));
|
|
14
16
|
console.log(`Generating client for service ${ctx.service.name} to ${filePath}...`);
|
|
15
17
|
const builder = new KotlinFileBuilder(packageName, ctx.config);
|
|
16
|
-
this.
|
|
18
|
+
builder.append(this.getClientFileContent(ctx, {}));
|
|
17
19
|
writeFileSync(filePath, builder.toString());
|
|
18
20
|
return { typeName, packageName };
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.addImport('OkHttpClient', 'okhttp3')
|
|
39
|
-
.addImport('ApiClient', ctx.infrastructurePackageName), { multiline: true })
|
|
40
|
-
.append(' : ')
|
|
41
|
-
.append('ApiClient(basePath, client)');
|
|
42
|
-
}
|
|
43
|
-
generateApiClientClassContent(ctx, builder) {
|
|
44
|
-
builder
|
|
45
|
-
.append((builder) => this.generateApiClientCompanionObject(ctx, builder))
|
|
46
|
-
.forEach(ctx.service.endpoints, (builder, endpoint) => builder
|
|
47
|
-
.ensurePreviousLineEmpty()
|
|
48
|
-
.append((builder) => this.generateApiClientMethod(ctx, builder, endpoint))
|
|
49
|
-
.ensurePreviousLineEmpty()
|
|
50
|
-
.append((builder) => this.generateApiClientHttpInfoMethod(ctx, builder, endpoint))
|
|
51
|
-
.ensurePreviousLineEmpty()
|
|
52
|
-
.append((builder) => this.generateApiClientRequestConfigMethod(ctx, builder, endpoint)))
|
|
53
|
-
.ensurePreviousLineEmpty()
|
|
54
|
-
.append((builder) => this.generateAdditionalMethods(ctx, builder));
|
|
55
|
-
}
|
|
56
|
-
generateApiClientCompanionObject(ctx, builder) {
|
|
57
|
-
builder
|
|
58
|
-
.append('companion object ')
|
|
59
|
-
.parenthesize('{}', (builder) => this.generateApiClientCompanionObjectContent(ctx, builder), { multiline: true });
|
|
60
|
-
}
|
|
61
|
-
generateApiClientCompanionObjectContent(ctx, builder) {
|
|
62
|
-
this.generateApiClientCompanionObjectDefaultBasePathProperty(ctx, builder);
|
|
63
|
-
}
|
|
64
|
-
generateApiClientCompanionObjectDefaultBasePathProperty(ctx, builder) {
|
|
65
|
-
builder
|
|
66
|
-
.appendAnnotation('JvmStatic')
|
|
67
|
-
.append('val defaultBasePath: String by lazy ')
|
|
68
|
-
.parenthesize('{}', (builder) => builder
|
|
69
|
-
.appendLine(`System.getProperties().getProperty(ApiClient.baseUrlKey, ${this.toStringLiteral(ctx, this.getBasePath(ctx))})`)
|
|
70
|
-
.addImport('ApiClient', ctx.infrastructurePackageName), { multiline: true });
|
|
71
|
-
}
|
|
72
|
-
generateApiClientMethod(ctx, builder, endpoint) {
|
|
73
|
-
builder
|
|
74
|
-
.append((builder) => this.generateApiClientMethodDocumentation(ctx, builder, endpoint))
|
|
75
|
-
.ensureCurrentLineEmpty()
|
|
76
|
-
.append((builder) => this.generateApiClientMethodAnnotations(ctx, builder, endpoint))
|
|
77
|
-
.ensureCurrentLineEmpty()
|
|
78
|
-
.append((builder) => this.generateApiClientMethodSignature(ctx, builder, endpoint))
|
|
79
|
-
.append(' ')
|
|
80
|
-
.parenthesize('{}', (builder) => this.generateApiClientMethodContent(ctx, builder, endpoint), {
|
|
81
|
-
multiline: true,
|
|
22
|
+
getClientFileContent(ctx, args) {
|
|
23
|
+
return appendValueGroup([this.getClientClass(ctx, {})]);
|
|
24
|
+
}
|
|
25
|
+
getClientClass(ctx, args) {
|
|
26
|
+
return kt.class(this.getApiClientName(ctx, {}), {
|
|
27
|
+
extends: ctx.refs.apiClient(),
|
|
28
|
+
primaryConstructor: kt.constructor([
|
|
29
|
+
kt.parameter('basePath', kt.refs.string(), { default: 'defaultBasePath' }),
|
|
30
|
+
kt.parameter('client', kt.refs.okhttp3.okHttpClient(), { default: kt.call(['ApiClient', 'defaultClient']) }),
|
|
31
|
+
], null, {
|
|
32
|
+
delegateTarget: 'super',
|
|
33
|
+
delegateArguments: ['basePath', 'client'],
|
|
34
|
+
}),
|
|
35
|
+
companionObject: this.getClientCompanionObject(ctx, {}),
|
|
36
|
+
members: [
|
|
37
|
+
...ctx.service.endpoints.flatMap((endpoint) => this.getEndpointClientMembers(ctx, { endpoint, parameters: this.getAllParameters(ctx, { endpoint }) })),
|
|
38
|
+
...this.getAdditionalClientMembers(ctx, {}),
|
|
39
|
+
],
|
|
82
40
|
});
|
|
83
41
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.append(`val localVarResponse = ${toCasing(endpoint.name, 'camel')}WithHttpInfo`)
|
|
134
|
-
.parenthesize('()', (builder) => this.generateParams(ctx, builder, endpoint, false))
|
|
135
|
-
.appendLine()
|
|
136
|
-
.appendLine()
|
|
137
|
-
.append('return when (localVarResponse.responseType) ')
|
|
138
|
-
.parenthesize('{}', (builder) => builder
|
|
139
|
-
.append('ResponseType.Success -> ')
|
|
140
|
-
.if(responseSchema === undefined, (builder) => builder.append('Unit'), (builder) => builder
|
|
141
|
-
.append('(localVarResponse as Success<*>).data as ')
|
|
142
|
-
.addImport('Success', ctx.infrastructurePackageName)
|
|
143
|
-
.append((builder) => this.generateTypeUsage(ctx, builder, responseSchema)))
|
|
144
|
-
.ensureCurrentLineEmpty()
|
|
145
|
-
.appendLine(responseErrorHandlingCode)
|
|
146
|
-
.addImport('ClientError', ctx.infrastructurePackageName)
|
|
147
|
-
.addImport('ServerError', ctx.infrastructurePackageName)
|
|
148
|
-
.addImport('ResponseType', ctx.infrastructurePackageName), { multiline: true });
|
|
149
|
-
}
|
|
150
|
-
generateApiClientHttpInfoMethod(ctx, builder, endpoint) {
|
|
151
|
-
builder
|
|
152
|
-
.append((builder) => this.generateApiClientHttpInfoMethodDocumentation(ctx, builder, endpoint))
|
|
153
|
-
.ensureCurrentLineEmpty()
|
|
154
|
-
.append((builder) => this.generateApiClientHttpInfoMethodAnnotations(ctx, builder, endpoint))
|
|
155
|
-
.ensureCurrentLineEmpty()
|
|
156
|
-
.append((builder) => this.generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint))
|
|
157
|
-
.append(' ')
|
|
158
|
-
.parenthesize('{}', (builder) => this.generateApiClientHttpInfoMethodContent(ctx, builder, endpoint), {
|
|
159
|
-
multiline: true,
|
|
42
|
+
getClientCompanionObject(ctx, args) {
|
|
43
|
+
const result = kt.object();
|
|
44
|
+
result.members.push(kt.property('defaultBasePath', {
|
|
45
|
+
annotations: [kt.annotation(kt.refs.jvmStatic())],
|
|
46
|
+
type: kt.refs.string(),
|
|
47
|
+
delegate: kt.refs.lazyFun.infer(),
|
|
48
|
+
delegateArguments: [
|
|
49
|
+
kt.lambda([], kt.call([kt.call([kt.refs.java.system(), 'getProperties'], []), 'getProperty'], [kt.call([ctx.refs.apiClient(), 'baseUrlKey']), kt.string(this.getBasePath(ctx, {}))])),
|
|
50
|
+
],
|
|
51
|
+
}));
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
getEndpointClientMembers(ctx, args) {
|
|
55
|
+
const { endpoint, parameters } = args;
|
|
56
|
+
const responseSchema = this.getResponseSchema(ctx, { endpoint });
|
|
57
|
+
return [
|
|
58
|
+
this.getEndpointClientMethod(ctx, { endpoint, parameters, responseSchema }),
|
|
59
|
+
this.getEndpointClientHttpInfoMethod(ctx, { endpoint, parameters, responseSchema }),
|
|
60
|
+
this.getEndpointClientRequestConfigMethod(ctx, { endpoint, parameters }),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
getEndpointClientMethod(ctx, args) {
|
|
64
|
+
const { endpoint, parameters, responseSchema } = args;
|
|
65
|
+
return kt.function(toCasing(endpoint.name, ctx.config.functionNameCasing), {
|
|
66
|
+
doc: kt.doc(endpoint.summary, [
|
|
67
|
+
kt.docTag('throws', 'IllegalStateException', 'If the request is not correctly configured'),
|
|
68
|
+
kt.docTag('throws', 'IOException', 'Rethrows the OkHttp execute method exception'),
|
|
69
|
+
kt.docTag('throws', 'UnsupportedOperationException', 'If the API returns an informational or redirection response'),
|
|
70
|
+
kt.docTag('throws', 'ClientException', 'If the API returns a client error response'),
|
|
71
|
+
kt.docTag('throws', 'ServerException', 'If the API returns a server error response'),
|
|
72
|
+
]),
|
|
73
|
+
annotations: [
|
|
74
|
+
kt.annotation(kt.refs.throws(), [
|
|
75
|
+
kt.refs.java.illegalStateException({ classReference: true }),
|
|
76
|
+
kt.refs.java.ioException({ classReference: true }),
|
|
77
|
+
kt.refs.java.unsupportedOperationException({ classReference: true }),
|
|
78
|
+
ctx.refs.clientException({ classReference: true }),
|
|
79
|
+
ctx.refs.serverException({ classReference: true }),
|
|
80
|
+
]),
|
|
81
|
+
],
|
|
82
|
+
parameters: parameters.map((p) => {
|
|
83
|
+
var _a;
|
|
84
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getTypeUsage(ctx, { schema: p.schema, nullable: !p.required }), {
|
|
85
|
+
description: p.description,
|
|
86
|
+
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
87
|
+
});
|
|
88
|
+
}),
|
|
89
|
+
returnType: this.getTypeUsage(ctx, { schema: responseSchema, fallback: kt.refs.unit() }),
|
|
90
|
+
body: this.getEndpointClientMethodBody(ctx, { endpoint, parameters, responseSchema }),
|
|
160
91
|
});
|
|
161
92
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
.
|
|
166
|
-
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
.ensureCurrentLineEmpty()
|
|
220
|
-
.append((builder) => this.generateApiClientRequestConfigMethodAnnotations(ctx, builder, endpoint))
|
|
221
|
-
.ensureCurrentLineEmpty()
|
|
222
|
-
.append((builder) => this.generateApiClientRequestConfigMethodSignature(ctx, builder, endpoint))
|
|
223
|
-
.append(' ')
|
|
224
|
-
.parenthesize('{}', (builder) => this.generateApiClientRequestConfigMethodContent(ctx, builder, endpoint), {
|
|
225
|
-
multiline: true,
|
|
93
|
+
getEndpointClientMethodBody(ctx, args) {
|
|
94
|
+
const { endpoint, parameters, responseSchema } = args;
|
|
95
|
+
return appendValueGroup([
|
|
96
|
+
s `val localVarResponse = ${kt.call([toCasing(endpoint.name + '_WithHttpInfo', ctx.config.functionNameCasing)], parameters.map((x) => x.name))}`,
|
|
97
|
+
'',
|
|
98
|
+
s `return when (localVarResponse.responseType) {${s.indent `
|
|
99
|
+
${ctx.refs.responseType()}.Success -> ${responseSchema === undefined
|
|
100
|
+
? kt.refs.unit()
|
|
101
|
+
: s `(localVarResponse as ${ctx.refs.success(['*'])}).data as ${this.getTypeUsage(ctx, {
|
|
102
|
+
schema: responseSchema,
|
|
103
|
+
})}`}
|
|
104
|
+
${ctx.refs.responseType()}.Informational -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
|
|
105
|
+
${ctx.refs.responseType()}.Redirection -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
|
|
106
|
+
${ctx.refs.responseType()}.ClientError -> {${s.indent `
|
|
107
|
+
val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
|
|
108
|
+
throw ${ctx.refs.clientException()}(${s.indent `
|
|
109
|
+
"Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
110
|
+
localVarError.statusCode,
|
|
111
|
+
localVarResponse`}
|
|
112
|
+
)`}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
${ctx.refs.responseType()}.ServerError -> {${s.indent `
|
|
116
|
+
val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
|
|
117
|
+
throw ${ctx.refs.serverException()}(${s.indent `
|
|
118
|
+
"Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
119
|
+
localVarError.statusCode,
|
|
120
|
+
localVarResponse`}
|
|
121
|
+
)`}
|
|
122
|
+
}`}
|
|
123
|
+
}`,
|
|
124
|
+
], '\n');
|
|
125
|
+
}
|
|
126
|
+
getEndpointClientHttpInfoMethod(ctx, args) {
|
|
127
|
+
const { endpoint, parameters, responseSchema } = args;
|
|
128
|
+
return kt.function(toCasing(args.endpoint.name, ctx.config.functionNameCasing) + 'WithHttpInfo', {
|
|
129
|
+
doc: kt.doc(endpoint.summary, [
|
|
130
|
+
kt.docTag('throws', 'IllegalStateException', 'If the request is not correctly configured'),
|
|
131
|
+
kt.docTag('throws', 'IOException', 'Rethrows the OkHttp execute method exception'),
|
|
132
|
+
]),
|
|
133
|
+
annotations: [
|
|
134
|
+
kt.annotation(kt.refs.throws(), [
|
|
135
|
+
kt.refs.java.illegalStateException({ classReference: true }),
|
|
136
|
+
kt.refs.java.ioException({ classReference: true }),
|
|
137
|
+
]),
|
|
138
|
+
],
|
|
139
|
+
parameters: parameters.map((p) => {
|
|
140
|
+
var _a;
|
|
141
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getTypeUsage(ctx, { schema: p.schema, nullable: !p.required }), {
|
|
142
|
+
description: p.description,
|
|
143
|
+
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
144
|
+
});
|
|
145
|
+
}),
|
|
146
|
+
returnType: ctx.refs.apiResponse([
|
|
147
|
+
this.getTypeUsage(ctx, { schema: responseSchema, fallback: kt.refs.unit(), nullable: true }),
|
|
148
|
+
]),
|
|
149
|
+
body: this.getEndpointClientHttpInfoMethodBody(ctx, { endpoint, parameters, responseSchema }),
|
|
226
150
|
});
|
|
227
151
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
152
|
+
getEndpointClientHttpInfoMethodBody(ctx, args) {
|
|
153
|
+
var _a;
|
|
154
|
+
const { endpoint, parameters, responseSchema } = args;
|
|
155
|
+
return appendValueGroup([
|
|
156
|
+
s `val localVariableConfig = ${kt.call([toCasing(endpoint.name, 'camel') + 'RequestConfig'], parameters.map((x) => x.name))}`,
|
|
157
|
+
s `return ${kt.call([
|
|
158
|
+
kt.reference('request', null, {
|
|
159
|
+
generics: [
|
|
160
|
+
this.getTypeUsage(ctx, { schema: (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, fallback: kt.refs.unit() }),
|
|
161
|
+
this.getTypeUsage(ctx, { schema: responseSchema, fallback: kt.refs.unit() }),
|
|
162
|
+
],
|
|
163
|
+
}),
|
|
164
|
+
], ['localVariableConfig'])}`,
|
|
165
|
+
], '\n');
|
|
166
|
+
}
|
|
167
|
+
getEndpointClientRequestConfigMethod(ctx, args) {
|
|
168
|
+
var _a;
|
|
169
|
+
const { endpoint, parameters } = args;
|
|
170
|
+
const operationName = toCasing(endpoint.name, ctx.config.functionNameCasing);
|
|
171
|
+
const requestSchema = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema;
|
|
172
|
+
return kt.function(toCasing(args.endpoint.name, ctx.config.functionNameCasing) + 'RequestConfig', {
|
|
173
|
+
accessModifier: 'private',
|
|
174
|
+
doc: kt.doc(`To obtain the request config of the operation ${operationName}`),
|
|
175
|
+
parameters: parameters.map((p) => {
|
|
176
|
+
var _a;
|
|
177
|
+
return kt.parameter(toCasing(p.name, ctx.config.parameterNameCasing), this.getTypeUsage(ctx, { schema: p.schema, nullable: !p.required }), {
|
|
178
|
+
description: p.description,
|
|
179
|
+
default: !p.required ? kt.toNode((_a = p.schema) === null || _a === void 0 ? void 0 : _a.default) : null,
|
|
180
|
+
});
|
|
181
|
+
}),
|
|
182
|
+
returnType: ctx.refs.requestConfig([this.getTypeUsage(ctx, { schema: requestSchema, fallback: kt.refs.unit() })]),
|
|
183
|
+
body: this.getEndpointClientRequestConfigMethodBody(ctx, { endpoint }),
|
|
184
|
+
});
|
|
256
185
|
}
|
|
257
|
-
|
|
186
|
+
getEndpointClientRequestConfigMethodBody(ctx, args) {
|
|
258
187
|
var _a, _b;
|
|
188
|
+
const { endpoint } = args;
|
|
259
189
|
const queryParameters = endpoint.parameters.filter((x) => x.target === 'query');
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
.
|
|
263
|
-
.
|
|
264
|
-
.if(queryParameters.length > 0, (builder) => builder.indent((builder) => builder.append('.apply ').parenthesize('{}', (builder) => builder.forEach(queryParameters, (builder, param) => builder
|
|
265
|
-
.appendIf(!param.required, `if (${toCasing(param.name, 'camel')} != null) `)
|
|
266
|
-
.parenthesizeIf(!param.required, '{}', (builder) => builder.appendLine(`put(${this.toStringLiteral(ctx, toCasing(param.name, 'camel'))}, listOf(${toCasing(param.name, 'camel')}.toString()))`), { multiline: true })
|
|
267
|
-
.appendLine()), { multiline: true })))
|
|
268
|
-
.ensureCurrentLineEmpty()
|
|
269
|
-
.appendLine('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()')
|
|
270
|
-
.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}"`)
|
|
271
|
-
.appendLine()
|
|
272
|
-
.append('return RequestConfig')
|
|
273
|
-
.addImport('RequestConfig', ctx.infrastructurePackageName)
|
|
274
|
-
.parenthesize('()', (builder) => builder
|
|
275
|
-
.appendLine(`method = RequestMethod.${endpoint.method.toUpperCase()},`)
|
|
276
|
-
.addImport('RequestMethod', ctx.infrastructurePackageName)
|
|
277
|
-
.appendLine(`path = "${this.getPathWithInterpolation(ctx, endpoint)}",`)
|
|
278
|
-
.appendLine('query = localVariableQuery,')
|
|
279
|
-
.appendLine('headers = localVariableHeaders,')
|
|
280
|
-
.appendLine('requiresAuthentication = false,')
|
|
281
|
-
.appendLineIf(!!endpoint.requestBody, 'body = localVariableBody'), { multiline: true });
|
|
282
|
-
}
|
|
283
|
-
generateAdditionalMethods(ctx, builder) {
|
|
284
|
-
this.generateEncodeUriComponentMethod(ctx, builder);
|
|
285
|
-
}
|
|
286
|
-
generateEncodeUriComponentMethod(ctx, builder) {
|
|
287
|
-
builder
|
|
288
|
-
.appendLine('private fun encodeURIComponent(uriComponent: String): String =')
|
|
289
|
-
.indent('HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]')
|
|
290
|
-
.addImport('HttpUrl', 'okhttp3');
|
|
291
|
-
}
|
|
292
|
-
generateParamDocEntries(ctx, builder, endpoint) {
|
|
293
|
-
const parameters = this.getAllParameters(ctx, endpoint);
|
|
294
|
-
builder.forEach(parameters, (builder, parameter) => { var _a; return builder.appendLine(`@param ${parameter.name} ${(_a = parameter.description) !== null && _a !== void 0 ? _a : 'TODO: Provide description'}`); });
|
|
295
|
-
}
|
|
296
|
-
generateParams(ctx, builder, endpoint, includeTypeDefinition) {
|
|
297
|
-
const parameters = this.getAllParameters(ctx, endpoint);
|
|
298
|
-
builder.forEach(parameters, (builder, parameter) => builder.append(toCasing(parameter.name, 'camel')).if(includeTypeDefinition, (builder) => builder
|
|
299
|
-
.append(': ')
|
|
300
|
-
.append((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
|
|
301
|
-
.appendIf(!parameter.required, '? = ', this.getDefaultValue(ctx, parameter.schema))), { separator: ', ' });
|
|
302
|
-
}
|
|
303
|
-
generateTypeUsage(ctx, builder, schema, fallback, nullable) {
|
|
304
|
-
if (schema && schema.kind === 'array') {
|
|
305
|
-
const schemaInfo = this.getSchemaInfo(ctx, schema.items);
|
|
306
|
-
builder.append(this.getTypeNameWithNullability(`List<${schemaInfo.typeName}>`, nullable));
|
|
307
|
-
builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
|
|
308
|
-
}
|
|
309
|
-
else if (schema || !fallback) {
|
|
310
|
-
const schemaInfo = this.getSchemaInfo(ctx, schema);
|
|
311
|
-
builder.append(this.getTypeNameWithNullability(schemaInfo.typeName, nullable));
|
|
312
|
-
builder.imports.addImports([schemaInfo, ...schemaInfo.additionalImports]);
|
|
190
|
+
const result = appendValueGroup([], '\n');
|
|
191
|
+
if (endpoint.requestBody) {
|
|
192
|
+
const bodyParamName = toCasing(this.getRequestBodyParamName(ctx, { endpoint }), ctx.config.parameterNameCasing);
|
|
193
|
+
result.values.push(`val localVariableBody = ${bodyParamName}`);
|
|
313
194
|
}
|
|
314
|
-
|
|
315
|
-
|
|
195
|
+
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
|
|
196
|
+
? ''
|
|
197
|
+
: s.indent `
|
|
198
|
+
.apply {${s.indent `
|
|
199
|
+
${appendValueGroup(queryParameters.map((param) => {
|
|
200
|
+
const paramName = toCasing(param.name, ctx.config.parameterNameCasing);
|
|
201
|
+
const put = s `put(${kt.string(paramName)}, listOf(${paramName}.toString()))`;
|
|
202
|
+
return param.required
|
|
203
|
+
? put
|
|
204
|
+
: s `if (${paramName} != null) {${s.indent `
|
|
205
|
+
${put}`}
|
|
206
|
+
}`;
|
|
207
|
+
}), '\n')}`}
|
|
208
|
+
}`}`);
|
|
209
|
+
result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
|
|
210
|
+
if (((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0]) !== undefined) {
|
|
211
|
+
result.values.push(`localVariableHeaders["Content-Type"] = "${(_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0].type}"`);
|
|
316
212
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
213
|
+
result.values.push(s `return ${kt.call([ctx.refs.requestConfig.infer()], [
|
|
214
|
+
kt.argument.named('method', kt.call([ctx.refs.requestMethod(), endpoint.method.toUpperCase()])),
|
|
215
|
+
kt.argument.named('path', kt.string(this.getPathWithInterpolation(ctx, { endpoint }), { template: true })),
|
|
216
|
+
kt.argument.named('query', 'localVariableQuery'),
|
|
217
|
+
kt.argument.named('headers', 'localVariableHeaders'),
|
|
218
|
+
kt.argument.named('requiresAuthentication', 'false'),
|
|
219
|
+
endpoint.requestBody ? kt.argument.named('body', 'localVariableBody') : null,
|
|
220
|
+
])}`);
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
getAdditionalClientMembers(ctx, args) {
|
|
224
|
+
return [
|
|
225
|
+
kt.function('encodeURIComponent', {
|
|
226
|
+
accessModifier: 'private',
|
|
227
|
+
parameters: [kt.parameter('uriComponent', kt.refs.string())],
|
|
228
|
+
returnType: kt.refs.string(),
|
|
229
|
+
singleExpression: true,
|
|
230
|
+
body: s `${kt.refs.okhttp3.httpUrl()}.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0]`,
|
|
231
|
+
}),
|
|
232
|
+
];
|
|
233
|
+
}
|
|
234
|
+
getTypeUsage(ctx, args) {
|
|
235
|
+
const { schema, nullable, fallback } = args;
|
|
236
|
+
const type = this.getSchemaType(ctx, { schema });
|
|
237
|
+
return type
|
|
238
|
+
? createOverwriteProxy(type, { nullable: nullable !== null && nullable !== void 0 ? nullable : type.nullable })
|
|
239
|
+
: fallback !== null && fallback !== void 0 ? fallback : kt.refs.any({ nullable });
|
|
240
|
+
}
|
|
241
|
+
getPackageName(ctx, args) {
|
|
242
|
+
const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(ctx.service);
|
|
320
243
|
return ctx.config.packageName + packageSuffix;
|
|
321
244
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return nullable ? `${typeName}?` : typeName.match(/^(.*?)\??$/)[1];
|
|
326
|
-
}
|
|
327
|
-
getDefaultValue(ctx, schema) {
|
|
328
|
-
if (!(schema === null || schema === void 0 ? void 0 : schema.default)) {
|
|
329
|
-
return 'null';
|
|
330
|
-
}
|
|
331
|
-
if (typeof schema.default === 'string') {
|
|
332
|
-
return toKotlinStringLiteral(schema.default);
|
|
333
|
-
}
|
|
334
|
-
else if (typeof schema.default === 'number' || typeof schema.default === 'boolean') {
|
|
335
|
-
return schema.default.toString();
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
return 'null';
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
getPathWithInterpolation(ctx, endpoint) {
|
|
342
|
-
let path = this.getEndpointPath(ctx, endpoint);
|
|
245
|
+
getPathWithInterpolation(ctx, args) {
|
|
246
|
+
const { endpoint } = args;
|
|
247
|
+
let path = this.getEndpointPath(ctx, { endpoint });
|
|
343
248
|
endpoint.parameters
|
|
344
249
|
.filter((x) => x.target === 'path')
|
|
345
250
|
.forEach((parameter) => {
|
|
@@ -347,23 +252,26 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
347
252
|
});
|
|
348
253
|
return path;
|
|
349
254
|
}
|
|
350
|
-
getResponseSchema(ctx,
|
|
255
|
+
getResponseSchema(ctx, args) {
|
|
351
256
|
var _a, _b;
|
|
257
|
+
const { endpoint } = args;
|
|
352
258
|
return (_b = (_a = endpoint.responses.find((x) => !x.statusCode || (x.statusCode >= 200 && x.statusCode < 300))) === null || _a === void 0 ? void 0 : _a.contentOptions[0]) === null || _b === void 0 ? void 0 : _b.schema;
|
|
353
259
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
return
|
|
260
|
+
getSchemaType(ctx, args) {
|
|
261
|
+
const { schema } = args;
|
|
262
|
+
return schema && ctx.input.models[schema.id].type;
|
|
357
263
|
}
|
|
358
|
-
getAllParameters(ctx,
|
|
264
|
+
getAllParameters(ctx, args) {
|
|
265
|
+
const { endpoint } = args;
|
|
359
266
|
const parameters = endpoint.parameters.filter((parameter) => parameter.target === 'query' || parameter.target === 'path');
|
|
360
267
|
if (endpoint.requestBody) {
|
|
361
268
|
const schema = endpoint.requestBody.content[0].schema;
|
|
362
269
|
parameters.push({
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
363
271
|
$src: undefined,
|
|
364
272
|
$ref: undefined,
|
|
365
273
|
id: 'body',
|
|
366
|
-
name: this.getRequestBodyParamName(ctx, endpoint),
|
|
274
|
+
name: this.getRequestBodyParamName(ctx, { endpoint }),
|
|
367
275
|
target: 'body',
|
|
368
276
|
schema,
|
|
369
277
|
required: endpoint.requestBody.required,
|
|
@@ -377,42 +285,26 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
|
|
|
377
285
|
}
|
|
378
286
|
return parameters.sort((a, b) => (a.required === b.required ? 0 : a.required ? -1 : 1));
|
|
379
287
|
}
|
|
380
|
-
getRequestBodyParamName(ctx,
|
|
288
|
+
getRequestBodyParamName(ctx, args) {
|
|
381
289
|
var _a;
|
|
290
|
+
const { endpoint } = args;
|
|
382
291
|
const schema = (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema;
|
|
383
|
-
const schemaInfo = this.
|
|
384
|
-
return
|
|
292
|
+
const schemaInfo = this.getSchemaType(ctx, { schema });
|
|
293
|
+
return toCasing(schemaInfo && schemaInfo.name !== 'Any' ? SourceBuilder.build((b) => kt.reference.write(b, schemaInfo)) : 'body', ctx.config.parameterNameCasing);
|
|
385
294
|
}
|
|
386
|
-
getBasePath(ctx) {
|
|
295
|
+
getBasePath(ctx, args) {
|
|
387
296
|
var _a, _b, _c, _d, _e, _f;
|
|
388
297
|
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);
|
|
389
298
|
}
|
|
390
|
-
getEndpointPath(ctx,
|
|
299
|
+
getEndpointPath(ctx, args) {
|
|
300
|
+
const { endpoint } = args;
|
|
391
301
|
return modifyString(endpoint.path, ctx.config.pathModifier, endpoint);
|
|
392
302
|
}
|
|
393
|
-
getFilePath(ctx,
|
|
394
|
-
|
|
303
|
+
getFilePath(ctx, args) {
|
|
304
|
+
const { packageName } = args;
|
|
305
|
+
return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx, {})}.kt`;
|
|
395
306
|
}
|
|
396
|
-
getApiClientName(ctx) {
|
|
397
|
-
return toCasing(ctx.service.name,
|
|
307
|
+
getApiClientName(ctx, args) {
|
|
308
|
+
return toCasing(ctx.service.name, ctx.config.typeNameCasing) + 'ApiClient';
|
|
398
309
|
}
|
|
399
310
|
}
|
|
400
|
-
const responseErrorHandlingCode = `ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
|
|
401
|
-
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
|
|
402
|
-
ResponseType.ClientError -> {
|
|
403
|
-
val localVarError = localVarResponse as ClientError<*>
|
|
404
|
-
throw ClientException(
|
|
405
|
-
"Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
406
|
-
localVarError.statusCode,
|
|
407
|
-
localVarResponse
|
|
408
|
-
)
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
ResponseType.ServerError -> {
|
|
412
|
-
val localVarError = localVarResponse as ServerError<*>
|
|
413
|
-
throw ServerException(
|
|
414
|
-
"Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
|
|
415
|
-
localVarError.statusCode,
|
|
416
|
-
localVarResponse
|
|
417
|
-
)
|
|
418
|
-
}`;
|