@goast/kotlin 0.1.5 → 0.1.7

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'],
@@ -132,49 +132,50 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
132
132
  .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
133
133
  .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?').append(' = null')));
134
134
  }
135
- generateObjectDataClass(ctx, builder, schema) {
136
- const inheritedSchemas = schema.inheritedSchemas
137
- .filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
138
- .filter((item, index, self) => self.indexOf(item) === index);
135
+ generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property) {
139
136
  builder
140
- .append((builder) => this.generateDocumentation(ctx, builder, schema))
141
- .append('data class ')
142
- .append(this.getDeclarationTypeName(ctx, schema))
143
- .parenthesizeIf(schema.properties.size > 0, '()', (builder) => builder.forEach(this.sortProperties(ctx, schema, schema.properties.values()), (builder, property) => builder
144
137
  .ensurePreviousLineEmpty()
145
138
  .append((builder) => this.generateObjectDataClassParameterAnnotations(ctx, builder, schema, property))
146
139
  .appendIf(inheritedSchemas.some((x) => this.hasProperty(ctx, x, property.name)), 'override ')
147
140
  .append(`val ${(0, core_1.toCasing)(property.name, 'camel')}: `)
148
141
  .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
149
142
  .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?'))
150
- .appendIf(property.schema.default !== undefined || !schema.required.has(property.name), ' = ', (builder) => this.generateDefaultValue(ctx, builder, property.schema)), { separator: ',\n' }), { multiline: true })
143
+ .appendIf(property.schema.default !== undefined || !schema.required.has(property.name), ' = ', (builder) => this.generateDefaultValue(ctx, builder, property.schema));
144
+ }
145
+ generateObjectDataClass(ctx, builder, schema) {
146
+ const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
147
+ const { params, properties } = this.classifyClassProperties(ctx, schema);
148
+ builder
149
+ .append((builder) => this.generateDocumentation(ctx, builder, schema))
150
+ .append('data class ')
151
+ .append(this.getDeclarationTypeName(ctx, schema))
152
+ .parenthesizeIf(schema.properties.size > 0, '()', (builder) => builder.forEach(params, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true })
151
153
  .if(inheritedSchemas.length > 0, (builder) => builder
152
154
  .append(' : ')
153
155
  .forEach(inheritedSchemas, (builder, schema) => this.generateTypeUsage(ctx, builder, schema), {
154
156
  separator: ', ',
155
157
  }))
156
158
  .append(' ')
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')
159
+ .parenthesizeIf((schema.additionalProperties !== undefined && schema.additionalProperties !== false) || properties.length > 0, '{}', (builder) => builder
160
+ .if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
161
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
160
162
  .append('val additionalProperties: Mutable')
161
163
  .append((builder) => this.generateMapType(ctx, builder, schema))
162
164
  .appendLine(' = mutableMapOf()')
163
165
  .appendLine()
164
- .appendLine('@JsonAnySetter')
165
- .addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation')
166
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnySetter').addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation'))
166
167
  .append('fun set')
167
168
  .parenthesize('()', (builder) => builder.append('name: String, value: ').if(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.additionalProperties)))
168
169
  .append(' ')
169
170
  .parenthesize('{}', 'this.additionalProperties[name] = value', { multiline: true })
170
171
  .appendLine()
171
172
  .appendLine()
172
- .appendLine('@JsonAnyGetter')
173
- .addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation')
173
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnyGetter').addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation'))
174
174
  .append('fun getMap(): ')
175
175
  .append((builder) => this.generateMapType(ctx, builder, schema))
176
176
  .append(' ')
177
- .parenthesize('{}', 'return this.additionalProperties', { multiline: true })), { multiline: true });
177
+ .parenthesize('{}', 'return this.additionalProperties', { multiline: true }))
178
+ .forEach(properties, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true });
178
179
  }
