@goast/kotlin 0.5.11-beta.2 → 0.5.11

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 (96) hide show
  1. package/LICENSE +21 -21
  2. package/assets/client/okhttp3/ApiAbstractions.kt +30 -30
  3. package/assets/client/okhttp3/ApiClient.kt +252 -252
  4. package/assets/client/okhttp3/ApiResponse.kt +43 -43
  5. package/assets/client/okhttp3/Errors.kt +21 -21
  6. package/assets/client/okhttp3/PartConfig.kt +11 -11
  7. package/assets/client/okhttp3/RequestConfig.kt +18 -18
  8. package/assets/client/okhttp3/RequestMethod.kt +8 -8
  9. package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
  10. package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
  11. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
  12. package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +9 -9
  13. package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +9 -9
  14. package/package.json +1 -1
  15. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
  16. package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +9 -9
  17. package/script/src/generators/services/spring-controllers/spring-controller-generator.js +9 -9
  18. package/src/mod.ts +8 -0
  19. package/src/src/assets.ts +9 -0
  20. package/src/src/ast/_index.ts +66 -0
  21. package/src/src/ast/common.ts +1 -0
  22. package/src/src/ast/index.ts +1 -0
  23. package/src/src/ast/node.ts +10 -0
  24. package/src/src/ast/nodes/annotation.ts +79 -0
  25. package/src/src/ast/nodes/argument.ts +62 -0
  26. package/src/src/ast/nodes/call.ts +75 -0
  27. package/src/src/ast/nodes/class.ts +178 -0
  28. package/src/src/ast/nodes/collection-literal.ts +49 -0
  29. package/src/src/ast/nodes/constructor.ts +126 -0
  30. package/src/src/ast/nodes/doc-tag.ts +138 -0
  31. package/src/src/ast/nodes/doc.ts +111 -0
  32. package/src/src/ast/nodes/enum-value.ts +100 -0
  33. package/src/src/ast/nodes/enum.ts +163 -0
  34. package/src/src/ast/nodes/function.ts +178 -0
  35. package/src/src/ast/nodes/generic-parameter.ts +54 -0
  36. package/src/src/ast/nodes/init-block.ts +38 -0
  37. package/src/src/ast/nodes/interface.ts +133 -0
  38. package/src/src/ast/nodes/lambda-type.ts +73 -0
  39. package/src/src/ast/nodes/lambda.ts +74 -0
  40. package/src/src/ast/nodes/object.ts +102 -0
  41. package/src/src/ast/nodes/parameter.ts +118 -0
  42. package/src/src/ast/nodes/property.ts +225 -0
  43. package/src/src/ast/nodes/reference.ts +178 -0
  44. package/src/src/ast/nodes/string.ts +114 -0
  45. package/src/src/ast/nodes/types.ts +23 -0
  46. package/src/src/ast/references/index.ts +10 -0
  47. package/src/src/ast/references/jackson.ts +59 -0
  48. package/src/src/ast/references/jakarta.ts +14 -0
  49. package/src/src/ast/references/java.ts +27 -0
  50. package/src/src/ast/references/kotlin.ts +41 -0
  51. package/src/src/ast/references/kotlinx.ts +14 -0
  52. package/src/src/ast/references/okhttp3.ts +5 -0
  53. package/src/src/ast/references/reactor.ts +5 -0
  54. package/src/src/ast/references/spring-reactive.ts +37 -0
  55. package/src/src/ast/references/spring.ts +86 -0
  56. package/src/src/ast/references/swagger.ts +23 -0
  57. package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
  58. package/src/src/ast/utils/to-kt-node.ts +31 -0
  59. package/src/src/ast/utils/write-kt-annotations.ts +15 -0
  60. package/src/src/ast/utils/write-kt-arguments.ts +45 -0
  61. package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
  62. package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
  63. package/src/src/ast/utils/write-kt-members.ts +25 -0
  64. package/src/src/ast/utils/write-kt-node.ts +37 -0
  65. package/src/src/ast/utils/write-kt-parameters.ts +25 -0
  66. package/src/src/common-results.ts +4 -0
  67. package/src/src/config.ts +61 -0
  68. package/src/src/file-builder.ts +112 -0
  69. package/src/src/generators/file-generator.ts +29 -0
  70. package/src/src/generators/index.ts +5 -0
  71. package/src/src/generators/models/args.ts +136 -0
  72. package/src/src/generators/models/index.ts +4 -0
  73. package/src/src/generators/models/model-generator.ts +725 -0
  74. package/src/src/generators/models/models-generator.ts +65 -0
  75. package/src/src/generators/models/models.ts +95 -0
  76. package/src/src/generators/services/okhttp3-clients/args.ts +90 -0
  77. package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
  78. package/src/src/generators/services/okhttp3-clients/models.ts +73 -0
  79. package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +613 -0
  80. package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +188 -0
  81. package/src/src/generators/services/okhttp3-clients/refs.ts +59 -0
  82. package/src/src/generators/services/spring-controllers/args.ts +95 -0
  83. package/src/src/generators/services/spring-controllers/index.ts +4 -0
  84. package/src/src/generators/services/spring-controllers/models.ts +76 -0
  85. package/src/src/generators/services/spring-controllers/refs.ts +17 -0
  86. package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1109 -0
  87. package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -0
  88. package/src/src/generators/services/spring-reactive-web-clients/args.ts +103 -0
  89. package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
  90. package/src/src/generators/services/spring-reactive-web-clients/models.ts +62 -0
  91. package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
  92. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +579 -0
  93. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -0
  94. package/src/src/import-collection.ts +98 -0
  95. package/src/src/types.ts +3 -0
  96. package/src/src/utils.ts +47 -0
