@goast/kotlin 0.1.4 → 0.1.6

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.
@@ -107,7 +107,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
107
107
  .parenthesize('{}', (builder) => this.generateObjectInterfaceMembers(ctx, builder, schema), { multiline: true });
108
108
  }
109
109
  generateObjectInterfaceAnnotations(ctx, builder, schema) {
110
- if (schema.discriminator) {
110
+ if (schema.discriminator && ctx.config.addJacksonAnnotations) {
111
111
  builder.appendAnnotation('JsonTypeInfo', 'com.fasterxml.jackson.annotation', [
112
112
  ['use', 'JsonTypeInfo.Id.NAME'],
113
113
  ['include', 'JsonTypeInfo.As.EXISTING_PROPERTY'],
@@ -155,22 +155,19 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
155
155
  }))
156
156
  .append(' ')
157
157
  .parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
158
- .appendLine('@JsonIgnore')
159
- .addImport('JsonIgnore', 'com.fasterxml.jackson.annotation')
158
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
160
159
  .append('val additionalProperties: Mutable')
161
160
  .append((builder) => this.generateMapType(ctx, builder, schema))
162
161
  .appendLine(' = mutableMapOf()')
163
162
  .appendLine()
164
- .appendLine('@JsonAnySetter')
165
- .addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation')
163
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnySetter').addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation'))
166
164
  .append('fun set')
167
165
  .parenthesize('()', (builder) => builder.append('name: String, value: ').if(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.additionalProperties)))
168
166
  .append(' ')
169
167
  .parenthesize('{}', 'this.additionalProperties[name] = value', { multiline: true })
170
168
  .appendLine()
171
169
  .appendLine()
172
- .appendLine('@JsonAnyGetter')
173
- .addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation')
170
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnyGetter').addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation'))
174
171
  .append('fun getMap(): ')
175
172
  .append((builder) => this.generateMapType(ctx, builder, schema))
176
173
  .append(' ')
@@ -190,7 +187,15 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
190
187
  builder.append(String(schema.default));
191
188
  break;
192
189
  case 'string':
193
- builder.append(this.toStringLiteral(ctx, String(schema.default)));
190
+ if (schema.enum && schema.enum.length > 0) {
191
+ builder
192
+ .append((builder) => this.generateTypeUsage(ctx, builder, schema))
193
+ .append('.')
194
+ .append((0, core_1.toCasing)(String(schema.default), ctx.config.enumValueNameCasing));
195
+ }
196
+ else {
197
+ builder.append(this.toStringLiteral(ctx, String(schema.default)));
198
+ }
194
199
  break;
195
200
  default:
196
201
  builder.append('null');
@@ -204,48 +209,52 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
204
209
  this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
205
210
  }
206
211
  generatePropertyValidationAnnotations(ctx, builder, schema, property) {
207
- if (property.schema.kind === 'string' && property.schema.pattern) {
208
- builder
209
- .append('@get:Pattern(regexp = ')
210
- .append(this.toStringLiteral(ctx, property.schema.pattern))
211
- .append(')')
212
- .addImport('Pattern', 'jakarta.validation.constraints')
213
- .appendLine();
214
- }
215
- if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
216
- builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
212
+ if (ctx.config.addJakartaValidationAnnotations) {
213
+ if (property.schema.kind === 'string' && property.schema.pattern) {
214
+ builder
215
+ .append('@get:Pattern(regexp = ')
216
+ .append(this.toStringLiteral(ctx, property.schema.pattern))
217
+ .append(')')
218
+ .addImport('Pattern', 'jakarta.validation.constraints')
219
+ .appendLine();
220
+ }
221
+ if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
222
+ builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
223
+ }
217
224
  }
218
225
  }