179
180
  generateDefaultValue(ctx, builder, schema) {
180
181
  if (schema.default === null || schema.default === undefined) {
@@ -212,48 +213,52 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
212
213
  this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
213
214
  }
214
215
  generatePropertyValidationAnnotations(ctx, builder, schema, property) {
215
- if (property.schema.kind === 'string' && property.schema.pattern) {
216
- builder
217
- .append('@get:Pattern(regexp = ')
218
- .append(this.toStringLiteral(ctx, property.schema.pattern))
219
- .append(')')
220
- .addImport('Pattern', 'jakarta.validation.constraints')
221
- .appendLine();
222
- }
223
- if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
224
- builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
216
+ if (ctx.config.addJakartaValidationAnnotations) {
217
+ if (property.schema.kind === 'string' && property.schema.pattern) {
218
+ builder
219
+ .append('@get:Pattern(regexp = ')
220
+ .append(this.toStringLiteral(ctx, property.schema.pattern))
221
+ .append(')')
222
+ .addImport('Pattern', 'jakarta.validation.constraints')
223
+ .appendLine();
224
+ }
225
+ if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
226
+ builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
227
+ }
225
228
  }
226
229
  }
227
230
  generatePropertySchemaAnnotation(ctx, builder, schema, property) {
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));
231
+ if (ctx.config.addSwaggerAnnotations) {
232
+ const parts = new Map();
233
+ if (property.schema.example !== undefined) {
234
+ parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
235
+ }
236
+ if (schema.required.has(property.name)) {
237
+ parts.set('required', 'true');
238
+ }
239
+ if (property.schema.description !== undefined) {
240
+ parts.set('description', this.toStringLiteral(ctx, property.schema.description));
241
+ }
242
+ builder
243
+ .append('@Schema')
244
+ .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
245
+ .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
246
+ separator: ', ',
247
+ }))
248
+ .appendLine();
237
249
  }
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();
245
250
  }
246
251
  generateJsonPropertyAnnotation(ctx, builder, schema, property, scope) {
247
252
  builder
253
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
248
254
  .append(`@${scope ? scope + ':' : ''}JsonProperty`)
249
255
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
250
256
  .parenthesize('()', (builder) => builder
251
257
  .append(this.toStringLiteral(ctx, property.name))
252
258
  .appendIf(schema.required.has(property.name), ', required = true'))
253
- .appendLine()
259
+ .appendLine())
254
260
  .if(property.schema.custom['exclude-when-null'] === true, (builder) => builder
255
- .append('@get:JsonInclude')
256
- .addImport('JsonInclude', 'com.fasterxml.jackson.annotation')
261
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.append('@get:JsonInclude').addImport('JsonInclude', 'com.fasterxml.jackson.annotation'))
257
262
  .parenthesize('()', 'JsonInclude.Include.NON_NULL')
258
263
  .appendLine());
259
264
  }
@@ -352,10 +357,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
352
357
  .parenthesize('{}', (builder) => {
353
358
  var _a;
354
359
  return builder.forEach((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder, value) => builder
360
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
355
361
  .append('@JsonProperty')
356
362
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
357
363
  .parenthesize('()', this.toStringLiteral(ctx, String(value)))
358
- .appendLine()
364
+ .appendLine())
359
365
  .append((0, core_1.toCasing)(String(value), 'snake'))
360
366
  .parenthesize('()', this.toStringLiteral(ctx, String(value))), { separator: (builder) => builder.appendLine(',').appendLine() });
361
367
  }, { multiline: true });
@@ -408,10 +414,36 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
408
414
  getDeclarationTypeName(ctx, schema) {
409
415
  return (0, core_1.toCasing)(schema.name, 'pascal');
410
416
  }
417
+ getInheritedSchemas(ctx, schema) {
418
+ return schema.inheritedSchemas
419
+ .filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
420
+ .filter((item, index, self) => self.indexOf(item) === index);
421
+ }
422
+ classifyClassProperties(ctx, schema) {
423
+ var _a, _b;
424
+ const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
425
+ const result = { params: [], properties: [] };
426
+ for (const property of schema.properties.values()) {
427
+ const discriminator = (_a = inheritedSchemas.find((x) => { var _a; return ((_a = x.discriminator) === null || _a === void 0 ? void 0 : _a.propertyName) === property.name; })) === null || _a === void 0 ? void 0 : _a.discriminator;
428
+ if (discriminator) {
429
+ const value = (_b = Object.entries(discriminator.mapping).find(([_, v]) => v.id === schema.id)) === null || _b === void 0 ? void 0 : _b[0];
430
+ if (value) {
431
+ const p = (0, core_1.createOverwriteProxy)(property);
432
+ const s = (0, core_1.createOverwriteProxy)(p.schema);
433
+ p.schema = s;
434
+ s.default = value;
435
+ result.properties.push(p);
436
+ continue;
437
+ }
438
+ }
439
+ result.params.push(property);
440
+ }
441
+ return result;
442
+ }
411
443
  sortProperties(ctx, schema, properties) {
412
444
  return [...properties].sort((a, b) => {
413
- const aRequired = schema.required.has(a.name) ? 1 : 0;
414
- const bRequired = schema.required.has(b.name) ? 1 : 0;
445
+ const aRequired = schema.required.has(a.name) || schema.default ? 1 : 0;
446
+ const bRequired = schema.required.has(b.name) || schema.default ? 1 : 0;
415
447
  return bRequired - aRequired;
416
448
  });
417
449
  }