@@ -1,43 +1,43 @@
1
- package @PACKAGE_NAME@
2
-
3
- enum class ResponseType {
4
- Success, Informational, Redirection, ClientError, ServerError
5
- }
6
-
7
- interface Response
8
-
9
- abstract class ApiResponse<T>(val responseType: ResponseType) : Response {
10
- abstract val statusCode: Int
11
- abstract val headers: Map<String, List<String>>
12
- }
13
-
14
- class Success<T>(
15
- val data: T,
16
- override val statusCode: Int = -1,
17
- override val headers: Map<String, List<String>> = mapOf()
18
- ) : ApiResponse<T>(ResponseType.Success)
19
-
20
- class Informational<T>(
21
- val statusText: String,
22
- override val statusCode: Int = -1,
23
- override val headers: Map<String, List<String>> = mapOf()
24
- ) : ApiResponse<T>(ResponseType.Informational)
25
-
26
- class Redirection<T>(
27
- override val statusCode: Int = -1,
28
- override val headers: Map<String, List<String>> = mapOf()
29
- ) : ApiResponse<T>(ResponseType.Redirection)
30
-
31
- class ClientError<T>(
32
- val message: String? = null,
33
- val body: Any? = null,
34
- override val statusCode: Int = -1,
35
- override val headers: Map<String, List<String>> = mapOf()
36
- ) : ApiResponse<T>(ResponseType.ClientError)
37
-
38
- class ServerError<T>(
39
- val message: String? = null,
40
- val body: Any? = null,
41
- override val statusCode: Int = -1,
42
- override val headers: Map<String, List<String>>
43
- ) : ApiResponse<T>(ResponseType.ServerError)
1
+ package @PACKAGE_NAME@
2
+
3
+ enum class ResponseType {
4
+ Success, Informational, Redirection, ClientError, ServerError
5
+ }
6
+
7
+ interface Response
8
+
9
+ abstract class ApiResponse<T>(val responseType: ResponseType) : Response {
10
+ abstract val statusCode: Int
11
+ abstract val headers: Map<String, List<String>>
12
+ }
13
+
14
+ class Success<T>(
15
+ val data: T,
16
+ override val statusCode: Int = -1,
17
+ override val headers: Map<String, List<String>> = mapOf()
18
+ ) : ApiResponse<T>(ResponseType.Success)
19
+
20
+ class Informational<T>(
21
+ val statusText: String,
22
+ override val statusCode: Int = -1,
23
+ override val headers: Map<String, List<String>> = mapOf()
24
+ ) : ApiResponse<T>(ResponseType.Informational)
25
+
26
+ class Redirection<T>(
27
+ override val statusCode: Int = -1,
28
+ override val headers: Map<String, List<String>> = mapOf()
29
+ ) : ApiResponse<T>(ResponseType.Redirection)
30
+
31
+ class ClientError<T>(
32
+ val message: String? = null,
33
+ val body: Any? = null,
34
+ override val statusCode: Int = -1,
35
+ override val headers: Map<String, List<String>> = mapOf()
36
+ ) : ApiResponse<T>(ResponseType.ClientError)
37
+
38
+ class ServerError<T>(
39
+ val message: String? = null,
40
+ val body: Any? = null,
41
+ override val statusCode: Int = -1,
42
+ override val headers: Map<String, List<String>>
43
+ ) : ApiResponse<T>(ResponseType.ServerError)
@@ -1,21 +1,21 @@
1
- @file:Suppress("unused")
2
-
3
- package @PACKAGE_NAME@
4
-
5
- import java.lang.RuntimeException
6
-
7
- open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) :
8
- RuntimeException(message) {
9
-
10
- companion object {
11
- private const val serialVersionUID: Long = 123L
12
- }
13
- }
14
-
15
- open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) :
16
- RuntimeException(message) {
17
-
18
- companion object {
19
- private const val serialVersionUID: Long = 456L
20
- }
21
- }
1
+ @file:Suppress("unused")
2
+
3
+ package @PACKAGE_NAME@
4
+
5
+ import java.lang.RuntimeException
6
+
7
+ open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) :
8
+ RuntimeException(message) {
9
+
10
+ companion object {
11
+ private const val serialVersionUID: Long = 123L
12
+ }
13
+ }
14
+
15
+ open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) :
16
+ RuntimeException(message) {
17
+
18
+ companion object {
19
+ private const val serialVersionUID: Long = 456L
20
+ }
21
+ }
@@ -1,11 +1,11 @@
1
- package @PACKAGE_NAME@
2
-
3
- /**
4
- * Defines a config object for a given part of a multi-part request.
5
- * NOTE: Headers is a Map<String,String> because rfc2616 defines
6
- * multi-valued headers as csv-only.
7
- */
8
- data class PartConfig<T>(
9
- val headers: MutableMap<String, String> = mutableMapOf(),
10
- val body: T? = null
11
- )
1
+ package @PACKAGE_NAME@
2
+
3
+ /**
4
+ * Defines a config object for a given part of a multi-part request.
5
+ * NOTE: Headers is a Map<String,String> because rfc2616 defines
6
+ * multi-valued headers as csv-only.
7
+ */
8
+ data class PartConfig<T>(
9
+ val headers: MutableMap<String, String> = mutableMapOf(),
10
+ val body: T? = null
11
+ )
@@ -1,18 +1,18 @@
1
- package @PACKAGE_NAME@
2
-
3
- /**
4
- * Defines a config object for a given request.
5
- * NOTE: This object doesn't include 'body' because it
6
- * allows for caching of the constructed object
7
- * for many request definitions.
8
- * NOTE: Headers is a Map<String,String> because rfc2616 defines
9
- * multi-valued headers as csv-only.
10
- */
11
- data class RequestConfig<T>(
12
- val method: RequestMethod,
13
- val path: String,
14
- val headers: MutableMap<String, String> = mutableMapOf(),
15
- val query: MutableMap<String, List<String>> = mutableMapOf(),
16
- val requiresAuthentication: Boolean,
17
- val body: T? = null
18
- )
1
+ package @PACKAGE_NAME@
2
+
3
+ /**
4
+ * Defines a config object for a given request.
5
+ * NOTE: This object doesn't include 'body' because it
6
+ * allows for caching of the constructed object
7
+ * for many request definitions.
8
+ * NOTE: Headers is a Map<String,String> because rfc2616 defines
9
+ * multi-valued headers as csv-only.
10
+ */
11
+ data class RequestConfig<T>(
12
+ val method: RequestMethod,
13
+ val path: String,
14
+ val headers: MutableMap<String, String> = mutableMapOf(),
15
+ val query: MutableMap<String, List<String>> = mutableMapOf(),
16
+ val requiresAuthentication: Boolean,
17
+ val body: T? = null
18
+ )
@@ -1,8 +1,8 @@
1
- package @PACKAGE_NAME@
2
-
3
- /**
4
- * Provides enumerated HTTP verbs
5
- */
6
- enum class RequestMethod {
7
- GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
8
- }
1
+ package @PACKAGE_NAME@
2
+
3
+ /**
4
+ * Provides enumerated HTTP verbs
5
+ */
6
+ enum class RequestMethod {
7
+ GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
8
+ }
@@ -1,24 +1,24 @@
1
- package @PACKAGE_NAME@
2
-
3
- import okhttp3.Response
4
-
5
- /**
6
- * Provides an extension to evaluation whether the response is a 1xx code
7
- */
8
- val Response.isInformational: Boolean get() = this.code in 100..199
9
-
10
- /**
11
- * Provides an extension to evaluation whether the response is a 3xx code
12
- */
13
- @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
14
- val Response.isRedirect: Boolean get() = this.code in 300..399
15
-
16
- /**
17
- * Provides an extension to evaluation whether the response is a 4xx code
18
- */
19
- val Response.isClientError: Boolean get() = this.code in 400..499
20
-
21
- /**
22
- * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
23
- */
24
- val Response.isServerError: Boolean get() = this.code in 500..999
1
+ package @PACKAGE_NAME@
2
+
3
+ import okhttp3.Response
4
+
5
+ /**
6
+ * Provides an extension to evaluation whether the response is a 1xx code
7
+ */
8
+ val Response.isInformational: Boolean get() = this.code in 100..199
9
+
10
+ /**
11
+ * Provides an extension to evaluation whether the response is a 3xx code
12
+ */
13
+ @Suppress("EXTENSION_SHADOWED_BY_MEMBER")
14
+ val Response.isRedirect: Boolean get() = this.code in 300..399
15
+
16
+ /**
17
+ * Provides an extension to evaluation whether the response is a 4xx code
18
+ */
19
+ val Response.isClientError: Boolean get() = this.code in 400..499
20
+
21
+ /**
22
+ * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
23
+ */
24
+ val Response.isServerError: Boolean get() = this.code in 500..999
@@ -1,33 +1,33 @@
1
- package @PACKAGE_NAME@
2
-
3
- import org.springframework.core.io.buffer.DataBuffer
4
- import org.springframework.http.MediaType
5
- import org.springframework.http.client.MultipartBodyBuilder
6
- import org.springframework.http.codec.multipart.FilePart
7
- import java.io.File
8
-
9
- interface ApiRequestFile {
10
- companion object {
11
- fun from(file: File): ApiRequestFile =
12
- object : ApiRequestFile {
13
- override fun addToBuilder(builder: MultipartBodyBuilder) {
14
- builder
15
- .part("file", file)
16
- .filename(file.name)
17
- .contentType(MediaType.APPLICATION_OCTET_STREAM)
18
- }
19
- }
20
-
21
- fun from(filePart: FilePart): ApiRequestFile =
22
- object : ApiRequestFile {
23
- override fun addToBuilder(builder: MultipartBodyBuilder) {
24
- builder
25
- .asyncPart("file", filePart.content(), DataBuffer::class.java)
26
- .filename(filePart.filename())
27
- .contentType(filePart.headers().contentType ?: MediaType.APPLICATION_OCTET_STREAM)
28
- }
29
- }
30
- }
31
-
32
- fun addToBuilder(builder: MultipartBodyBuilder)
33
- }
1
+ package @PACKAGE_NAME@
2
+
3
+ import org.springframework.core.io.buffer.DataBuffer
4
+ import org.springframework.http.MediaType
5
+ import org.springframework.http.client.MultipartBodyBuilder
6
+ import org.springframework.http.codec.multipart.FilePart
7
+ import java.io.File
8
+
9
+ interface ApiRequestFile {
10
+ companion object {
11
+ fun from(file: File): ApiRequestFile =
12
+ object : ApiRequestFile {
13
+ override fun addToBuilder(builder: MultipartBodyBuilder) {
14
+ builder
15
+ .part("file", file)
16
+ .filename(file.name)
17
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
18
+ }
19
+ }
20
+
21
+ fun from(filePart: FilePart): ApiRequestFile =
22
+ object : ApiRequestFile {
23
+ override fun addToBuilder(builder: MultipartBodyBuilder) {
24
+ builder
25
+ .asyncPart("file", filePart.content(), DataBuffer::class.java)
26
+ .filename(filePart.filename())
27
+ .contentType(filePart.headers().contentType ?: MediaType.APPLICATION_OCTET_STREAM)
28
+ }
29
+ }
30
+ }
31
+
32
+ fun addToBuilder(builder: MultipartBodyBuilder)
33
+ }
@@ -109,31 +109,31 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
109
109
  return appendValueGroup([
110
110
  s `val localVarResponse = ${kt.call([toCasing(endpoint.name + '_WithHttpInfo', ctx.config.functionNameCasing)], parameters.map((x) => toCasing(x.name, ctx.config.parameterNameCasing)))}`,
111
111
  '',
112
- s `return when (localVarResponse.responseType) {${s.indent `
112
+ s `return when (localVarResponse.responseType) {${s.indent `
113
113
  ${ctx.refs.responseType()}.Success -> ${responseSchema === undefined
114
114
  ? kt.refs.unit()
115
115
  : s `(localVarResponse as ${ctx.refs.success(['*'])}).data as ${this.getTypeUsage(ctx, {
116
116
  schema: responseSchema,
117
- })}`}
118
- ${ctx.refs.responseType()}.Informational -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
119
- ${ctx.refs.responseType()}.Redirection -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
120
- ${ctx.refs.responseType()}.ClientError -> {${s.indent `
121
- val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
122
- throw ${ctx.refs.clientException()}(${s.indent `
123
- "Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
124
- localVarError.statusCode,
125
- localVarResponse`}
126
- )`}
127
- }
128
-
129
- ${ctx.refs.responseType()}.ServerError -> {${s.indent `
130
- val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
131
- throw ${ctx.refs.serverException()}(${s.indent `
132
- "Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
133
- localVarError.statusCode,
134
- localVarResponse`}
135
- )`}
136
- }`}
117
+ })}`}
118
+ ${ctx.refs.responseType()}.Informational -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
119
+ ${ctx.refs.responseType()}.Redirection -> throw ${kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
120
+ ${ctx.refs.responseType()}.ClientError -> {${s.indent `
121
+ val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
122
+ throw ${ctx.refs.clientException()}(${s.indent `
123
+ "Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
124
+ localVarError.statusCode,
125
+ localVarResponse`}
126
+ )`}
127
+ }
128
+
129
+ ${ctx.refs.responseType()}.ServerError -> {${s.indent `
130
+ val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
131
+ throw ${ctx.refs.serverException()}(${s.indent `
132
+ "Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
133
+ localVarError.statusCode,
134
+ localVarResponse`}
135
+ )`}
136
+ }`}
137
137
  }`,
138
138
  ], '\n');