219
226
  generatePropertySchemaAnnotation(ctx, builder, schema, property) {
220
- const parts = new Map();
221
- if (property.schema.example !== undefined) {
222
- parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
223
- }
224
- if (schema.required.has(property.name)) {
225
- parts.set('required', 'true');
226
- }
227
- if (property.schema.description !== undefined) {
228
- parts.set('description', this.toStringLiteral(ctx, property.schema.description));
227
+ if (ctx.config.addSwaggerAnnotations) {
228
+ const parts = new Map();
229
+ if (property.schema.example !== undefined) {
230
+ parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
231
+ }
232
+ if (schema.required.has(property.name)) {
233
+ parts.set('required', 'true');
234
+ }
235
+ if (property.schema.description !== undefined) {
236
+ parts.set('description', this.toStringLiteral(ctx, property.schema.description));
237
+ }
238
+ builder
239
+ .append('@Schema')
240
+ .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
241
+ .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
242
+ separator: ', ',
243
+ }))
244
+ .appendLine();
229
245
  }
230
- builder
231
- .append('@Schema')
232
- .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
233
- .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
234
- separator: ', ',
235
- }))
236
- .appendLine();
237
246
  }
238
247
  generateJsonPropertyAnnotation(ctx, builder, schema, property, scope) {
239
248
  builder
249
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
240
250
  .append(`@${scope ? scope + ':' : ''}JsonProperty`)
241
251
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
242
252
  .parenthesize('()', (builder) => builder
243
253
  .append(this.toStringLiteral(ctx, property.name))
244
254
  .appendIf(schema.required.has(property.name), ', required = true'))
245
- .appendLine()
255
+ .appendLine())
246
256
  .if(property.schema.custom['exclude-when-null'] === true, (builder) => builder
247
- .append('@get:JsonInclude')
248
- .addImport('JsonInclude', 'com.fasterxml.jackson.annotation')
257
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.append('@get:JsonInclude').addImport('JsonInclude', 'com.fasterxml.jackson.annotation'))
249
258
  .parenthesize('()', 'JsonInclude.Include.NON_NULL')
250
259
  .appendLine());
251
260
  }
@@ -344,10 +353,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
344
353
  .parenthesize('{}', (builder) => {
345
354
  var _a;
346
355
  return builder.forEach((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder, value) => builder
356
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
347
357
  .append('@JsonProperty')
348
358
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
349
359
  .parenthesize('()', this.toStringLiteral(ctx, String(value)))
350
- .appendLine()
360
+ .appendLine())
351
361
  .append((0, core_1.toCasing)(String(value), 'snake'))
352
362
  .parenthesize('()', this.toStringLiteral(ctx, String(value))), { separator: (builder) => builder.appendLine(',').appendLine() });
353
363
  }, { multiline: true });
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultKotlinModelsGeneratorConfig = void 0;
4
4
  const config_1 = require("../../config");
5
- exports.defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of' });
5
+ exports.defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of', addJacksonAnnotations: true, addJakartaValidationAnnotations: true, addSwaggerAnnotations: true });
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultKotlinServicesGeneratorConfig = void 0;
4
4
  const config_1 = require("../../../config");
5
- exports.defaultKotlinServicesGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api' });
5
+ exports.defaultKotlinServicesGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api', addSwaggerAnnotations: true, addJakartaValidationAnnotations: true });
@@ -69,32 +69,35 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
69
69
  });
70
70
  }
