@goast/kotlin 0.0.7 → 0.1.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.
@@ -18,11 +18,11 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
18
18
  }
19
19
  generateApiClientFileContent(ctx, builder) {
20
20
  builder
21
- .apply((builder) => this.generateApiClientClassAnnotations(ctx, builder))
21
+ .append((builder) => this.generateApiClientClassAnnotations(ctx, builder))
22
22
  .ensureCurrentLineEmpty()
23
- .apply((builder) => this.generateApiClientClassSignature(ctx, builder))
23
+ .append((builder) => this.generateApiClientClassSignature(ctx, builder))
24
24
  .append(' ')
25
- .parenthesizeMultiline('{}', (builder) => this.generateApiClientClassContent(ctx, builder));
25
+ .parenthesize('{}', (builder) => this.generateApiClientClassContent(ctx, builder), { multiline: true });
26
26
  }
27
27
  generateApiClientClassAnnotations(ctx, builder) {
28
28
  // None for now
@@ -31,31 +31,31 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
31
31
  builder
32
32
  .append('class ')
33
33
  .append(this.getApiClientName(ctx))
34
- .parenthesizeMultiline('()', (builder) => builder
34
+ .parenthesize('()', (builder) => builder
35
35
  .appendLine('basePath: String = defaultBasePath,')
36
36
  .appendLine('client: OkHttpClient = ApiClient.defaultClient')
37
37
  .addImport('OkHttpClient', 'okhttp3')
38
- .addImport('ApiClient', ctx.infrastructurePackageName))
38
+ .addImport('ApiClient', ctx.infrastructurePackageName), { multiline: true })
39
39
  .append(' : ')
40
40
  .append('ApiClient(basePath, client)');
41
41
  }
42
42
  generateApiClientClassContent(ctx, builder) {
43
43
  builder
44
- .apply((builder) => this.generateApiClientCompanionObject(ctx, builder))
44
+ .append((builder) => this.generateApiClientCompanionObject(ctx, builder))
45
45
  .forEach(ctx.service.endpoints, (builder, endpoint) => builder
46
46
  .ensurePreviousLineEmpty()
47
- .apply((builder) => this.generateApiClientMethod(ctx, builder, endpoint))
47
+ .append((builder) => this.generateApiClientMethod(ctx, builder, endpoint))
48
48
  .ensurePreviousLineEmpty()
49
- .apply((builder) => this.generateApiClientHttpInfoMethod(ctx, builder, endpoint))
49
+ .append((builder) => this.generateApiClientHttpInfoMethod(ctx, builder, endpoint))
50
50
  .ensurePreviousLineEmpty()
51
- .apply((builder) => this.generateApiClientRequestConfigMethod(ctx, builder, endpoint)))
51
+ .append((builder) => this.generateApiClientRequestConfigMethod(ctx, builder, endpoint)))
52
52
  .ensurePreviousLineEmpty()
53
- .apply((builder) => this.generateAdditionalMethods(ctx, builder));
53
+ .append((builder) => this.generateAdditionalMethods(ctx, builder));
54
54
  }
55
55
  generateApiClientCompanionObject(ctx, builder) {
56
56
  builder
57
57
  .append('companion object ')
58
- .parenthesizeMultiline('{}', (builder) => this.generateApiClientCompanionObjectContent(ctx, builder));
58
+ .parenthesize('{}', (builder) => this.generateApiClientCompanionObjectContent(ctx, builder), { multiline: true });
59
59
  }
60
60
  generateApiClientCompanionObjectContent(ctx, builder) {
61
61
  this.generateApiClientCompanionObjectDefaultBasePathProperty(ctx, builder);
@@ -64,30 +64,32 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
64
64
  builder
65
65
  .appendAnnotation('JvmStatic')
66
66
  .append('val defaultBasePath: String by lazy ')
67
- .parenthesizeMultiline('{}', (builder) => builder
67
+ .parenthesize('{}', (builder) => builder
68
68
  .appendLine(`System.getProperties().getProperty(ApiClient.baseUrlKey, ${this.toStringLiteral(ctx, this.getBasePath(ctx))})`)
69
- .addImport('ApiClient', ctx.infrastructurePackageName));
69
+ .addImport('ApiClient', ctx.infrastructurePackageName), { multiline: true });
70
70
  }