@@ -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));
@@ -1,6 +1,6 @@
1
1
  import { dirname } from 'path';
2
2
  import { ensureDirSync, writeFileSync } from 'fs-extra';
3
- import { getSchemaReference, resolveAnyOfAndAllOf, toCasing, } from '@goast/core';
3
+ import { createOverwriteProxy, getSchemaReference, resolveAnyOfAndAllOf, toCasing, } from '@goast/core';
4
4
  import { KotlinFileBuilder } from '../../file-builder';
5
5
  import { KotlinFileGenerator } from '../file-generator';
6
6
  export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
@@ -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'],
@@ -129,49 +129,50 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
129
129
  .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
130
130
  .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?').append(' = null')));
131
131
  }
132
- generateObjectDataClass(ctx, builder, schema) {
133
- const inheritedSchemas = schema.inheritedSchemas
134
- .filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
135
- .filter((item, index, self) => self.indexOf(item) === index);
132
+ generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property) {
136
133
  builder
137
- .append((builder) => this.generateDocumentation(ctx, builder, schema))
138
- .append('data class ')
139
- .append(this.getDeclarationTypeName(ctx, schema))
140
- .parenthesizeIf(schema.properties.size > 0, '()', (builder) => builder.forEach(this.sortProperties(ctx, schema, schema.properties.values()), (builder, property) => builder
141
134
  .ensurePreviousLineEmpty()
142
135
  .append((builder) => this.generateObjectDataClassParameterAnnotations(ctx, builder, schema, property))
143
136
  .appendIf(inheritedSchemas.some((x) => this.hasProperty(ctx, x, property.name)), 'override ')
144
137
  .append(`val ${toCasing(property.name, 'camel')}: `)
145
138
  .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
146
139
  .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?'))
147
- .appendIf(property.schema.default !== undefined || !schema.required.has(property.name), ' = ', (builder) => this.generateDefaultValue(ctx, builder, property.schema)), { separator: ',\n' }), { multiline: true })
140
+ .appendIf(property.schema.default !== undefined || !schema.required.has(property.name), ' = ', (builder) => this.generateDefaultValue(ctx, builder, property.schema));
141
+ }
142
+ generateObjectDataClass(ctx, builder, schema) {
143
+ const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
144
+ const { params, properties } = this.classifyClassProperties(ctx, schema);
145
+ builder
146
+ .append((builder) => this.generateDocumentation(ctx, builder, schema))
147
+ .append('data class ')
148
+ .append(this.getDeclarationTypeName(ctx, schema))
149
+ .parenthesizeIf(schema.properties.size > 0, '()', (builder) => builder.forEach(params, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true })
148
150
  .if(inheritedSchemas.length > 0, (builder) => builder
149
151
  .append(' : ')
150
152
  .forEach(inheritedSchemas, (builder, schema) => this.generateTypeUsage(ctx, builder, schema), {
151
153
  separator: ', ',
152
154
  }))
153
155
  .append(' ')
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')
156
+ .parenthesizeIf((schema.additionalProperties !== undefined && schema.additionalProperties !== false) || properties.length > 0, '{}', (builder) => builder
157
+ .if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
158
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
157
159
  .append('val additionalProperties: Mutable')
158
160
  .append((builder) => this.generateMapType(ctx, builder, schema))
159
161
  .appendLine(' = mutableMapOf()')
160
162
  .appendLine()
161
- .appendLine('@JsonAnySetter')
162
- .addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation')
163
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnySetter').addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation'))
163
164
  .append('fun set')