71
71
  generateApiInterfaceMethodAnnnotations(ctx, builder, endpoint) {
72
- var _a, _b, _c;
72
+ var _a;
73
73
  builder
74
- .appendAnnotation('Operation', 'io.swagger.v3.oas.annotations', [
75
- ['summary', this.toStringLiteral(ctx, (_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())],
76
- ['operationId', this.toStringLiteral(ctx, endpoint.name)],
77
- ['description', this.toStringLiteral(ctx, (_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())],
78
- [
79
- 'responses',
80
- (builder) => builder.parenthesize('[]', (builder) => builder.forEach(endpoint.responses, (builder, response) => builder
81
- .append('ApiResponse')
82
- .addImport('ApiResponse', 'io.swagger.v3.oas.annotations.responses')
83
- .parenthesize('()', (builder) => {
84
- var _a, _b;
85
- return builder
86
- .append(`responseCode = ${this.toStringLiteral(ctx, (_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())}, `)
87
- .append(`description = ${this.toStringLiteral(ctx, (_b = response.description) === null || _b === void 0 ? void 0 : _b.trim())}`);
88
- }), { separator: ',\n' }), { multiline: true }),
89
- endpoint.responses.length > 0,
90
- ],
91
- ])
74
+ .if(ctx.config.addSwaggerAnnotations, (builder) => {
75
+ var _a, _b;
76
+ return builder.appendAnnotation('Operation', 'io.swagger.v3.oas.annotations', [
77
+ ['summary', this.toStringLiteral(ctx, (_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())],
78
+ ['operationId', this.toStringLiteral(ctx, endpoint.name)],
79
+ ['description', this.toStringLiteral(ctx, (_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())],
80
+ [
81
+ 'responses',
82
+ (builder) => builder.parenthesize('[]', (builder) => builder.forEach(endpoint.responses, (builder, response) => builder
83
+ .append('ApiResponse')
84
+ .addImport('ApiResponse', 'io.swagger.v3.oas.annotations.responses')
85
+ .parenthesize('()', (builder) => {
86
+ var _a, _b;
87
+ return builder
88
+ .append(`responseCode = ${this.toStringLiteral(ctx, (_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())}, `)
89
+ .append(`description = ${this.toStringLiteral(ctx, (_b = response.description) === null || _b === void 0 ? void 0 : _b.trim())}`);
90
+ }), { separator: ',\n' }), { multiline: true }),
91
+ endpoint.responses.length > 0,
92
+ ],
93
+ ]);
94
+ })
92
95
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
93
96
  ['method', '[RequestMethod.' + endpoint.method.toUpperCase() + ']'],
94
97
  ['value', '[' + this.toStringLiteral(ctx, this.getEndpointPath(ctx, endpoint)) + ']'],
95
98
  [
96
99
  'consumes',
97
- '[' + ((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
100
+ '[' + ((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
98
101
  !!endpoint.requestBody && endpoint.requestBody.content.length > 0,
99
102
  ],
100
103
  ])
@@ -126,19 +129,21 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
126
129
  generateApiInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter) {
127
130
  var _a, _b, _c, _d, _e, _f, _g, _h;
128
131
  const parameterSchemaInfo = this.getSchemaInfo(ctx, parameter.schema);
129
- if (((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) !== undefined) {
130
- builder.addImport('Schema', 'io.swagger.v3.oas.annotations.media');
132
+ if (ctx.config.addSwaggerAnnotations) {
133
+ if (((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) !== undefined) {
134
+ builder.addImport('Schema', 'io.swagger.v3.oas.annotations.media');
135
+ }
136
+ builder.appendAnnotation('Parameter', 'io.swagger.v3.oas.annotations', [
137
+ ['description', this.toStringLiteral(ctx, (_b = parameter.description) === null || _b === void 0 ? void 0 : _b.trim())],
138
+ ['required', (_c = parameter.required) === null || _c === void 0 ? void 0 : _c.toString()],
139
+ [
140
+ 'schema',
141
+ `Schema(defaultValue = ${this.toStringLiteral(ctx, String((_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default))})`,
142
+ ((_e = parameter.schema) === null || _e === void 0 ? void 0 : _e.default) !== undefined,
143
+ ],
144
+ ]);
131
145
  }
132
- builder.appendAnnotation('Parameter', 'io.swagger.v3.oas.annotations', [
133
- ['description', this.toStringLiteral(ctx, (_b = parameter.description) === null || _b === void 0 ? void 0 : _b.trim())],
134
- ['required', (_c = parameter.required) === null || _c === void 0 ? void 0 : _c.toString()],
135
- [
136
- 'schema',
137
- `Schema(defaultValue = ${this.toStringLiteral(ctx, String((_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default))})`,
138
- ((_e = parameter.schema) === null || _e === void 0 ? void 0 : _e.default) !== undefined,
139
- ],
140
- ]);
141
- if (parameterSchemaInfo.packageName) {
146
+ if (parameterSchemaInfo.packageName && ctx.config.addJakartaValidationAnnotations) {
142
147
  builder.appendAnnotation('Valid', 'jakarta.validation');
143
148
  }
144
149
  if (parameter.target === 'body') {
@@ -198,9 +203,9 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
198
203
  }
199
204
  generateApiControllerAnnotations(ctx, builder) {
200
205
  builder
201
- .appendAnnotation('Generated', 'jakarta.annotation', [
206
+ .if(ctx.config.addJakartaValidationAnnotations, (builder) => builder.appendAnnotation('Generated', 'jakarta.annotation', [
202
207
  ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
203
- ])
208
+ ]))
204
209
  .appendAnnotation('Controller', 'org.springframework.stereotype')
205
210
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
206
211
  this.getControllerRequestMapping(ctx),
@@ -254,9 +259,11 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
254
259
  .parenthesize('{}', (builder) => this.generateApiDelegateInterfaceContent(ctx, builder), { multiline: true });
255
260
  }
256
261
  generateApiDelegateInterfaceAnnotations(ctx, builder) {
257
- builder.appendAnnotation('Generated', 'jakarta.annotation', [
258
- ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
259
- ]);
262
+ if (ctx.config.addJakartaValidationAnnotations) {
263
+ builder.appendAnnotation('Generated', 'jakarta.annotation', [
264
+ ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
265
+ ]);
266
+ }
260
267
  }
261
268
  generateApiDelegateInterfaceSignature(ctx, builder) {
262
269
  builder.append('interface ').append(this.getApiDelegateInterfaceName(ctx));
@@ -104,7 +104,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
104
104
  .parenthesize('{}', (builder) => this.generateObjectInterfaceMembers(ctx, builder, schema), { multiline: true });
105
105
  }
106
106
  generateObjectInterfaceAnnotations(ctx, builder, schema) {
107
- if (schema.discriminator) {
107
+ if (schema.discriminator && ctx.config.addJacksonAnnotations) {
108
108
  builder.appendAnnotation('JsonTypeInfo', 'com.fasterxml.jackson.annotation', [
109
109
  ['use', 'JsonTypeInfo.Id.NAME'],
110
110
  ['include', 'JsonTypeInfo.As.EXISTING_PROPERTY'],
@@ -152,22 +152,19 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
152
152
  }))
153
153
  .append(' ')
154
154
  .parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
155
- .appendLine('@JsonIgnore')
156
- .addImport('JsonIgnore', 'com.fasterxml.jackson.annotation')
155
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
157
156
  .append('val additionalProperties: Mutable')
158
157
  .append((builder) => this.generateMapType(ctx, builder, schema))
159
158
  .appendLine(' = mutableMapOf()')
160
159
  .appendLine()
161
- .appendLine('@JsonAnySetter')
162
- .addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation')
160
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnySetter').addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation'))
163
161
  .append('fun set')
164
162
  .parenthesize('()', (builder) => builder.append('name: String, value: ').if(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.additionalProperties)))
165
163
  .append(' ')
166
164
  .parenthesize('{}', 'this.additionalProperties[name] = value', { multiline: true })
167
165
  .appendLine()
168
166
  .appendLine()
169
- .appendLine('@JsonAnyGetter')
170
- .addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation')
167
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnyGetter').addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation'))
171
168
  .append('fun getMap(): ')
172
169
  .append((builder) => this.generateMapType(ctx, builder, schema))
173
170
  .append(' ')
@@ -187,7 +184,15 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
187
184
  builder.append(String(schema.default));
188
185
  break;
189
186
  case 'string':
190
- builder.append(this.toStringLiteral(ctx, String(schema.default)));
187
+ if (schema.enum && schema.enum.length > 0) {
188
+ builder
189
+ .append((builder) => this.generateTypeUsage(ctx, builder, schema))
190
+ .append('.')
191
+ .append(toCasing(String(schema.default), ctx.config.enumValueNameCasing));
192
+ }
193
+ else {
194
+ builder.append(this.toStringLiteral(ctx, String(schema.default)));
195
+ }
191
196
  break;
192
197
  default:
193
198
  builder.append('null');
@@ -201,48 +206,52 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
201
206
  this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
202
207
  }
203
208
  generatePropertyValidationAnnotations(ctx, builder, schema, property) {
204
- if (property.schema.kind === 'string' && property.schema.pattern) {
205
- builder
206
- .append('@get:Pattern(regexp = ')
207
- .append(this.toStringLiteral(ctx, property.schema.pattern))
208
- .append(')')
209
- .addImport('Pattern', 'jakarta.validation.constraints')
210
- .appendLine();
211
- }
212
- if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
213
- builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
209
+ if (ctx.config.addJakartaValidationAnnotations) {
210
+ if (property.schema.kind === 'string' && property.schema.pattern) {
211
+ builder
212
+ .append('@get:Pattern(regexp = ')
213
+ .append(this.toStringLiteral(ctx, property.schema.pattern))
214
+ .append(')')
215
+ .addImport('Pattern', 'jakarta.validation.constraints')
216
+ .appendLine();
217
+ }
218
+ if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
219
+ builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
220
+ }
214
221
  }
215
222
  }
216
223
  generatePropertySchemaAnnotation(ctx, builder, schema, property) {
217
- const parts = new Map();
218
- if (property.schema.example !== undefined) {
219
- parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
220
- }
221
- if (schema.required.has(property.name)) {
222
- parts.set('required', 'true');
223
- }
224
- if (property.schema.description !== undefined) {
225
- parts.set('description', this.toStringLiteral(ctx, property.schema.description));
224
+ if (ctx.config.addSwaggerAnnotations) {
225
+ const parts = new Map();
226
+ if (property.schema.example !== undefined) {
227
+ parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
228
+ }
229
+ if (schema.required.has(property.name)) {
230
+ parts.set('required', 'true');
231
+ }
232
+ if (property.schema.description !== undefined) {
233
+ parts.set('description', this.toStringLiteral(ctx, property.schema.description));
234
+ }
235
+ builder
236
+ .append('@Schema')
237
+ .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
238
+ .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
239
+ separator: ', ',
240
+ }))
241
+ .appendLine();
226
242
  }
227
- builder
228
- .append('@Schema')
229
- .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
230
- .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
231
- separator: ', ',
232
- }))
233
- .appendLine();
234
243
  }
235
244
  generateJsonPropertyAnnotation(ctx, builder, schema, property, scope) {
236
245
  builder
246
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
237
247
  .append(`@${scope ? scope + ':' : ''}JsonProperty`)
238
248
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
239
249
  .parenthesize('()', (builder) => builder
240
250
  .append(this.toStringLiteral(ctx, property.name))
241
251
  .appendIf(schema.required.has(property.name), ', required = true'))
242
- .appendLine()
252
+ .appendLine())
243
253
  .if(property.schema.custom['exclude-when-null'] === true, (builder) => builder
244
- .append('@get:JsonInclude')
245
- .addImport('JsonInclude', 'com.fasterxml.jackson.annotation')
254
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.append('@get:JsonInclude').addImport('JsonInclude', 'com.fasterxml.jackson.annotation'))
246
255
  .parenthesize('()', 'JsonInclude.Include.NON_NULL')
247
256
  .appendLine());