139
139
  }
@@ -212,16 +212,16 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
212
212
  result.values.push(`val localVariableBody = ${bodyParamName}`);
213
213
  }
214
214
  }
215
- 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 ? '' : s.indent `
216
- .apply {${s.indent `
215
+ 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 ? '' : s.indent `
216
+ .apply {${s.indent `
217
217
  ${appendValueGroup(queryParameters.map((param) => {
218
218
  const paramName = toCasing(param.name, ctx.config.parameterNameCasing);
219
219
  const toString = this.getParameterToString(ctx, { endpoint, parameter: param });
220
220
  const put = s `put(${kt.string(param.name)}, listOf(${paramName}${toString}))`;
221
- return param.required ? put : s `if (${paramName} != null) {${s.indent `
222
- ${put}`}
221
+ return param.required ? put : s `if (${paramName} != null) {${s.indent `
222
+ ${put}`}
223
223
  }`;
224
- }), '\n')}`}
224
+ }), '\n')}`}
225
225
  }`}`);
226
226
  result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
227
227
  if (((_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0]) !== undefined) {
@@ -230,8 +230,8 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
230
230
  for (const header of headerParameters) {
231
231
  const paramName = toCasing(header.name, ctx.config.parameterNameCasing);
232
232
  const toString = this.getParameterToString(ctx, { endpoint, parameter: header });
233
- result.values.push(s `if (${paramName} != null) {${s.indent `
234
- localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
233
+ result.values.push(s `if (${paramName} != null) {${s.indent `
234
+ localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
235
235
  }`);
236
236
  }
237
237
  result.values.push(s `return ${kt.call([ctx.refs.requestConfig.infer()], [
@@ -100,16 +100,16 @@ export class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProv
100
100
  const jsonIncludeMember = toCasing(ctx.config.serializerJsonInclude, 'snake');
101
101
  const defaultFactory = springBootVersion === 4
102
102
  // Jackson 3's ObjectMapper is immutable; configuration moved to the (Kotlin) mapper builder.
103
- ? s `${kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${s.indent `
104
- .findAndAddModules()
105
- .changeDefaultPropertyInclusion { it.withValueInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
106
- .configure(${kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
107
- .configure(${kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
103
+ ? s `${kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${s.indent `
104
+ .findAndAddModules()
105
+ .changeDefaultPropertyInclusion { it.withValueInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
106
+ .configure(${kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
107
+ .configure(${kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
108
108
  .build()`}`
109
- : s `${kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${s.indent `
110
- .findAndRegisterModules()
111
- .setSerializationInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
112
- .configure(${kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
109
+ : s `${kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${s.indent `
110
+ .findAndRegisterModules()
111
+ .setSerializationInclusion(${kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
112
+ .configure(${kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
113
113
  .configure(${kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)`}`;
114
114
  const factory = typeof ctx.config.serializer === 'object'
115
115
  ? ctx.config.serializer.factory
@@ -257,13 +257,13 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
257
257
  }
258
258
  }
259
259
  });
260
- body.values.push(s `try {${s.indent `
260
+ body.values.push(s `try {${s.indent `
261
261
  return ${kt.call([
262
262
  kt.call(kt.reference('getDelegate'), []),
263
263
  toCasing(endpoint.name, ctx.config.functionNameCasing),
264
- ], parameters.map((x) => toCasing(x.name, ctx.config.parameterNameCasing)))}`}
265
- } catch (e: ${kt.refs.throwable()}) {${s.indent `
266
- return getExceptionHandler()?.handleApiException(e) ?: throw e`}
264
+ ], parameters.map((x) => toCasing(x.name, ctx.config.parameterNameCasing)))}`}
265
+ } catch (e: ${kt.refs.throwable()}) {${s.indent `
266
+ return getExceptionHandler()?.handleApiException(e) ?: throw e`}
267
267
  }`);
268
268
  return body;
269
269
  }
@@ -325,11 +325,11 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
325
325
  hasResponseBody ? kt.argument('body') : kt.toNode(null),
326
326
  kt.toNode(code),
327
327
  contentType
328
- ? s `${kt.refs.spring.linkedMultiValueMap([kt.refs.string(), kt.refs.string()])}().also {
329
- if (headers != null) {
330
- it.putAll(headers)
331
- }
332
- it.addIfAbsent("Content-Type", ${kt.string(contentType)})
328
+ ? s `${kt.refs.spring.linkedMultiValueMap([kt.refs.string(), kt.refs.string()])}().also {
329
+ if (headers != null) {
330
+ it.putAll(headers)
331
+ }
332
+ it.addIfAbsent("Content-Type", ${kt.string(contentType)})
333
333
  }`
334
334
  : kt.argument('headers'),
335
335
  ]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/kotlin",
3
- "version": "0.5.11-beta.2",
3
+ "version": "0.5.11",
4
4
  "description": "Provides gOAst generators for generating Kotlin code from OpenAPI specifications.",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -112,31 +112,31 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
112
112
  return (0, core_1.appendValueGroup)([
113
113
  (0, core_1.builderTemplate) `val localVarResponse = ${index_js_1.kt.call([(0, core_1.toCasing)(endpoint.name + '_WithHttpInfo', ctx.config.functionNameCasing)], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`,
114
114
  '',
115
- (0, core_1.builderTemplate) `return when (localVarResponse.responseType) {${core_1.builderTemplate.indent `
115
+ (0, core_1.builderTemplate) `return when (localVarResponse.responseType) {${core_1.builderTemplate.indent `
116
116
  ${ctx.refs.responseType()}.Success -> ${responseSchema === undefined
117
117
  ? index_js_1.kt.refs.unit()
118
118
  : (0, core_1.builderTemplate) `(localVarResponse as ${ctx.refs.success(['*'])}).data as ${this.getTypeUsage(ctx, {
119
119
  schema: responseSchema,
120
- })}`}
121
- ${ctx.refs.responseType()}.Informational -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
122
- ${ctx.refs.responseType()}.Redirection -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
123
- ${ctx.refs.responseType()}.ClientError -> {${core_1.builderTemplate.indent `
124
- val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
125
- throw ${ctx.refs.clientException()}(${core_1.builderTemplate.indent `
126
- "Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
127
- localVarError.statusCode,
128
- localVarResponse`}
129
- )`}
130
- }
131
-
132
- ${ctx.refs.responseType()}.ServerError -> {${core_1.builderTemplate.indent `
133
- val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
134
- throw ${ctx.refs.serverException()}(${core_1.builderTemplate.indent `
135
- "Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
136
- localVarError.statusCode,
137
- localVarResponse`}
138
- )`}
139
- }`}
120
+ })}`}
121
+ ${ctx.refs.responseType()}.Informational -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Informational responses.")
122
+ ${ctx.refs.responseType()}.Redirection -> throw ${index_js_1.kt.refs.java.unsupportedOperationException()}("Client does not support Redirection responses.")
123
+ ${ctx.refs.responseType()}.ClientError -> {${core_1.builderTemplate.indent `
124
+ val localVarError = localVarResponse as ${ctx.refs.clientError(['*'])}
125
+ throw ${ctx.refs.clientException()}(${core_1.builderTemplate.indent `
126
+ "Client error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
127
+ localVarError.statusCode,
128
+ localVarResponse`}
129
+ )`}
130
+ }
131
+
132
+ ${ctx.refs.responseType()}.ServerError -> {${core_1.builderTemplate.indent `
133
+ val localVarError = localVarResponse as ${ctx.refs.serverError(['*'])}
134
+ throw ${ctx.refs.serverException()}(${core_1.builderTemplate.indent `
135
+ "Server error : \${localVarError.statusCode} \${localVarError.message.orEmpty()}",
136
+ localVarError.statusCode,
137
+ localVarResponse`}
138
+ )`}
139
+ }`}
140
140
  }`,
141
141
  ], '\n');
142
142
  }
@@ -215,16 +215,16 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
215
215
  result.values.push(`val localVariableBody = ${bodyParamName}`);
216
216
  }
217
217
  }
218
- result.values.push((0, core_1.builderTemplate) `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${index_js_1.kt.call([index_js_1.kt.refs.mutableMapOf([index_js_1.kt.refs.string(), index_js_1.kt.refs.list([index_js_1.kt.refs.string()])])], [])}${queryParameters.length === 0 ? '' : core_1.builderTemplate.indent `
219
- .apply {${core_1.builderTemplate.indent `
218
+ result.values.push((0, core_1.builderTemplate) `val localVariableQuery: ${ctx.refs.multiValueMap()} = ${index_js_1.kt.call([index_js_1.kt.refs.mutableMapOf([index_js_1.kt.refs.string(), index_js_1.kt.refs.list([index_js_1.kt.refs.string()])])], [])}${queryParameters.length === 0 ? '' : core_1.builderTemplate.indent `
219
+ .apply {${core_1.builderTemplate.indent `
220
220
  ${(0, core_1.appendValueGroup)(queryParameters.map((param) => {
221
221
  const paramName = (0, core_1.toCasing)(param.name, ctx.config.parameterNameCasing);
222
222
  const toString = this.getParameterToString(ctx, { endpoint, parameter: param });
223
223
  const put = (0, core_1.builderTemplate) `put(${index_js_1.kt.string(param.name)}, listOf(${paramName}${toString}))`;
224
- return param.required ? put : (0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
225
- ${put}`}
224
+ return param.required ? put : (0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
225
+ ${put}`}
226
226
  }`;
227
- }), '\n')}`}
227
+ }), '\n')}`}
228
228
  }`}`);
229
229
  result.values.push('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()');
230
230
  if (((_b = endpoint.requestBody) === null || _b === void 0 ? void 0 : _b.content[0]) !== undefined) {
@@ -233,8 +233,8 @@ class DefaultKotlinOkHttp3Generator extends file_generator_js_1.KotlinFileGenera
233
233
  for (const header of headerParameters) {
234
234
  const paramName = (0, core_1.toCasing)(header.name, ctx.config.parameterNameCasing);
235
235
  const toString = this.getParameterToString(ctx, { endpoint, parameter: header });
236
- result.values.push((0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
237
- localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
236
+ result.values.push((0, core_1.builderTemplate) `if (${paramName} != null) {${core_1.builderTemplate.indent `
237
+ localVariableHeaders["${header.name}"] = ${paramName}${toString}`}
238
238
  }`);
239
239
  }
240
240
  result.values.push((0, core_1.builderTemplate) `return ${index_js_1.kt.call([ctx.refs.requestConfig.infer()], [
@@ -103,16 +103,16 @@ class KotlinOkHttp3ClientsGenerator extends core_1.OpenApiServicesGenerationProv
103
103
  const jsonIncludeMember = (0, core_1.toCasing)(ctx.config.serializerJsonInclude, 'snake');
104
104
  const defaultFactory = springBootVersion === 4
105
105
  // Jackson 3's ObjectMapper is immutable; configuration moved to the (Kotlin) mapper builder.
106
- ? (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${core_1.builderTemplate.indent `
107
- .findAndAddModules()
108
- .changeDefaultPropertyInclusion { it.withValueInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
109
- .configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
110
- .configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
106
+ ? (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonMapperBuilder(springBootVersion)}()${core_1.builderTemplate.indent `
107
+ .findAndAddModules()
108
+ .changeDefaultPropertyInclusion { it.withValueInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}).withContentInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember}) }
109
+ .configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
110
+ .configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)
111
111
  .build()`}`
112
- : (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${core_1.builderTemplate.indent `
113
- .findAndRegisterModules()
114
- .setSerializationInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
115
- .configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
112
+ : (0, core_1.builderTemplate) `${index_js_1.kt.refs.jackson.jacksonObjectMapper(springBootVersion)}()${core_1.builderTemplate.indent `
113
+ .findAndRegisterModules()
114
+ .setSerializationInclusion(${index_js_1.kt.refs.jackson.jsonInclude()}.Include.${jsonIncludeMember})
115
+ .configure(${index_js_1.kt.refs.jackson.serializationFeature(springBootVersion)}.WRITE_DATES_AS_TIMESTAMPS, false)
116
116
  .configure(${index_js_1.kt.refs.jackson.deserializationFeature(springBootVersion)}.FAIL_ON_UNKNOWN_PROPERTIES, false)`}`;
117
117
  const factory = typeof ctx.config.serializer === 'object'
118
118
  ? ctx.config.serializer.factory
@@ -261,13 +261,13 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
261
261
  }
262
262
  }
263
263
  });
264
- body.values.push((0, core_1.builderTemplate) `try {${core_1.builderTemplate.indent `
264
+ body.values.push((0, core_1.builderTemplate) `try {${core_1.builderTemplate.indent `
265
265
  return ${index_js_1.kt.call([
266
266
  index_js_1.kt.call(index_js_1.kt.reference('getDelegate'), []),
267
267
  (0, core_1.toCasing)(endpoint.name, ctx.config.functionNameCasing),
268
- ], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`}
269
- } catch (e: ${index_js_1.kt.refs.throwable()}) {${core_1.builderTemplate.indent `
270
- return getExceptionHandler()?.handleApiException(e) ?: throw e`}
268
+ ], parameters.map((x) => (0, core_1.toCasing)(x.name, ctx.config.parameterNameCasing)))}`}
269
+ } catch (e: ${index_js_1.kt.refs.throwable()}) {${core_1.builderTemplate.indent `
270
+ return getExceptionHandler()?.handleApiException(e) ?: throw e`}
271
271
  }`);
272
272
  return body;
273
273
  }
@@ -329,11 +329,11 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_js_1.KotlinF
329
329
  hasResponseBody ? index_js_1.kt.argument('body') : index_js_1.kt.toNode(null),
330
330
  index_js_1.kt.toNode(code),
331
331
  contentType
332
- ? (0, core_1.builderTemplate) `${index_js_1.kt.refs.spring.linkedMultiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()])}().also {
333
- if (headers != null) {
334
- it.putAll(headers)
335
- }
336
- it.addIfAbsent("Content-Type", ${index_js_1.kt.string(contentType)})
332
+ ? (0, core_1.builderTemplate) `${index_js_1.kt.refs.spring.linkedMultiValueMap([index_js_1.kt.refs.string(), index_js_1.kt.refs.string()])}().also {
333
+ if (headers != null) {
334
+ it.putAll(headers)
335
+ }
336
+ it.addIfAbsent("Content-Type", ${index_js_1.kt.string(contentType)})
337
337
  }`
338
338
  : index_js_1.kt.argument('headers'),
339
339
  ]),