164
165
  .parenthesize('()', (builder) => builder.append('name: String, value: ').if(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.additionalProperties)))
165
166
  .append(' ')
166
167
  .parenthesize('{}', 'this.additionalProperties[name] = value', { multiline: true })
167
168
  .appendLine()
168
169
  .appendLine()
169
- .appendLine('@JsonAnyGetter')
170
- .addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation')
170
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnyGetter').addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation'))
171
171
  .append('fun getMap(): ')
172
172
  .append((builder) => this.generateMapType(ctx, builder, schema))
173
173
  .append(' ')
174
- .parenthesize('{}', 'return this.additionalProperties', { multiline: true })), { multiline: true });
174
+ .parenthesize('{}', 'return this.additionalProperties', { multiline: true }))
175
+ .forEach(properties, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true });
175
176
  }
176
177
  generateDefaultValue(ctx, builder, schema) {
177
178
  if (schema.default === null || schema.default === undefined) {
@@ -209,48 +210,52 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
209
210
  this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
210
211
  }
211
212
  generatePropertyValidationAnnotations(ctx, builder, schema, property) {
212
- if (property.schema.kind === 'string' && property.schema.pattern) {
213
- builder
214
- .append('@get:Pattern(regexp = ')
215
- .append(this.toStringLiteral(ctx, property.schema.pattern))
216
- .append(')')
217
- .addImport('Pattern', 'jakarta.validation.constraints')
218
- .appendLine();
219
- }
220
- if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
221
- builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
213
+ if (ctx.config.addJakartaValidationAnnotations) {
214
+ if (property.schema.kind === 'string' && property.schema.pattern) {
215
+ builder
216
+ .append('@get:Pattern(regexp = ')
217
+ .append(this.toStringLiteral(ctx, property.schema.pattern))
218
+ .append(')')
219
+ .addImport('Pattern', 'jakarta.validation.constraints')
220
+ .appendLine();
221
+ }
222
+ if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
223
+ builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
224
+ }
222
225
  }
223
226
  }
224
227
  generatePropertySchemaAnnotation(ctx, builder, schema, property) {
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));
228
+ if (ctx.config.addSwaggerAnnotations) {
229
+ const parts = new Map();
230
+ if (property.schema.example !== undefined) {
231
+ parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
232
+ }
233
+ if (schema.required.has(property.name)) {
234
+ parts.set('required', 'true');
235
+ }
236
+ if (property.schema.description !== undefined) {
237
+ parts.set('description', this.toStringLiteral(ctx, property.schema.description));
238
+ }
239
+ builder
240
+ .append('@Schema')
241
+ .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
242
+ .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEach(parts.entries(), (builder, [key, value]) => builder.append(`${key} = ${value}`), {
243
+ separator: ', ',
244
+ }))
245
+ .appendLine();
234
246
  }
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();
242
247
  }
243
248
  generateJsonPropertyAnnotation(ctx, builder, schema, property, scope) {
244
249
  builder
250
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
245
251
  .append(`@${scope ? scope + ':' : ''}JsonProperty`)
246
252
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
247
253
  .parenthesize('()', (builder) => builder
248
254
  .append(this.toStringLiteral(ctx, property.name))
249
255
  .appendIf(schema.required.has(property.name), ', required = true'))
250
- .appendLine()
256
+ .appendLine())
251
257
  .if(property.schema.custom['exclude-when-null'] === true, (builder) => builder
252
- .append('@get:JsonInclude')
253
- .addImport('JsonInclude', 'com.fasterxml.jackson.annotation')
258
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder.append('@get:JsonInclude').addImport('JsonInclude', 'com.fasterxml.jackson.annotation'))
254
259
  .parenthesize('()', 'JsonInclude.Include.NON_NULL')
255
260
  .appendLine());
256
261
  }
