@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.
Files changed (179) hide show
  1. package/cjs/index.js +3 -0
  2. package/cjs/lib/ast/_index.js +81 -0
  3. package/cjs/lib/ast/common.js +2 -0
  4. package/cjs/lib/ast/index.js +5 -0
  5. package/cjs/lib/ast/node.js +10 -0
  6. package/cjs/lib/ast/nodes/annotation.js +39 -0
  7. package/cjs/lib/ast/nodes/argument.js +32 -0
  8. package/cjs/lib/ast/nodes/call.js +37 -0
  9. package/cjs/lib/ast/nodes/class.js +94 -0
  10. package/cjs/lib/ast/nodes/collection-literal.js +24 -0
  11. package/cjs/lib/ast/nodes/constructor.js +75 -0
  12. package/cjs/lib/ast/nodes/doc-tag.js +60 -0
  13. package/cjs/lib/ast/nodes/doc.js +55 -0
  14. package/cjs/lib/ast/nodes/enum-value.js +50 -0
  15. package/cjs/lib/ast/nodes/enum.js +83 -0
  16. package/cjs/lib/ast/nodes/function.js +105 -0
  17. package/cjs/lib/ast/nodes/generic-parameter.js +29 -0
  18. package/cjs/lib/ast/nodes/init-block.js +19 -0
  19. package/cjs/lib/ast/nodes/interface.js +68 -0
  20. package/cjs/lib/ast/nodes/lambda-type.js +44 -0
  21. package/cjs/lib/ast/nodes/lambda.js +36 -0
  22. package/cjs/lib/ast/nodes/object.js +58 -0
  23. package/cjs/lib/ast/nodes/parameter.js +57 -0
  24. package/cjs/lib/ast/nodes/property.js +142 -0
  25. package/cjs/lib/ast/nodes/reference.js +79 -0
  26. package/cjs/lib/ast/nodes/string.js +87 -0
  27. package/cjs/lib/ast/nodes/types.js +2 -0
  28. package/cjs/lib/ast/references/index.js +12 -0
  29. package/cjs/lib/ast/references/jackson.js +12 -0
  30. package/cjs/lib/ast/references/jakarta.js +10 -0
  31. package/cjs/lib/ast/references/java.js +14 -0
  32. package/cjs/lib/ast/references/kotlin.js +27 -0
  33. package/cjs/lib/ast/references/okhttp3.js +7 -0
  34. package/cjs/lib/ast/references/reactor.js +6 -0
  35. package/cjs/lib/ast/references/spring.js +21 -0
  36. package/cjs/lib/ast/references/swagger.js +11 -0
  37. package/cjs/lib/ast/utils/get-kotlin-builder-options.js +19 -0
  38. package/cjs/lib/ast/utils/to-kt-node.js +22 -0
  39. package/cjs/lib/ast/utils/write-kt-annotations.js +13 -0
  40. package/cjs/lib/ast/utils/write-kt-arguments.js +33 -0
  41. package/cjs/lib/ast/utils/write-kt-enum-values.js +17 -0
  42. package/cjs/lib/ast/utils/write-kt-generic-parameters.js +12 -0
  43. package/cjs/lib/ast/utils/write-kt-members.js +16 -0
  44. package/cjs/lib/ast/utils/write-kt-node.js +24 -0
  45. package/cjs/lib/ast/utils/write-kt-parameters.js +13 -0
  46. package/cjs/lib/config.js +15 -1
  47. package/cjs/lib/file-builder.js +17 -2
  48. package/cjs/lib/generators/models/args.js +2 -0
  49. package/cjs/lib/generators/models/index.js +2 -0
  50. package/cjs/lib/generators/models/model-generator.js +281 -322
  51. package/cjs/lib/generators/services/okhttp3-clients/args.js +2 -0
  52. package/cjs/lib/generators/services/okhttp3-clients/index.js +2 -0
  53. package/cjs/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +240 -348
  54. package/cjs/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
  55. package/cjs/lib/generators/services/okhttp3-clients/refs.js +34 -0
  56. package/cjs/lib/generators/services/spring-controllers/args.js +2 -0
  57. package/cjs/lib/generators/services/spring-controllers/index.js +2 -0
  58. package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +270 -346
  59. package/cjs/lib/import-collection.js +24 -15
  60. package/esm/index.js +3 -0
  61. package/esm/lib/ast/_index.js +27 -0
  62. package/esm/lib/ast/common.js +1 -0
  63. package/esm/lib/ast/index.js +2 -0
  64. package/esm/lib/ast/node.js +6 -0
  65. package/esm/lib/ast/nodes/annotation.js +35 -0
  66. package/esm/lib/ast/nodes/argument.js +28 -0
  67. package/esm/lib/ast/nodes/call.js +33 -0
  68. package/esm/lib/ast/nodes/class.js +90 -0
  69. package/esm/lib/ast/nodes/collection-literal.js +20 -0
  70. package/esm/lib/ast/nodes/constructor.js +71 -0
  71. package/esm/lib/ast/nodes/doc-tag.js +56 -0
  72. package/esm/lib/ast/nodes/doc.js +51 -0
  73. package/esm/lib/ast/nodes/enum-value.js +46 -0
  74. package/esm/lib/ast/nodes/enum.js +79 -0
  75. package/esm/lib/ast/nodes/function.js +101 -0
  76. package/esm/lib/ast/nodes/generic-parameter.js +25 -0
  77. package/esm/lib/ast/nodes/init-block.js +15 -0
  78. package/esm/lib/ast/nodes/interface.js +64 -0
  79. package/esm/lib/ast/nodes/lambda-type.js +40 -0
  80. package/esm/lib/ast/nodes/lambda.js +32 -0
  81. package/esm/lib/ast/nodes/object.js +54 -0
  82. package/esm/lib/ast/nodes/parameter.js +53 -0
  83. package/esm/lib/ast/nodes/property.js +135 -0
  84. package/esm/lib/ast/nodes/reference.js +75 -0
  85. package/esm/lib/ast/nodes/string.js +83 -0
  86. package/esm/lib/ast/nodes/types.js +1 -0
  87. package/esm/lib/ast/references/index.js +15 -0
  88. package/esm/lib/ast/references/jackson.js +9 -0
  89. package/esm/lib/ast/references/jakarta.js +7 -0
  90. package/esm/lib/ast/references/java.js +11 -0
  91. package/esm/lib/ast/references/kotlin.js +24 -0
  92. package/esm/lib/ast/references/okhttp3.js +4 -0
  93. package/esm/lib/ast/references/reactor.js +3 -0
  94. package/esm/lib/ast/references/spring.js +18 -0
  95. package/esm/lib/ast/references/swagger.js +8 -0
  96. package/esm/lib/ast/utils/get-kotlin-builder-options.js +15 -0
  97. package/esm/lib/ast/utils/to-kt-node.js +18 -0
  98. package/esm/lib/ast/utils/write-kt-annotations.js +9 -0
  99. package/esm/lib/ast/utils/write-kt-arguments.js +29 -0
  100. package/esm/lib/ast/utils/write-kt-enum-values.js +13 -0
  101. package/esm/lib/ast/utils/write-kt-generic-parameters.js +8 -0
  102. package/esm/lib/ast/utils/write-kt-members.js +12 -0
  103. package/esm/lib/ast/utils/write-kt-node.js +19 -0
  104. package/esm/lib/ast/utils/write-kt-parameters.js +9 -0
  105. package/esm/lib/config.js +15 -1
  106. package/esm/lib/file-builder.js +16 -2
  107. package/esm/lib/generators/models/args.js +1 -0
  108. package/esm/lib/generators/models/index.js +2 -0
  109. package/esm/lib/generators/models/model-generator.js +282 -323
  110. package/esm/lib/generators/services/okhttp3-clients/args.js +1 -0
  111. package/esm/lib/generators/services/okhttp3-clients/index.js +2 -0
  112. package/esm/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +242 -350
  113. package/esm/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
  114. package/esm/lib/generators/services/okhttp3-clients/refs.js +30 -0
  115. package/esm/lib/generators/services/spring-controllers/args.js +1 -0
  116. package/esm/lib/generators/services/spring-controllers/index.js +2 -0
  117. package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +269 -346
  118. package/esm/lib/import-collection.js +23 -14
  119. package/package.json +6 -6
  120. package/types/index.d.ts +2 -0
  121. package/types/lib/ast/_index.d.ts +28 -0
  122. package/types/lib/ast/common.d.ts +1 -0
  123. package/types/lib/ast/index.d.ts +1 -0
  124. package/types/lib/ast/node.d.ts +4 -0
  125. package/types/lib/ast/nodes/annotation.d.ts +23 -0
  126. package/types/lib/ast/nodes/argument.d.ts +22 -0
  127. package/types/lib/ast/nodes/call.d.ts +22 -0
  128. package/types/lib/ast/nodes/class.d.ts +54 -0
  129. package/types/lib/ast/nodes/collection-literal.d.ts +17 -0
  130. package/types/lib/ast/nodes/constructor.d.ts +34 -0
  131. package/types/lib/ast/nodes/doc-tag.d.ts +34 -0
  132. package/types/lib/ast/nodes/doc.d.ts +26 -0
  133. package/types/lib/ast/nodes/enum-value.d.ts +30 -0
  134. package/types/lib/ast/nodes/enum.d.ts +45 -0
  135. package/types/lib/ast/nodes/function.d.ts +58 -0
  136. package/types/lib/ast/nodes/generic-parameter.d.ts +21 -0
  137. package/types/lib/ast/nodes/init-block.d.ts +16 -0
  138. package/types/lib/ast/nodes/interface.d.ts +41 -0
  139. package/types/lib/ast/nodes/lambda-type.d.ts +21 -0
  140. package/types/lib/ast/nodes/lambda.d.ts +20 -0
  141. package/types/lib/ast/nodes/object.d.ts +34 -0
  142. package/types/lib/ast/nodes/parameter.d.ts +48 -0
  143. package/types/lib/ast/nodes/property.d.ts +87 -0
  144. package/types/lib/ast/nodes/reference.d.ts +63 -0
  145. package/types/lib/ast/nodes/string.d.ts +30 -0
  146. package/types/lib/ast/nodes/types.d.ts +10 -0
  147. package/types/lib/ast/references/index.d.ts +8 -0
  148. package/types/lib/ast/references/jackson.d.ts +77 -0
  149. package/types/lib/ast/references/jakarta.d.ts +33 -0
  150. package/types/lib/ast/references/java.d.ts +71 -0
  151. package/types/lib/ast/references/kotlin.d.ts +265 -0
  152. package/types/lib/ast/references/okhttp3.d.ts +22 -0
  153. package/types/lib/ast/references/reactor.d.ts +16 -0
  154. package/types/lib/ast/references/spring.d.ts +126 -0
  155. package/types/lib/ast/references/swagger.d.ts +44 -0
  156. package/types/lib/ast/utils/get-kotlin-builder-options.d.ts +3 -0
  157. package/types/lib/ast/utils/to-kt-node.d.ts +7 -0
  158. package/types/lib/ast/utils/write-kt-annotations.d.ts +5 -0
  159. package/types/lib/ast/utils/write-kt-arguments.d.ts +3 -0
  160. package/types/lib/ast/utils/write-kt-enum-values.d.ts +3 -0
  161. package/types/lib/ast/utils/write-kt-generic-parameters.d.ts +3 -0
  162. package/types/lib/ast/utils/write-kt-members.d.ts +5 -0
  163. package/types/lib/ast/utils/write-kt-node.d.ts +7 -0
  164. package/types/lib/ast/utils/write-kt-parameters.d.ts +3 -0
  165. package/types/lib/config.d.ts +4 -0
  166. package/types/lib/file-builder.d.ts +10 -3
  167. package/types/lib/generators/models/args.d.ts +99 -0
  168. package/types/lib/generators/models/index.d.ts +1 -0
  169. package/types/lib/generators/models/model-generator.d.ts +35 -32
  170. package/types/lib/generators/models/models.d.ts +4 -4
  171. package/types/lib/generators/services/okhttp3-clients/args.d.ts +66 -0
  172. package/types/lib/generators/services/okhttp3-clients/index.d.ts +1 -0
  173. package/types/lib/generators/services/okhttp3-clients/models.d.ts +2 -0
  174. package/types/lib/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +25 -47
  175. package/types/lib/generators/services/okhttp3-clients/refs.d.ts +235 -0
  176. package/types/lib/generators/services/spring-controllers/args.d.ts +70 -0
  177. package/types/lib/generators/services/spring-controllers/index.d.ts +1 -0
  178. package/types/lib/generators/services/spring-controllers/spring-controller-generator.d.ts +37 -51
  179. 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, toKotlinStringLiteral } from '../../../utils';
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, ctx.service);
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.generateApiClientFileContent(ctx, builder);
18
+ builder.append(this.getClientFileContent(ctx, {}));
17
19
  writeFileSync(filePath, builder.toString());