71
71
  generateApiClientMethod(ctx, builder, endpoint) {
72
72
  builder
73
- .apply((builder) => this.generateApiClientMethodDocumentation(ctx, builder, endpoint))
73
+ .append((builder) => this.generateApiClientMethodDocumentation(ctx, builder, endpoint))
74
74
  .ensureCurrentLineEmpty()
75
- .apply((builder) => this.generateApiClientMethodAnnotations(ctx, builder, endpoint))
75
+ .append((builder) => this.generateApiClientMethodAnnotations(ctx, builder, endpoint))
76
76
  .ensureCurrentLineEmpty()
77
- .apply((builder) => this.generateApiClientMethodSignature(ctx, builder, endpoint))
77
+ .append((builder) => this.generateApiClientMethodSignature(ctx, builder, endpoint))
78
78
  .append(' ')
79
- .parenthesizeMultiline('{}', (builder) => this.generateApiClientMethodContent(ctx, builder, endpoint));
79
+ .parenthesize('{}', (builder) => this.generateApiClientMethodContent(ctx, builder, endpoint), {
80
+ multiline: true,
81
+ });
80
82
  }
81
83
  generateApiClientMethodDocumentation(ctx, builder, endpoint) {
82
84
  builder
83
85
  .appendLine('/**')
84
- .applyWithLinePrefix(' * ', (builder) => {
86
+ .appendWithLinePrefix(' * ', (builder) => {
85
87
  var _a;
86
88
  return builder
87
89
  .appendLine(`${(_a = endpoint.summary) !== null && _a !== void 0 ? _a : 'TODO: Provide summary'}`)
88
- .apply((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
90
+ .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
89
91
  .append('@return ')
90
- .apply((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint))
92
+ .append((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint))
91
93
  .appendLine()
92
94
  .appendLine('@throws IllegalStateException If the request is not correctly configured')
93
95
  .appendLine('@throws IOException Rethrows the OkHttp execute method exception')
@@ -116,7 +118,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
116
118
  .append(toCasing(endpoint.name, 'camel'))
117
119
  .parenthesize('()', (builder) => this.generateApiClientMethodParameters(ctx, builder, endpoint))
118
120
  .append(': ')
119
- .apply((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint));
121
+ .append((builder) => this.generateApiClientMethodReturnType(ctx, builder, endpoint));
120
122
  }
121
123
  generateApiClientMethodParameters(ctx, builder, endpoint) {
122
124
  this.generateParams(ctx, builder, endpoint, true);
@@ -132,38 +134,40 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
132
134
  .appendLine()
133
135
  .appendLine()
134
136
  .append('return when (localVarResponse.responseType) ')
135
- .parenthesizeMultiline('{}', (builder) => builder
137
+ .parenthesize('{}', (builder) => builder
136
138
  .append('ResponseType.Success -> ')
137
- .applyIfElse(responseSchema === undefined, (builder) => builder.append('Unit'), (builder) => builder
139
+ .if(responseSchema === undefined, (builder) => builder.append('Unit'), (builder) => builder
138
140
  .append('(localVarResponse as Success<*>).data as ')
139
141
  .addImport('Success', ctx.infrastructurePackageName)
140
- .apply((builder) => this.generateTypeUsage(ctx, builder, responseSchema)))
142
+ .append((builder) => this.generateTypeUsage(ctx, builder, responseSchema)))
141
143
  .ensureCurrentLineEmpty()
142
144
  .appendLine(responseErrorHandlingCode)
143
145
  .addImport('ClientError', ctx.infrastructurePackageName)
144
146
  .addImport('ServerError', ctx.infrastructurePackageName)
145
- .addImport('ResponseType', ctx.infrastructurePackageName));
147
+ .addImport('ResponseType', ctx.infrastructurePackageName), { multiline: true });
146
148
  }
147
149
  generateApiClientHttpInfoMethod(ctx, builder, endpoint) {
148
150
  builder
149
- .apply((builder) => this.generateApiClientHttpInfoMethodDocumentation(ctx, builder, endpoint))
151
+ .append((builder) => this.generateApiClientHttpInfoMethodDocumentation(ctx, builder, endpoint))
150
152
  .ensureCurrentLineEmpty()
151
- .apply((builder) => this.generateApiClientHttpInfoMethodAnnotations(ctx, builder, endpoint))
153
+ .append((builder) => this.generateApiClientHttpInfoMethodAnnotations(ctx, builder, endpoint))
152
154
  .ensureCurrentLineEmpty()
153
- .apply((builder) => this.generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint))
155
+ .append((builder) => this.generateApiClientHttpInfoMethodSignature(ctx, builder, endpoint))
154
156
  .append(' ')
155
- .parenthesizeMultiline('{}', (builder) => this.generateApiClientHttpInfoMethodContent(ctx, builder, endpoint));
157
+ .parenthesize('{}', (builder) => this.generateApiClientHttpInfoMethodContent(ctx, builder, endpoint), {
158
+ multiline: true,
159
+ });
156
160
  }
157
161
  generateApiClientHttpInfoMethodDocumentation(ctx, builder, endpoint) {
158
162
  builder
159
163
  .appendLine('/**')
160
- .applyWithLinePrefix(' * ', (builder) => {
164
+ .appendWithLinePrefix(' * ', (builder) => {
161
165
  var _a;
162
166
  return builder
163
167
  .appendLine(`${(_a = endpoint.summary) !== null && _a !== void 0 ? _a : 'TODO: Provide summary'}`)
164
- .apply((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
168
+ .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
165
169
  .append('@return ')
166
- .apply((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint))
170
+ .append((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint))
167
171
  .appendLine()
168
172
  .appendLine('@throws IllegalStateException If the request is not correctly configured')
169
173
  .appendLine('@throws IOException Rethrows the OkHttp execute method exception')
@@ -184,7 +188,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
184
188
  .append(toCasing(endpoint.name, 'camel'), 'WithHttpInfo')
185
189
  .parenthesize('()', (builder) => this.generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint))
186
190
  .append(': ')
187
- .apply((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint));
191
+ .append((builder) => this.generateApiClientHttpInfoMethodReturnType(ctx, builder, endpoint));
188
192
  }
189
193
  generateApiClientHttpInfoMethodSignatureParameters(ctx, builder, endpoint) {
190
194
  this.generateParams(ctx, builder, endpoint, true);
@@ -203,27 +207,29 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
203
207
  .appendLine()
204
208
  .append('return request')
205
209
  .parenthesize('<>', (builder) => builder
206
- .apply((builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); })
210
+ .append((builder) => { var _a; return this.generateTypeUsage(ctx, builder, (_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content[0].schema, 'Unit'); })
207
211
  .append(', ')
208
- .apply((builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit')))
209
- .parenthesizeMultiline('()', (builder) => builder.append('localVariableConfig'));
212
+ .append((builder) => this.generateTypeUsage(ctx, builder, this.getResponseSchema(ctx, endpoint), 'Unit')))
213
+ .parenthesize('()', (builder) => builder.append('localVariableConfig'), { multiline: true });
210
214
  }
211
215
  generateApiClientRequestConfigMethod(ctx, builder, endpoint) {
212
216
  builder
213
- .apply((builder) => this.generateApiClientRequestConfigMethodDocumentation(ctx, builder, endpoint))
217
+ .append((builder) => this.generateApiClientRequestConfigMethodDocumentation(ctx, builder, endpoint))
214
218
  .ensureCurrentLineEmpty()
215
- .apply((builder) => this.generateApiClientRequestConfigMethodAnnotations(ctx, builder, endpoint))
219
+ .append((builder) => this.generateApiClientRequestConfigMethodAnnotations(ctx, builder, endpoint))
216
220
  .ensureCurrentLineEmpty()
217
- .apply((builder) => this.generateApiClientRequestConfigMethodSignature(ctx, builder, endpoint))
221
+ .append((builder) => this.generateApiClientRequestConfigMethodSignature(ctx, builder, endpoint))
218
222
  .append(' ')
219
- .parenthesizeMultiline('{}', (builder) => this.generateApiClientRequestConfigMethodContent(ctx, builder, endpoint));
223
+ .parenthesize('{}', (builder) => this.generateApiClientRequestConfigMethodContent(ctx, builder, endpoint), {
224
+ multiline: true,
225
+ });
220
226
  }
221
227
  generateApiClientRequestConfigMethodDocumentation(ctx, builder, endpoint) {
222
228
  builder
223
229
  .appendLine('/**')
224
- .applyWithLinePrefix(' * ', (builder) => builder
230
+ .appendWithLinePrefix(' * ', (builder) => builder
225
231
  .appendLine(`To obtain the request config of the operation ${toCasing(endpoint.name, 'camel')}`)
226
- .apply((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
232
+ .append((builder) => this.generateParamDocEntries(ctx, builder, endpoint))
227
233
  .append('@return RequestConfig'))
228
234
  .appendLine(' */');
229
235
  }
@@ -236,7 +242,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
236
242
  .append(toCasing(endpoint.name, 'camel'), 'RequestConfig')
237
243
  .parenthesize('()', (builder) => this.generateApiClientRequestConfigMethodSignatureParameters(ctx, builder, endpoint))
238
244
  .append(': ')
239
- .apply((builder) => this.generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint));
245
+ .append((builder) => this.generateApiClientRequestConfigMethodReturnType(ctx, builder, endpoint));
240
246
  }
241
247
  generateApiClientRequestConfigMethodSignatureParameters(ctx, builder, endpoint) {
242
248
  this.generateParams(ctx, builder, endpoint, true);
@@ -254,24 +260,24 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
254
260
  .appendLineIf(!!endpoint.requestBody, `val localVariableBody = ${toCasing(this.getRequestBodyParamName(ctx, endpoint), 'camel')}`)
255
261
  .appendLine('val localVariableQuery: MultiValueMap = mutableMapOf<String, List<String>>()')
256
262
  .addImport('MultiValueMap', ctx.infrastructurePackageName)
257
- .applyIf(queryParameters.length > 0, (builder) => builder.indent((builder) => builder.append('.apply ').parenthesizeMultiline('{}', (builder) => builder.forEach(queryParameters, (builder, param) => builder
263
+ .if(queryParameters.length > 0, (builder) => builder.indent((builder) => builder.append('.apply ').parenthesize('{}', (builder) => builder.forEach(queryParameters, (builder, param) => builder
258
264
  .appendIf(!param.required, `if (${toCasing(param.name, 'camel')} != null) `)
259
- .parenthesizeMultilineIf(!param.required, '{}', (builder) => builder.appendLine(`put(${this.toStringLiteral(ctx, toCasing(param.name, 'camel'))}, listOf(${toCasing(param.name, 'camel')}.toString()))`))
260
- .appendLine()))))
265
+ .parenthesizeIf(!param.required, '{}', (builder) => builder.appendLine(`put(${this.toStringLiteral(ctx, toCasing(param.name, 'camel'))}, listOf(${toCasing(param.name, 'camel')}.toString()))`), { multiline: true })
266
+ .appendLine()), { multiline: true })))
261
267
  .ensureCurrentLineEmpty()
262
268
  .appendLine('val localVariableHeaders: MutableMap<String, String> = mutableMapOf()')
263
269
  .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}"`)
264
270
  .appendLine()
265
271
  .append('return RequestConfig')
266
272
  .addImport('RequestConfig', ctx.infrastructurePackageName)
267
- .parenthesizeMultiline('()', (builder) => builder
273
+ .parenthesize('()', (builder) => builder
268
274
  .appendLine(`method = RequestMethod.${endpoint.method.toUpperCase()},`)
269
275
  .addImport('RequestMethod', ctx.infrastructurePackageName)
270
276
  .appendLine(`path = "${this.getPathWithInterpolation(ctx, endpoint)}",`)
271
277
  .appendLine('query = localVariableQuery,')
272
278
  .appendLine('headers = localVariableHeaders,')
273
279
  .appendLine('requiresAuthentication = false,')
274
- .appendLineIf(!!endpoint.requestBody, 'body = localVariableBody'));
280
+ .appendLineIf(!!endpoint.requestBody, 'body = localVariableBody'), { multiline: true });
275
281
  }
276
282
  generateAdditionalMethods(ctx, builder) {
277
283
  this.generateEncodeUriComponentMethod(ctx, builder);
@@ -288,10 +294,10 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
288
294
  }
289
295
  generateParams(ctx, builder, endpoint, includeTypeDefinition) {
290
296
  const parameters = this.getAllParameters(ctx, endpoint);
291
- builder.forEachSeparated(parameters, ', ', (builder, parameter) => builder.append(toCasing(parameter.name, 'camel')).applyIf(includeTypeDefinition, (builder) => builder
297
+ builder.forEach(parameters, (builder, parameter) => builder.append(toCasing(parameter.name, 'camel')).if(includeTypeDefinition, (builder) => builder
292
298
  .append(': ')
293
- .apply((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
294
- .appendIf(!parameter.required, '? = ', this.getDefaultValue(ctx, parameter.schema))));
299
+ .append((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
300
+ .appendIf(!parameter.required, '? = ', this.getDefaultValue(ctx, parameter.schema))), { separator: ', ' });
295
301
  }
296
302
  generateTypeUsage(ctx, builder, schema, fallback, nullable) {
297
303
  if (schema && schema.kind === 'array') {
@@ -27,11 +27,11 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
27
27
  }
28
28
  generateApiInterfaceFileContent(ctx, builder) {
29
29
  builder
30
- .apply((builder) => this.generateApiInterfaceAnnotations(ctx, builder))
30
+ .append((builder) => this.generateApiInterfaceAnnotations(ctx, builder))
31
31
  .ensureCurrentLineEmpty()
32
- .apply((builder) => this.generateApiInterfaceSignature(ctx, builder))
32
+ .append((builder) => this.generateApiInterfaceSignature(ctx, builder))
33
33
  .append(' ')
34
- .parenthesizeMultiline('{}', (builder) => this.generateApiInterfaceContent(ctx, builder));
34
+ .parenthesize('{}', (builder) => this.generateApiInterfaceContent(ctx, builder), { multiline: true });
35
35
  }
36
36
  generateApiInterfaceAnnotations(ctx, builder) {
37
37
  builder
@@ -45,23 +45,25 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
45
45
  }
46
46
  generateApiInterfaceContent(ctx, builder) {
47
47
  builder
48
- .apply((builder) => this.generateApiInterfaceDelegateAccessor(ctx, builder))
48
+ .append((builder) => this.generateApiInterfaceDelegateAccessor(ctx, builder))
49
49
  .ensurePreviousLineEmpty()
50
- .apply((builder) => this.generateApiInterfaceMethods(ctx, builder));
50
+ .append((builder) => this.generateApiInterfaceMethods(ctx, builder));
51
51
  }
52
52
  generateApiInterfaceDelegateAccessor(ctx, builder) {
53
53
  builder.appendLine(`fun getDelegate(): ${this.getApiDelegateInterfaceName(ctx)} = object : ${this.getApiDelegateInterfaceName(ctx)} {}`);
54
54
  }
55
55
  generateApiInterfaceMethods(ctx, builder) {
56
- builder.forEach(ctx.service.endpoints, (builder, endpoint) => builder.ensurePreviousLineEmpty().apply((builder) => this.generateApiInterfaceMethod(ctx, builder, endpoint)));
56
+ builder.forEach(ctx.service.endpoints, (builder, endpoint) => builder.ensurePreviousLineEmpty().append((builder) => this.generateApiInterfaceMethod(ctx, builder, endpoint)));
57
57
  }
58
58
  generateApiInterfaceMethod(ctx, builder, endpoint) {
59
59
  builder
60
- .apply((builder) => this.generateApiInterfaceMethodAnnnotations(ctx, builder, endpoint))
60
+ .append((builder) => this.generateApiInterfaceMethodAnnnotations(ctx, builder, endpoint))
61
61
  .ensureCurrentLineEmpty()
62
- .apply((builder) => this.generateApiInterfaceMethodSignature(ctx, builder, endpoint))
62
+ .append((builder) => this.generateApiInterfaceMethodSignature(ctx, builder, endpoint))
63
63
  .append(' ')
64
- .parenthesizeMultiline('{}', (builder) => this.generateApiInterfaceMethodContent(ctx, builder, endpoint));
64
+ .parenthesize('{}', (builder) => this.generateApiInterfaceMethodContent(ctx, builder, endpoint), {
65
+ multiline: true,
66
+ });
65
67
  }
66
68
  generateApiInterfaceMethodAnnnotations(ctx, builder, endpoint) {
67
69
  var _a, _b, _c;
@@ -72,7 +74,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
72
74
  ['description', this.toStringLiteral(ctx, (_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())],
73
75
  [
74
76
  'responses',
75
- (builder) => builder.parenthesizeMultiline('[]', (builder) => builder.forEachSeparated(endpoint.responses, ',\n', (builder, response) => builder
77
+ (builder) => builder.parenthesize('[]', (builder) => builder.forEach(endpoint.responses, (builder, response) => builder
76
78
  .append('ApiResponse')
77
79
  .addImport('ApiResponse', 'io.swagger.v3.oas.annotations.responses')
78
80
  .parenthesize('()', (builder) => {
@@ -80,7 +82,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
80
82
  return builder
81
83
  .append(`responseCode = ${this.toStringLiteral(ctx, (_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())}, `)
82
84
  .append(`description = ${this.toStringLiteral(ctx, (_b = response.description) === null || _b === void 0 ? void 0 : _b.trim())}`);
83
- }))),
85
+ }), { separator: ',\n' }), { multiline: true }),
84
86
  endpoint.responses.length > 0,
85
87
  ],
86
88
  ])
@@ -98,13 +100,15 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
98
100
  generateApiInterfaceMethodSignature(ctx, builder, endpoint) {
99
101
  builder
100
102
  .append(`suspend fun ${toCasing(endpoint.name, 'camel')}`)
101
- .parenthesizeMultiline('()', (builder) => this.generateApiInterfaceMethodParameters(ctx, builder, endpoint))
103
+ .parenthesize('()', (builder) => this.generateApiInterfaceMethodParameters(ctx, builder, endpoint), {
104
+ multiline: true,
105
+ })
102
106
  .append(': ')
103
- .apply((builder) => this.generateApiInterfaceMethodReturnType(ctx, builder, endpoint));
107
+ .append((builder) => this.generateApiInterfaceMethodReturnType(ctx, builder, endpoint));
104
108
  }
105
109
  generateApiInterfaceMethodParameters(ctx, builder, endpoint) {
106
110
  const parameters = this.getAllParameters(ctx, endpoint);
107
- builder.forEachSeparated(parameters, ',\n', (builder, parameter) => this.generateApiInterfaceMethodParameter(ctx, builder, endpoint, parameter));
111
+ builder.forEach(parameters, (builder, parameter) => this.generateApiInterfaceMethodParameter(ctx, builder, endpoint, parameter), { separator: ',\n' });
108
112
  }
109
113
  generateApiInterfaceMethodReturnType(ctx, builder, endpoint) {
110
114
  var _a, _b;
@@ -112,9 +116,9 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
112
116
  }
113
117
  generateApiInterfaceMethodParameter(ctx, builder, endpoint, parameter) {
114
118
  builder
115
- .apply((builder) => this.generateApiInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter))
119
+ .append((builder) => this.generateApiInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter))
116
120
  .ensureCurrentLineEmpty()
117
- .apply((builder) => this.generateApiInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter));
121
+ .append((builder) => this.generateApiInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter));
118
122
  }
119
123
  generateApiInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter) {
120
124
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -155,16 +159,20 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
155
159
  }
156
160
  }
157
161
  generateApiInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter) {
162
+ var _a, _b;
158
163
  builder
159
164
  .append(toCasing(parameter.name, 'camel'))
160
165
  .append(': ')
161
- .apply((builder) => this.generateTypeUsage(ctx, builder, parameter.schema));
166
+ .append((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
167
+ .append(!parameter.required && ((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) === undefined && !((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.nullable) ? '?' : '');
162
168
  }
163
169
  generateApiInterfaceMethodContent(ctx, builder, endpoint) {
164
170
  const parameters = this.getAllParameters(ctx, endpoint);
165
171
  builder
166
172
  .append(`return getDelegate().${toCasing(endpoint.name, 'camel')}(`)
167
- .forEachSeparated(parameters, ', ', (builder, parameter) => builder.append(toCasing(parameter.name, 'camel')))
173
+ .forEach(parameters, (builder, parameter) => builder.append(toCasing(parameter.name, 'camel')), {
174
+ separator: ', ',
175
+ })
168
176
  .append(')');
169
177
  }
170
178
  generateApiControllerFile(ctx, dirPath, packageName) {
@@ -179,11 +187,11 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
179
187
  }
180
188
  generateApiControllerFileContent(ctx, builder) {
181
189
  builder
182
- .apply((builder) => this.generateApiControllerAnnotations(ctx, builder))
190
+ .append((builder) => this.generateApiControllerAnnotations(ctx, builder))
183
191
  .ensureCurrentLineEmpty()
184
- .apply((builder) => this.generateApiControllerSignature(ctx, builder))
192
+ .append((builder) => this.generateApiControllerSignature(ctx, builder))
185
193
  .append(' ')
186
- .parenthesizeMultiline('{}', (builder) => this.generateApiControllerContent(ctx, builder));
194
+ .parenthesize('{}', (builder) => this.generateApiControllerContent(ctx, builder), { multiline: true });
187
195
  }
188
196
  generateApiControllerAnnotations(ctx, builder) {
189
197
  builder
@@ -199,7 +207,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
199
207
  builder
200
208
  .append('class ')
201
209
  .append(this.getApiControllerName(ctx))
202
- .parenthesizeMultiline('()', (builder) => this.generateApiControllerParameters(ctx, builder))
210
+ .parenthesize('()', (builder) => this.generateApiControllerParameters(ctx, builder), { multiline: true })
203
211
  .append(' : ')
204
212
  .append(this.getApiInterfaceName(ctx));
205
213
  }
@@ -216,10 +224,10 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
216
224
  .appendLine(this.getApiDelegateInterfaceName(ctx))
217
225
  .appendLine()
218
226
  .append('init ')
219
- .parenthesizeMultiline('{}', (builder) => builder
227
+ .parenthesize('{}', (builder) => builder
220
228
  .append('this.delegate = Optional.ofNullable(delegate).orElse')
221
229
  .addImport('Optional', 'java.util')
222
- .parenthesize('()', (builder) => builder.append('object : ').append(this.getApiDelegateInterfaceName(ctx)).append(' {}')))
230
+ .parenthesize('()', (builder) => builder.append('object : ').append(this.getApiDelegateInterfaceName(ctx)).append(' {}')), { multiline: true })
223
231
  .appendLine()
224
232
  .appendLine()
225
233
  .appendLine(`override fun getDelegate(): ${this.getApiDelegateInterfaceName(ctx)} = delegate`);
@@ -236,11 +244,11 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
236
244
  }
237
245
  generateApiDelegateInterfaceFileContent(ctx, builder) {
238
246
  builder
239
- .apply((builder) => this.generateApiDelegateInterfaceAnnotations(ctx, builder))
247
+ .append((builder) => this.generateApiDelegateInterfaceAnnotations(ctx, builder))
240
248
  .ensureCurrentLineEmpty()
241
- .apply((builder) => this.generateApiDelegateInterfaceSignature(ctx, builder))
249
+ .append((builder) => this.generateApiDelegateInterfaceSignature(ctx, builder))
242
250
  .append(' ')
243
- .parenthesizeMultiline('{}', (builder) => this.generateApiDelegateInterfaceContent(ctx, builder));
251
+ .parenthesize('{}', (builder) => this.generateApiDelegateInterfaceContent(ctx, builder), { multiline: true });
244
252
  }
245
253
  generateApiDelegateInterfaceAnnotations(ctx, builder) {
246
254
  builder.appendAnnotation('Generated', 'jakarta.annotation', [
@@ -257,15 +265,17 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
257
265
  .addImport('NativeWebRequest', 'org.springframework.web.context.request')
258
266
  .forEach(ctx.service.endpoints, (builder, endpoint) => builder
259
267
  .ensurePreviousLineEmpty()
260
- .apply((builder) => this.generateApiDelegateInterfaceMethod(ctx, builder, endpoint)));
268
+ .append((builder) => this.generateApiDelegateInterfaceMethod(ctx, builder, endpoint)));
261
269
  }
262
270
  generateApiDelegateInterfaceMethod(ctx, builder, endpoint) {
263
271
  builder
264
- .apply((builder) => this.generateApiDelegateInterfaceMethodAnnnotations(ctx, builder, endpoint))
272
+ .append((builder) => this.generateApiDelegateInterfaceMethodAnnnotations(ctx, builder, endpoint))
265
273
  .ensureCurrentLineEmpty()
266
- .apply((builder) => this.generateApiDelegateInterfaceMethodSignature(ctx, builder, endpoint))
274
+ .append((builder) => this.generateApiDelegateInterfaceMethodSignature(ctx, builder, endpoint))
267
275
  .append(' ')
268
- .parenthesizeMultiline('{}', (builder) => this.generateApiDelegateInterfaceMethodContent(ctx, builder, endpoint));
276
+ .parenthesize('{}', (builder) => this.generateApiDelegateInterfaceMethodContent(ctx, builder, endpoint), {
277
+ multiline: true,
278
+ });
269
279
  }
270
280
  generateApiDelegateInterfaceMethodAnnnotations(ctx, builder, endpoint) {
271
281
  // None for now.
@@ -273,13 +283,15 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
273
283
  generateApiDelegateInterfaceMethodSignature(ctx, builder, endpoint) {
274
284
  builder
275
285
  .append(`suspend fun ${toCasing(endpoint.name, 'camel')}`)
276
- .parenthesizeMultiline('()', (builder) => this.generateApiDelegateInterfaceMethodParameters(ctx, builder, endpoint))
286
+ .parenthesize('()', (builder) => this.generateApiDelegateInterfaceMethodParameters(ctx, builder, endpoint), {
287
+ multiline: true,
288
+ })
277
289
  .append(': ')
278
- .apply((builder) => this.generateApiDelegateInterfaceMethodReturnType(ctx, builder, endpoint));
290
+ .append((builder) => this.generateApiDelegateInterfaceMethodReturnType(ctx, builder, endpoint));
279
291
  }
280
292
  generateApiDelegateInterfaceMethodParameters(ctx, builder, endpoint) {
281
293
  const parameters = this.getAllParameters(ctx, endpoint);
282
- builder.forEachSeparated(parameters, ',\n', (builder, parameter) => this.generateApiDelegateInterfaceMethodParameter(ctx, builder, endpoint, parameter));
294
+ builder.forEach(parameters, (builder, parameter) => this.generateApiDelegateInterfaceMethodParameter(ctx, builder, endpoint, parameter), { separator: ',\n' });
283
295
  }
284
296
  generateApiDelegateInterfaceMethodReturnType(ctx, builder, endpoint) {
285
297
  var _a, _b;
@@ -287,18 +299,20 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
287
299
  }
288
300
  generateApiDelegateInterfaceMethodParameter(ctx, builder, endpoint, parameter) {
289
301
  builder
290
- .apply((builder) => this.generateApiDelegateInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter))
302
+ .append((builder) => this.generateApiDelegateInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter))
291
303
  .ensureCurrentLineEmpty()
292
- .apply((builder) => this.generateApiDelegateInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter));
304
+ .append((builder) => this.generateApiDelegateInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter));
293
305
  }
294
306
  generateApiDelegateInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter) {
295
307
  // None for now.
296
308
  }
297
309
  generateApiDelegateInterfaceMethodParameterSignature(ctx, builder, endpoint, parameter) {
310
+ var _a, _b;
298
311
  builder
299
312
  .append(toCasing(parameter.name, 'camel'))
300
313
  .append(': ')
301
- .apply((builder) => this.generateTypeUsage(ctx, builder, parameter.schema));
314
+ .append((builder) => this.generateTypeUsage(ctx, builder, parameter.schema))
315
+ .append(!parameter.required && ((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) === undefined && !((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.nullable) ? '?' : '');
302
316
  }
303
317
  generateApiDelegateInterfaceMethodContent(ctx, builder, endpoint) {
304
318
  builder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/kotlin",
3
- "version": "0.0.7",
3
+ "version": "0.1.1",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -12,7 +12,7 @@
12
12
  "fs-extra": "^11.1.1",
13
13
  "node-fetch": "^2.6.11",
14
14
  "yaml": "^2.3.1",
15
- "@goast/core": "0.0.6",
15
+ "@goast/core": "0.1.0",
16
16
  "tslib": "^2.3.0"
17
17
  },
18
18
  "module": "./esm/index.js",
@@ -11,6 +11,7 @@ export interface KotlinModelGenerator<TOutput extends Output = Output> {
11
11
  export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Context, Output> implements KotlinModelGenerator {
12
12
  generate(ctx: KotlinModelGeneratorContext): KotlinModelGeneratorOutput;
13
13
  protected generateFileContent(ctx: Context, builder: Builder): void;
14
+ protected generateTypeUsage(ctx: Context, builder: Builder, schema: ApiSchema): void;
14
15
  protected generateObjectType(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
15
16
  protected generateObjectPackageMember(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
16
17
  protected generateObjectInterface(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
@@ -30,7 +31,7 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
30
31
  protected generateArrayType(ctx: Context, builder: Builder, schema: ApiSchema<'array'>): void;
31
32
  protected generateDocumentation(ctx: Context, builder: Builder, schema: ApiSchema): void;
32
33
  protected shouldGenerateTypeDeclaration(ctx: Context, schema: ApiSchema): boolean;
33
- protected getDeclarationTypeName(ctx: Context): string;
34
+ protected getDeclarationTypeName(ctx: Context, schema: ApiSchema): string;
34
35
  protected sortProperties(ctx: Context, schema: ApiSchema, properties: Iterable<ApiSchemaProperty>): ApiSchemaProperty[];
35
36
  private hasProperty;
36
37
  }
@@ -19,5 +19,4 @@ export type KotlinModelGeneratorOutput = KotlinImport & {
19
19
  export type KotlinModelsGeneratorContext = OpenApiSchemasGenerationProviderContext<KotlinModelsGeneratorInput, KotlinModelsGeneratorOutput, KotlinModelsGeneratorConfig, KotlinModelGeneratorOutput>;
20
20
  export type KotlinModelGeneratorContext = KotlinModelsGeneratorContext & {
21
21
  schema: ApiSchema;
22
- getSchemaResult(schema: ApiSchema): KotlinModelGeneratorOutput;
23
22
  };