@@ -349,10 +354,11 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
349
354
  .parenthesize('{}', (builder) => {
350
355
  var _a;
351
356
  return builder.forEach((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder, value) => builder
357
+ .if(ctx.config.addJacksonAnnotations, (builder) => builder
352
358
  .append('@JsonProperty')
353
359
  .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
354
360
  .parenthesize('()', this.toStringLiteral(ctx, String(value)))
355
- .appendLine()
361
+ .appendLine())
356
362
  .append(toCasing(String(value), 'snake'))
357
363
  .parenthesize('()', this.toStringLiteral(ctx, String(value))), { separator: (builder) => builder.appendLine(',').appendLine() });
358
364
  }, { multiline: true });
@@ -405,10 +411,36 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
405
411
  getDeclarationTypeName(ctx, schema) {
406
412
  return toCasing(schema.name, 'pascal');
407
413
  }
414
+ getInheritedSchemas(ctx, schema) {
415
+ return schema.inheritedSchemas
416
+ .filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
417
+ .filter((item, index, self) => self.indexOf(item) === index);
418
+ }
419
+ classifyClassProperties(ctx, schema) {
420
+ var _a, _b;
421
+ const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
422
+ const result = { params: [], properties: [] };
423
+ for (const property of schema.properties.values()) {
424
+ const discriminator = (_a = inheritedSchemas.find((x) => { var _a; return ((_a = x.discriminator) === null || _a === void 0 ? void 0 : _a.propertyName) === property.name; })) === null || _a === void 0 ? void 0 : _a.discriminator;
425
+ if (discriminator) {
426
+ const value = (_b = Object.entries(discriminator.mapping).find(([_, v]) => v.id === schema.id)) === null || _b === void 0 ? void 0 : _b[0];
427
+ if (value) {
428
+ const p = createOverwriteProxy(property);
429
+ const s = createOverwriteProxy(p.schema);
430
+ p.schema = s;
431
+ s.default = value;
432
+ result.properties.push(p);
433
+ continue;
434
+ }
435
+ }
436
+ result.params.push(property);
437
+ }
438
+ return result;
439
+ }
408
440
  sortProperties(ctx, schema, properties) {
409
441
  return [...properties].sort((a, b) => {
410
- const aRequired = schema.required.has(a.name) ? 1 : 0;
411
- const bRequired = schema.required.has(b.name) ? 1 : 0;
442
+ const aRequired = schema.required.has(a.name) || schema.default ? 1 : 0;
443
+ const bRequired = schema.required.has(b.name) || schema.default ? 1 : 0;
412
444
  return bRequired - aRequired;
413
445
  });
414
446
  }
@@ -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.5",
3
+ "version": "0.1.7",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -18,6 +18,7 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
18
18
  protected generateObjectInterfaceAnnotations(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
19
19
  protected generateObjectInterfaceSignature(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
20
20
  protected generateObjectInterfaceMembers(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
21
+ protected generateObjectDataClassProperty(ctx: Context, builder: Builder, schema: ApiSchema<'object'>, inheritedSchemas: ApiSchema[], property: ApiSchemaProperty): void;
21
22
  protected generateObjectDataClass(ctx: Context, builder: Builder, schema: ApiSchema<'object'>): void;
22
23
  protected generateDefaultValue(ctx: Context, builder: Builder, schema: ApiSchema): void;
23
24
  protected generateObjectDataClassParameterAnnotations(ctx: Context, builder: Builder, schema: ApiSchema, property: ApiSchemaProperty): void;
@@ -33,6 +34,11 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
33
34
  protected generateDocumentation(ctx: Context, builder: Builder, schema: ApiSchema): void;
34
35
  protected shouldGenerateTypeDeclaration(ctx: Context, schema: ApiSchema): boolean;
35
36
  protected getDeclarationTypeName(ctx: Context, schema: ApiSchema): string;
37
+ protected getInheritedSchemas(ctx: KotlinModelGeneratorContext, schema: ApiSchema): ApiSchema<import("@goast/core").ApiSchemaKind>[];
38
+ protected classifyClassProperties(ctx: Context, schema: ApiSchema<'object'>): {
39
+ params: ApiSchemaProperty[];
40
+ properties: ApiSchemaProperty[];
41
+ };
36
42
  protected sortProperties(ctx: Context, schema: ApiSchema, properties: Iterable<ApiSchemaProperty>): ApiSchemaProperty[];
37
43
  private normalizeSchema;
38
44
  private hasProperty;
@@ -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;