248
257
  }
@@ -341,10 +350,11 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
341
350
  .parenthesize('{}', (builder) => {
342
351
  var _a;
343
352
  return builder.forEach((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder, value) => builder
353
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
344
354
  .append('@JsonProperty')
345
355
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
346
356
  .parenthesize('()', this.toStringLiteral(ctx, String(value)))
347
- .appendLine()
357
+ .appendLine())
348
358
  .append(toCasing(String(value), 'snake'))
349
359
  .parenthesize('()', this.toStringLiteral(ctx, String(value))), { separator: (builder) => builder.appendLine(',').appendLine() });
350
360
  }, { multiline: true });
@@ -1,2 +1,2 @@
1
1
  import { defaultKotlinGeneratorConfig } from '../../config';
2
- export const defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of' });
2
+ export const defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of', addJacksonAnnotations: true, addJakartaValidationAnnotations: true, addSwaggerAnnotations: true });
@@ -1,2 +1,2 @@
1
1
  import { defaultKotlinGeneratorConfig } from '../../../config';
2
- export const defaultKotlinServicesGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api' });
2
+ export const defaultKotlinServicesGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api', addSwaggerAnnotations: true, addJakartaValidationAnnotations: true });
@@ -66,32 +66,35 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
66
66
  });
67
67
  }
