@goast/kotlin 0.1.18 → 0.2.1

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