18
20
  return { typeName, packageName };
19
21
  }
20
- generateApiClientFileContent(ctx, builder) {
21
- builder
22
- .append((builder) => this.generateApiClientClassAnnotations(ctx, builder))
23
- .ensureCurrentLineEmpty()
24
- .append((builder) => this.generateApiClientClassSignature(ctx, builder))
25
- .append(' ')
26
- .parenthesize('{}', (builder) => this.generateApiClientClassContent(ctx, builder), { multiline: true });
27
- }
28
- generateApiClientClassAnnotations(ctx, builder) {
29
- // None for now
30
- }
31
- generateApiClientClassSignature(ctx, builder) {
32
- builder
33
- .append('class ')
34
- .append(this.getApiClientName(ctx))
35
- .parenthesize('()', (builder) => builder
36
- .appendLine('basePath: String = defaultBasePath,')
37
- .appendLine('client: OkHttpClient = ApiClient.defaultClient')
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
- generateApiClientMethodDocumentation(ctx, builder, endpoint) {
85
- builder
86
- .appendLine('/**')
87
- .appendWithLinePrefix(' * ', (builder) => {
88
- var _a;
89
- return builder
90
- .appendLine(`${(_a = endpoint.summary) !== null && _a !== void 0 ? _a : 'TODO: Provide summary'}`)
91
- .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
92
- .append('@return ')
93
- .append((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint))
94
- .appendLine()
95
- .appendLine('@throws IllegalStateException If the request is not correctly configured')
96
- .appendLine('@throws IOException Rethrows the OkHttp execute method exception')
97
- .appendLine('@throws UnsupportedOperationException If the API returns an informational or redirection response')
98
- .appendLine('@throws ClientException If the API returns a client error response')
99
- .appendLine('@throws ServerException If the API returns a server error response');
100
- })
101
- .appendLine(' */');
102
- }
103
- generateApiClientMethodAnnotations(ctx, builder, endpoint) {
104
- builder
105
- .appendAnnotation('Throws', undefined, [
106
- 'IllegalStateException::class',
107
- 'IOException::class',
108
- 'UnsupportedOperationException::class',
109
- 'ClientException::class',
110
- 'ServerException::class',
111
- ])
112
- .addImport('IOException', 'java.io')
113
- .addImport('ClientException', ctx.infrastructurePackageName)
114
- .addImport('ServerException', ctx.infrastructurePackageName);
115
- }
116
- generateApiClientMethodSignature(ctx, builder, endpoint) {
117
- builder
118
- .append('fun ')
119
- .append(toCasing(endpoint.name, 'camel'))
120
- .parenthesize('()', (builder) => this.generateApiClientMethodParameters(ctx, builder, endpoint))
121
- .append(': ')
122
- .append((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint));
123
- }
124
- generateApiClientMethodParameters(ctx, builder, endpoint) {
125
- this.generateParams(ctx, builder, endpoint, true);
126
- }
127
- generateApiClientMethodReturnType(ctx, builder, endpoint) {
128
- this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit');
129
- }
130
- generateApiClientMethodContent(ctx, builder, endpoint) {
131
- const responseSchema = this.getResponseSchema(ctx, endpoint);
132
- builder
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
- generateApiClientHttpInfoMethodDocumentation(ctx, builder, endpoint) {
163
- builder
164
- .appendLine('/**')
165
- .appendWithLinePrefix(' * ', (builder) => {
166
- var _a;
167
- return builder
168
- .appendLine(`${(_a = endpoint.summary) !== null && _a !== void 0 ? _a : 'TODO: Provide summary'}`)
169
- .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
170
- .append('@return ')
171
- .append((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint))
172
- .appendLine()
173
- .appendLine('@throws IllegalStateException If the request is not correctly configured')
174
- .appendLine('@throws IOException Rethrows the OkHttp execute method exception')
175
- .appendLine('@throws UnsupportedOperationException If the API returns an informational or redirection response')
176
- .appendLine('@throws ClientException If the API returns a client error response')
177
- .appendLine('@throws ServerException If the API returns a server error response');
178
- })
179
- .appendLine(' */');
180
- }
181
- generateApiClientHttpInfoMethodAnnotations(ctx, builder, endpoint) {
182
- builder
183
- .appendAnnotation('Throws', undefined, ['IllegalStateException::class', 'IOException::class'])
184
- .addImport('IOException', 'java.io');
185
- }
186
- generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint) {
187
- builder
188
- .append('fun ')
189
- .append(toCasing(endpoint.name, 'camel'), 'WithHttpInfo')
190
- .parenthesize('()', (builder) => this.generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint))
191
- .append(': ')
192
- .append((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint));
193
- }
194
- generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint) {
195
- this.generateParams(ctx, builder, endpoint, true);
196
- }
197
- generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint) {
198
- builder
199
- .append('ApiResponse')
200
- .addImport('ApiResponse', ctx.infrastructurePackageName)
201
- .parenthesize('<>', (builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit', true));
202
- }
203
- generateApiClientHttpInfoMethodContent(ctx, builder, endpoint) {
204
- builder
205
- .append(`val localVariableConfig = ${toCasing(endpoint.name, 'camel')}RequestConfig`)
206
- .parenthesize('()', (builder) => this.generateParams(ctx, builder, endpoint, false))
207
- .appendLine()
208
- .appendLine()
209
- .append('return request')
210
- .parenthesize('<>', (builder) => builder
211
- .append((builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); })
212
- .append(', ')
213
- .append((builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit')))
214
- .parenthesize('()', (builder) => builder.append('localVariableConfig'), { multiline: true });
215
- }
216
- generateApiClientRequestConfigMethod(ctx, builder, endpoint) {
217
- builder
218
- .append((builder) => this.generateApiClientRequestConfigMethodDocumentation(ctx, builder, endpoint))
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
- generateApiClientRequestConfigMethodDocumentation(ctx, builder, endpoint) {
229
- builder
230
- .appendLine('/**')
231
- .appendWithLinePrefix(' * ', (builder) => builder
232
- .appendLine(`To obtain the request config of the operation ${toCasing(endpoint.name, 'camel')}`)
233
- .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
234
- .append('@return RequestConfig'))
235
- .appendLine(' */');
236
- }
237
- generateApiClientRequestConfigMethodAnnotations(ctx, builder, endpoint) {
238
- // No annotations needed
239
- }
240
- generateApiClientRequestConfigMethodSignature(ctx, builder, endpoint) {
241
- builder
242
- .append('private fun ')
243
- .append(toCasing(endpoint.name, 'camel'), 'RequestConfig')
244
- .parenthesize('()', (builder) => this.generateApiClientRequestConfigMethodSignatureParameters(ctx, builder, endpoint))
245
- .append(': ')
246
- .append((builder) => this.generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint));
247
- }
248
- generateApiClientRequestConfigMethodSignatureParameters(ctx, builder, endpoint) {
249
- this.generateParams(ctx, builder, endpoint, true);
250
- }
251
- generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint) {
252
- builder
253
- .append('RequestConfig')
254
- .addImport('RequestConfig', ctx.infrastructurePackageName)
255
- .parenthesize('<>', (builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); });
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
- generateApiClientRequestConfigMethodContent(ctx, builder, endpoint) {
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
- builder
261
- .appendLineIf(!!endpoint.requestBody, `val localVariableBody = ${toCasing(this.getRequestBodyParamName(ctx, endpoint), 'camel')}`)
262
- .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf<String, List<String>>()')
263
- .addImport('MultiValueMap', ctx.infrastructurePackageName)
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
- else {
315
- builder.append(this.getTypeNameWithNullability(fallback, nullable));
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
- getPackageName(ctx, service) {
319
- const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(service);
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
- getTypeNameWithNullability(typeName, nullable) {
323
- if (nullable === undefined)
324
- return typeName;
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, endpoint) {
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
- getSchemaInfo(ctx, schema) {
355
- var _a;
356
- return ((_a = (schema && ctx.input.models[schema.id])) !== null && _a !== void 0 ? _a : { typeName: 'Any?', packageName: undefined, additionalImports: [] });
260
+ getSchemaType(ctx, args) {
261
+ const { schema } = args;
262
+ return schema && ctx.input.models[schema.id].type;
357
263
  }
358
- getAllParameters(ctx, endpoint) {
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, endpoint) {
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.getSchemaInfo(ctx, schema);
384
- return /^Any\??$/.test(schemaInfo.typeName) ? 'body' : schemaInfo.typeName;
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, endpoint) {
299
+ getEndpointPath(ctx, args) {
300
+ const { endpoint } = args;
391
301
  return modifyString(endpoint.path, ctx.config.pathModifier, endpoint);
392
302
  }
393
- getFilePath(ctx, packageName) {
394
- return `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${this.getApiClientName(ctx)}.kt`;
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, 'pascal') + 'ApiClient';
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
- }`;