68
68
  generateApiInterfaceMethodAnnnotations(ctx, builder, endpoint) {
69
- var _a, _b, _c;
69
+ var _a;
70
70
  builder
71
- .appendAnnotation('Operation', 'io.swagger.v3.oas.annotations', [
72
- ['summary', this.toStringLiteral(ctx, (_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())],
73
- ['operationId', this.toStringLiteral(ctx, endpoint.name)],
74
- ['description', this.toStringLiteral(ctx, (_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())],
75
- [
76
- 'responses',
77
- (builder) => builder.parenthesize('[]', (builder) => builder.forEach(endpoint.responses, (builder, response) => builder
78
- .append('ApiResponse')
79
- .addImport('ApiResponse', 'io.swagger.v3.oas.annotations.responses')
80
- .parenthesize('()', (builder) => {
81
- var _a, _b;
82
- return builder
83
- .append(`responseCode = ${this.toStringLiteral(ctx, (_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())}, `)
84
- .append(`description = ${this.toStringLiteral(ctx, (_b = response.description) === null || _b === void 0 ? void 0 : _b.trim())}`);
85
- }), { separator: ',\n' }), { multiline: true }),
86
- endpoint.responses.length > 0,
87
- ],
88
- ])
71
+ .if(ctx.config.addSwaggerAnnotations, (builder) => {
72
+ var _a, _b;
73
+ return builder.appendAnnotation('Operation', 'io.swagger.v3.oas.annotations', [
74
+ ['summary', this.toStringLiteral(ctx, (_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())],
75
+ ['operationId', this.toStringLiteral(ctx, endpoint.name)],
76
+ ['description', this.toStringLiteral(ctx, (_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())],
77
+ [
78
+ 'responses',
79
+ (builder) => builder.parenthesize('[]', (builder) => builder.forEach(endpoint.responses, (builder, response) => builder
80
+ .append('ApiResponse')
81
+ .addImport('ApiResponse', 'io.swagger.v3.oas.annotations.responses')
82
+ .parenthesize('()', (builder) => {
83
+ var _a, _b;
84
+ return builder
85
+ .append(`responseCode = ${this.toStringLiteral(ctx, (_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())}, `)
86
+ .append(`description = ${this.toStringLiteral(ctx, (_b = response.description) === null || _b === void 0 ? void 0 : _b.trim())}`);
87
+ }), { separator: ',\n' }), { multiline: true }),
88
+ endpoint.responses.length > 0,
89
+ ],
90
+ ]);
91
+ })
89
92
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
90
93
  ['method', '[RequestMethod.' + endpoint.method.toUpperCase() + ']'],
91
94
  ['value', '[' + this.toStringLiteral(ctx, this.getEndpointPath(ctx, endpoint)) + ']'],
92
95
  [
93
96
  'consumes',
94
- '[' + ((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
97
+ '[' + ((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.content.map((x) => this.toStringLiteral(ctx, x.type)).join(', ')) + ']',
95
98
  !!endpoint.requestBody && endpoint.requestBody.content.length > 0,
96
99
  ],
97
100
  ])
@@ -123,19 +126,21 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
123
126
  generateApiInterfaceMethodParameterAnnotations(ctx, builder, endpoint, parameter) {
124
127
  var _a, _b, _c, _d, _e, _f, _g, _h;
125
128
  const parameterSchemaInfo = this.getSchemaInfo(ctx, parameter.schema);
126
- if (((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) !== undefined) {
127
- builder.addImport('Schema', 'io.swagger.v3.oas.annotations.media');
129
+ if (ctx.config.addSwaggerAnnotations) {
130
+ if (((_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.default) !== undefined) {
131
+ builder.addImport('Schema', 'io.swagger.v3.oas.annotations.media');
132
+ }
133
+ builder.appendAnnotation('Parameter', 'io.swagger.v3.oas.annotations', [
134
+ ['description', this.toStringLiteral(ctx, (_b = parameter.description) === null || _b === void 0 ? void 0 : _b.trim())],
135
+ ['required', (_c = parameter.required) === null || _c === void 0 ? void 0 : _c.toString()],
136
+ [
137
+ 'schema',
138
+ `Schema(defaultValue = ${this.toStringLiteral(ctx, String((_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default))})`,
139
+ ((_e = parameter.schema) === null || _e === void 0 ? void 0 : _e.default) !== undefined,
140
+ ],
141
+ ]);
128
142
  }
129
- builder.appendAnnotation('Parameter', 'io.swagger.v3.oas.annotations', [
130
- ['description', this.toStringLiteral(ctx, (_b = parameter.description) === null || _b === void 0 ? void 0 : _b.trim())],
131
- ['required', (_c = parameter.required) === null || _c === void 0 ? void 0 : _c.toString()],
132
- [
133
- 'schema',
134
- `Schema(defaultValue = ${this.toStringLiteral(ctx, String((_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default))})`,
135
- ((_e = parameter.schema) === null || _e === void 0 ? void 0 : _e.default) !== undefined,
136
- ],
137
- ]);
138
- if (parameterSchemaInfo.packageName) {
143
+ if (parameterSchemaInfo.packageName && ctx.config.addJakartaValidationAnnotations) {
139
144
  builder.appendAnnotation('Valid', 'jakarta.validation');
140
145
  }
141
146
  if (parameter.target === 'body') {
@@ -195,9 +200,9 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
195
200
  }
196
201
  generateApiControllerAnnotations(ctx, builder) {
197
202
  builder
198
- .appendAnnotation('Generated', 'jakarta.annotation', [
203
+ .if(ctx.config.addJakartaValidationAnnotations, (builder) => builder.appendAnnotation('Generated', 'jakarta.annotation', [
199
204
  ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
200
- ])
205
+ ]))
201
206
  .appendAnnotation('Controller', 'org.springframework.stereotype')
202
207
  .appendAnnotation('RequestMapping', 'org.springframework.web.bind.annotation', [
203
208
  this.getControllerRequestMapping(ctx),
@@ -251,9 +256,11 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
251
256
  .parenthesize('{}', (builder) => this.generateApiDelegateInterfaceContent(ctx, builder), { multiline: true });
252
257
  }
253
258
  generateApiDelegateInterfaceAnnotations(ctx, builder) {
254
- builder.appendAnnotation('Generated', 'jakarta.annotation', [
255
- ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
256
- ]);
259
+ if (ctx.config.addJakartaValidationAnnotations) {
260
+ builder.appendAnnotation('Generated', 'jakarta.annotation', [
261
+ ['value', '[' + this.toStringLiteral(ctx, 'com.goast.kotlin.spring-service-generator') + ']'],
262
+ ]);
263
+ }
257
264
  }
258
265
  generateApiDelegateInterfaceSignature(ctx, builder) {
259
266
  builder.append('interface ').append(this.getApiDelegateInterfaceName(ctx));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/kotlin",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -5,6 +5,9 @@ export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
5
5
  packageName: string;
6
6
  packageSuffix: string;
7
7
  oneOfBehavior: 'treat-as-any-of' | 'treat-as-all-of';
8
+ addJacksonAnnotations: boolean;
9
+ addJakartaValidationAnnotations: boolean;
10
+ addSwaggerAnnotations: boolean;
8
11
  };
9
12
  export declare const defaultKotlinModelsGeneratorConfig: DefaultGenerationProviderConfig<KotlinModelsGeneratorConfig>;
10
13
  export type KotlinModelsGeneratorInput = {};
@@ -7,6 +7,8 @@ export type KotlinServicesGeneratorConfig = KotlinGeneratorConfig & {
7
7
  packageSuffix: string;
8
8
  basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
9
9
  pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
10
+ addSwaggerAnnotations: boolean;
11
+ addJakartaValidationAnnotations: boolean;
10
12
  };
11
13
  export declare const defaultKotlinServicesGeneratorConfig: DefaultGenerationProviderConfig<KotlinServicesGeneratorConfig>;
12
14
  export type KotlinServicesGeneratorInput = KotlinModelsGeneratorOutput;