@goast/kotlin 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +7 -0
  2. package/cjs/index.js +9 -0
  3. package/cjs/lib/common-results.js +2 -0
  4. package/cjs/lib/config.js +9 -0
  5. package/cjs/lib/file-builder.js +63 -0
  6. package/cjs/lib/generators/file-generator.js +17 -0
  7. package/cjs/lib/generators/index.js +6 -0
  8. package/cjs/lib/generators/models/index.js +6 -0
  9. package/cjs/lib/generators/models/model-generator.js +337 -0
  10. package/cjs/lib/generators/models/models-generator.js +28 -0
  11. package/cjs/lib/generators/models/models.js +5 -0
  12. package/cjs/lib/generators/services/spring-controllers/index.js +6 -0
  13. package/cjs/lib/generators/services/spring-controllers/models.js +5 -0
  14. package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +416 -0
  15. package/cjs/lib/generators/services/spring-controllers/spring-controllers-generator.js +30 -0
  16. package/cjs/lib/import-collection.js +70 -0
  17. package/cjs/lib/utils.js +22 -0
  18. package/cjs/package.json +1 -0
  19. package/esm/index.js +6 -0
  20. package/esm/lib/common-results.js +1 -0
  21. package/esm/lib/config.js +6 -0
  22. package/esm/lib/file-builder.js +59 -0
  23. package/esm/lib/generators/file-generator.js +13 -0
  24. package/esm/lib/generators/index.js +3 -0
  25. package/esm/lib/generators/models/index.js +3 -0
  26. package/esm/lib/generators/models/model-generator.js +333 -0
  27. package/esm/lib/generators/models/models-generator.js +24 -0
  28. package/esm/lib/generators/models/models.js +2 -0
  29. package/esm/lib/generators/services/spring-controllers/index.js +3 -0
  30. package/esm/lib/generators/services/spring-controllers/models.js +2 -0
  31. package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +412 -0
  32. package/esm/lib/generators/services/spring-controllers/spring-controllers-generator.js +26 -0
  33. package/esm/lib/import-collection.js +66 -0
  34. package/esm/lib/utils.js +17 -0
  35. package/package.json +29 -0
  36. package/types/index.d.ts +6 -0
  37. package/types/lib/common-results.d.ts +4 -0
  38. package/types/lib/config.d.ts +6 -0
  39. package/types/lib/file-builder.d.ts +14 -0
  40. package/types/lib/generators/file-generator.d.ts +8 -0
  41. package/types/lib/generators/index.d.ts +3 -0
  42. package/types/lib/generators/models/index.d.ts +3 -0
  43. package/types/lib/generators/models/model-generator.d.ts +31 -0
  44. package/types/lib/generators/models/models-generator.d.ts +17 -0
  45. package/types/lib/generators/models/models.d.ts +22 -0
  46. package/types/lib/generators/services/spring-controllers/index.d.ts +3 -0
  47. package/types/lib/generators/services/spring-controllers/models.d.ts +24 -0
  48. package/types/lib/generators/services/spring-controllers/spring-controller-generator.d.ts +63 -0
  49. package/types/lib/generators/services/spring-controllers/spring-controllers-generator.d.ts +17 -0
  50. package/types/lib/import-collection.d.ts +13 -0
  51. package/types/lib/utils.d.ts +3 -0
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # kotlin
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test kotlin` to execute the unit tests via [Jest](https://jestjs.io).
package/cjs/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/common-results"), exports);
5
+ tslib_1.__exportStar(require("./lib/config"), exports);
6
+ tslib_1.__exportStar(require("./lib/generators"), exports);
7
+ tslib_1.__exportStar(require("./lib/file-builder"), exports);
8
+ tslib_1.__exportStar(require("./lib/import-collection"), exports);
9
+ tslib_1.__exportStar(require("./lib/utils"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultKotlinGeneratorConfig = void 0;
4
+ exports.defaultKotlinGeneratorConfig = {
5
+ charsTreatedAsEmptyLine: ['{'],
6
+ indent: { type: 'spaces', count: 4 },
7
+ propertyNameCasing: 'camel',
8
+ enumValueNameCasing: 'snake',
9
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KotlinFileBuilder = void 0;
4
+ const core_1 = require("@goast/core");
5
+ const import_collection_1 = require("./import-collection");
6
+ class KotlinFileBuilder extends core_1.SourceBuilder {
7
+ constructor(packageName, options) {
8
+ super(options);
9
+ this.imports = new import_collection_1.ImportCollection();
10
+ this.packageName = packageName;
11
+ }
12
+ addImport(name, packageName) {
13
+ if (packageName !== undefined && packageName !== this.packageName) {
14
+ this.imports.addImport(name, packageName);
15
+ }
16
+ return this;
17
+ }
18
+ appendAnnotation(name, packageName, args) {
19
+ const allArgs = [];
20
+ if (args) {
21
+ for (const a of args) {
22
+ if (!Array.isArray(a)) {
23
+ allArgs.push([undefined, a]);
24
+ }
25
+ else if (a.length === 2 && a[1] === true) {
26
+ allArgs.push([undefined, a[0]]);
27
+ }
28
+ }
29
+ for (const a of args) {
30
+ if (Array.isArray(a) && typeof a[1] !== 'boolean' && a[2] !== false) {
31
+ allArgs.push(a.length === 2 ? a : [a[0], a[1]]);
32
+ }
33
+ }
34
+ }
35
+ this.append(`@${name}`).addImport(name, packageName);
36
+ if (allArgs.length > 0) {
37
+ const multiline = allArgs.some((x) => typeof x[1] !== 'string') ||
38
+ allArgs.reduce((c, [key, value]) => { var _a; return c + (key ? key.length + 3 : 0) + ((_a = value === null || value === void 0 ? void 0 : value.length) !== null && _a !== void 0 ? _a : 0); }, 0) > 80;
39
+ this.parenthesize('()', (builder) => builder
40
+ .appendLineIf(multiline)
41
+ .forEachSeparated(allArgs, multiline ? ',\n' : ', ', (builder, [name, value]) => builder
42
+ .append(name ? `${name} = ` : '')
43
+ .apply((builder) => (typeof value === 'string' ? builder.append(value) : value(builder))))
44
+ .appendLineIf(multiline));
45
+ }
46
+ this.appendLine();
47
+ return this;
48
+ }
49
+ clear() {
50
+ super.clear();
51
+ this.imports.clear();
52
+ }
53
+ toString(addPadding = true) {
54
+ return new core_1.SourceBuilder(this.options)
55
+ .applyIf(this.packageName !== undefined, (builder) => builder.appendLine(`package ${this.packageName}`).appendLine())
56
+ .apply((builder) => this.imports.writeTo(builder))
57
+ .applyIf(addPadding, (builder) => builder.ensurePreviousLineEmpty())
58
+ .append(super.toString())
59
+ .applyIf(addPadding, (builder) => builder.ensureCurrentLineEmpty())
60
+ .toString();
61
+ }
62
+ }
63
+ exports.KotlinFileBuilder = KotlinFileBuilder;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KotlinFileGenerator = void 0;
4
+ const core_1 = require("@goast/core");
5
+ const utils_1 = require("../utils");
6
+ class KotlinFileGenerator {
7
+ toPropertyName(context, name) {
8
+ return (0, utils_1.toKotlinPropertyName)((0, core_1.toCasing)(name, context.config.propertyNameCasing));
9
+ }
10
+ toEnumValueName(context, name) {
11
+ return (0, utils_1.toKotlinPropertyName)((0, core_1.toCasing)(name, context.config.enumValueNameCasing));
12
+ }
13
+ toStringLiteral(context, text) {
14
+ return (0, utils_1.toKotlinStringLiteral)(text);
15
+ }
16
+ }
17
+ exports.KotlinFileGenerator = KotlinFileGenerator;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./file-generator"), exports);
5
+ tslib_1.__exportStar(require("./models"), exports);
6
+ tslib_1.__exportStar(require("./services/spring-controllers"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./model-generator"), exports);
5
+ tslib_1.__exportStar(require("./models"), exports);
6
+ tslib_1.__exportStar(require("./models-generator"), exports);
@@ -0,0 +1,337 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultKotlinModelGenerator = void 0;
4
+ const path_1 = require("path");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const core_1 = require("@goast/core");
7
+ const file_builder_1 = require("../../file-builder");
8
+ const file_generator_1 = require("../file-generator");
9
+ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
10
+ generate(ctx) {
11
+ if (/\/(anyOf|allOf)(\/[0-9]+)?$/.test(ctx.schema.$src.path)) {
12
+ // Do not generate types that are only used for anyOf and/or allOf
13
+ return { typeName: 'Any?', packageName: undefined, additionalImports: [] };
14
+ }
15
+ if (ctx.schema.id === ctx.schema.name) {
16
+ // TODO: Add this to @goast/core
17
+ const match = ctx.schema.$src.path.match(/\/components\/responses\/([^/]+)\/content\/.+\/schema/);
18
+ if (match) {
19
+ ctx.schema.name = match[1].toLowerCase().endsWith('response') ? match[1] : match[1] + 'Response';
20
+ }
21
+ }
22
+ if (ctx.schema.isNameGenerated) {
23
+ // TODO: Change this in @goast/core
24
+ const match = ctx.schema.$src.path.match(/\/paths\/(?<path>.+)\/(?<method>.+)\/responses\/(?<status>\d+)\//);
25
+ if (match && match.groups) {
26
+ const { path, method, status } = match.groups;
27
+ const endpoint = ctx.data.endpoints.find((e) => e.path === path && e.method === method);
28
+ if (endpoint) {
29
+ ctx.schema.name = `${endpoint.name}${status}Response`;
30
+ }
31
+ }
32
+ }
33
+ if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
34
+ const typeName = this.getDeclarationTypeName(ctx);
35
+ const packageName = ctx.config.packageName + ctx.config.packageSuffix;
36
+ const filePath = `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${typeName}.kt`;
37
+ console.log(`Generating model ${packageName}.${typeName} to ${filePath}...`);
38
+ (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(filePath));
39
+ const builder = new file_builder_1.KotlinFileBuilder(packageName, ctx.config);
40
+ this.generateFileContent(ctx, builder);
41
+ (0, fs_extra_1.writeFileSync)(filePath, builder.toString());
42
+ return { typeName, packageName, additionalImports: [] };
43
+ }
44
+ else {
45
+ const builder = new file_builder_1.KotlinFileBuilder(undefined, ctx.config);
46
+ this.generateType(ctx, builder, ctx.schema);
47
+ const additionalImports = builder.imports.imports;
48
+ builder.imports.clear();
49
+ return { typeName: builder.toString(false), packageName: undefined, additionalImports };
50
+ }
51
+ }
52
+ generateFileContent(ctx, builder) {
53
+ let schema = ctx.schema;
54
+ if (schema.kind === 'object' || schema.kind === 'combined') {
55
+ const mergedSchema = (0, core_1.resolveAnyOfAndAllOf)(schema, true);
56
+ if (mergedSchema) {
57
+ schema = mergedSchema;
58
+ }
59
+ }
60
+ if (schema.kind === 'object') {
61
+ this.generateObjectType(ctx, builder, schema);
62
+ }
63
+ else if (schema.enum !== undefined && schema.enum.length > 0) {
64
+ this.generateEnum(ctx, builder, schema);
65
+ }
66
+ else {
67
+ this.generateType(ctx, builder, schema);
68
+ }
69
+ }
70
+ generateObjectType(ctx, builder, schema) {
71
+ if (schema.properties.size === 0) {
72
+ if (schema.additionalProperties) {
73
+ this.generateMapType(ctx, builder, schema);
74
+ }
75
+ else {
76
+ builder.append('Any');
77
+ }
78
+ }
79
+ else {
80
+ this.generateDataClass(ctx, builder, schema);
81
+ }
82
+ }
83
+ generateDataClass(ctx, builder, schema) {
84
+ builder
85
+ .apply((builder) => this.generateDocumentation(ctx, builder, schema))
86
+ .append('data class ')
87
+ .append(this.getDeclarationTypeName(ctx))
88
+ .parenthesizeIf(schema.properties.size > 0, '()', (builder) => builder
89
+ .appendLine()
90
+ .forEachSeparated(this.sortProperties(ctx, schema, schema.properties.values()), ',\n', (builder, property) => builder
91
+ .ensurePreviousLineEmpty()
92
+ .apply((builder) => this.generatePropertyAnnotations(ctx, builder, schema, property))
93
+ .append(`val ${(0, core_1.toCasing)(property.name, 'camel')}: `)
94
+ .apply((builder) => this.generateType(ctx, builder, property.schema))
95
+ .applyIf(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?').append(' = null')))
96
+ .appendLineIf(schema.properties.size > 0))
97
+ .parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder
98
+ .appendLine()
99
+ .applyIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
100
+ .appendLine('@JsonIgnore')
101
+ .addImport('JsonIgnore', 'com.fasterxml.jackson.annotation')
102
+ .append('val additionalProperties: Mutable')
103
+ .apply((builder) => this.generateMapType(ctx, builder, schema))
104
+ .appendLine(' = mutableMapOf()')
105
+ .appendLine()
106
+ .appendLine('@JsonAnySetter')
107
+ .addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation')
108
+ .append('fun set')
109
+ .parenthesize('()', (builder) => builder.append('name: String, value: ').applyIfElse(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateType(ctx, builder, schema.additionalProperties)))
110
+ .append(' ')
111
+ .parenthesize('{}', (builder) => builder.appendLine().appendLine('this.additionalProperties[name] = value'))
112
+ .appendLine()
113
+ .appendLine()
114
+ .appendLine('@JsonAnyGetter')
115
+ .addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation')
116
+ .append('fun getMap(): ')
117
+ .apply((builder) => this.generateMapType(ctx, builder, schema))
118
+ .append(' ')
119
+ .parenthesize('{}', (builder) => builder.appendLine().appendLine('return this.additionalProperties'))
120
+ .appendLine()));
121
+ }
122
+ generatePropertyAnnotations(ctx, builder, schema, property) {
123
+ this.generatePropertyValidationAnnotations(ctx, builder, schema, property);
124
+ this.generatePropertySchemaAnnotation(ctx, builder, schema, property);
125
+ this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
126
+ }
127
+ generatePropertyValidationAnnotations(ctx, builder, schema, property) {
128
+ if (property.schema.kind === 'string' && property.schema.pattern) {
129
+ builder
130
+ .append('@get:Pattern(regexp = ')
131
+ .append(this.toStringLiteral(ctx, property.schema.pattern))
132
+ .append(')')
133
+ .addImport('Pattern', 'jakarta.validation.constraints')
134
+ .appendLine();
135
+ }
136
+ if (this.shouldGenerateTypeDeclaration(ctx, property.schema)) {
137
+ builder.append('@field:Valid').addImport('Valid', 'jakarta.validation').appendLine();
138
+ }
139
+ }
140
+ generatePropertySchemaAnnotation(ctx, builder, schema, property) {
141
+ const parts = new Map();
142
+ if (property.schema.example !== undefined) {
143
+ parts.set('example', this.toStringLiteral(ctx, String(property.schema.example)));
144
+ }
145
+ if (schema.required.has(property.name)) {
146
+ parts.set('required', 'true');
147
+ }
148
+ if (property.schema.description !== undefined) {
149
+ parts.set('description', this.toStringLiteral(ctx, property.schema.description));
150
+ }
151
+ builder
152
+ .append('@Schema')
153
+ .addImport('Schema', 'io.swagger.v3.oas.annotations.media')
154
+ .parenthesizeIf(parts.size > 0, '()', (builder) => builder.forEachSeparated(parts.entries(), ', ', (builder, [key, value]) => builder.append(`${key} = ${value}`)))
155
+ .appendLine();
156
+ }
157
+ generateJsonPropertyAnnotation(ctx, builder, schema, property) {
158
+ builder
159
+ .append('@JsonProperty')
160
+ .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
161
+ .parenthesize('()', (builder) => builder
162
+ .append(this.toStringLiteral(ctx, property.name))
163
+ .appendIf(schema.required.has(property.name), ', required = true'))
164
+ .appendLine()
165
+ .applyIf(property.schema.custom['exclude-when-null'] === true, (builder) => builder
166
+ .append('@get:JsonInclude')
167
+ .addImport('JsonInclude', 'com.fasterxml.jackson.annotation')
168
+ .parenthesize('()', (builder) => builder.append('JsonInclude.Include.NON_NULL'))
169
+ .appendLine());
170
+ }
171
+ generateMapType(ctx, builder, schema) {
172
+ if (schema.additionalProperties === true) {
173
+ builder.append('Map<String, Any?>');
174
+ }
175
+ else if (typeof schema.additionalProperties === 'object') {
176
+ const propertiesType = schema.additionalProperties;
177
+ builder
178
+ .append('Map')
179
+ .parenthesize('<>', (builder) => builder.append('String, ').apply((builder) => this.generateType(ctx, builder, propertiesType)));
180
+ }
181
+ }
182
+ generateType(ctx, builder, schema) {
183
+ if (this.shouldGenerateTypeDeclaration(ctx, schema)) {
184
+ if (schema === ctx.schema) {
185
+ builder.append('Any?');
186
+ return;
187
+ }
188
+ const schemaResult = ctx.getSchemaResult(schema);
189
+ builder.append(schemaResult.typeName);
190
+ if (schemaResult.packageName) {
191
+ builder.addImport(schemaResult.typeName, schemaResult.packageName);
192
+ }
193
+ return;
194
+ }
195
+ switch (schema.kind) {
196
+ case 'boolean':
197
+ builder.append('Boolean');
198
+ break;
199
+ case 'integer':
200
+ case 'number':
201
+ this.generateNumberType(ctx, builder, schema);
202
+ break;
203
+ case 'string':
204
+ if (schema.enum !== undefined && schema.enum.length > 0) {
205
+ this.generateEnum(ctx, builder, schema);
206
+ }
207
+ else {
208
+ this.generateStringType(ctx, builder, schema);
209
+ }
210
+ break;
211
+ case 'null':
212
+ builder.append('null');
213
+ break;
214
+ case 'unknown':
215
+ builder.append('Any');
216
+ break;
217
+ case 'array':
218
+ this.generateArrayType(ctx, builder, schema);
219
+ break;
220
+ case 'object':
221
+ this.generateObjectType(ctx, builder, schema);
222
+ break;
223
+ case 'combined':
224
+ builder.append('Any');
225
+ break;
226
+ case 'multi-type':
227
+ builder.append('Any');
228
+ break;
229
+ case 'oneOf':
230
+ builder.append('Any');
231
+ break;
232
+ default:
233
+ builder.append('Any');
234
+ break;
235
+ }
236
+ if (schema.nullable) {
237
+ builder.append('?');
238
+ }
239
+ }
240
+ generateNumberType(ctx, builder, schema) {
241
+ switch (schema.format) {
242
+ case 'int32':
243
+ builder.append('Int');
244
+ break;
245
+ case 'int64':
246
+ builder.append('Long');
247
+ break;
248
+ case 'float':
249
+ builder.append('Float');
250
+ break;
251
+ case 'double':
252
+ builder.append('Double');
253
+ break;
254
+ default:
255
+ builder.append(schema.kind === 'integer' ? 'Int' : 'Double');
256
+ break;
257
+ }
258
+ }
259
+ generateStringType(ctx, builder, schema) {
260
+ switch (schema.format) {
261
+ case 'date-time':
262
+ builder.append('OffsetDateTime').addImport('OffsetDateTime', 'java.time');
263
+ break;
264
+ default:
265
+ builder.append('String');
266
+ break;
267
+ }
268
+ }
269
+ generateEnum(ctx, builder, schema) {
270
+ builder
271
+ .apply((builder) => this.generateDocumentation(ctx, builder, schema))
272
+ .append('enum class ')
273
+ .append(this.getDeclarationTypeName(ctx))
274
+ .append('(val value: String) ')
275
+ .parenthesize('{}', (builder) => {
276
+ var _a;
277
+ return builder
278
+ .appendLine()
279
+ .forEachSeparated((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder) => builder.appendLine(',').appendLine(), (builder, value) => builder
280
+ .append('@JsonProperty')
281
+ .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
282
+ .parenthesize('()', (builder) => builder.append(this.toStringLiteral(ctx, String(value))))
283
+ .appendLine()
284
+ .append((0, core_1.toCasing)(String(value), 'snake'))
285
+ .parenthesize('()', (builder) => builder.append(this.toStringLiteral(ctx, String(value)))))
286
+ .appendLine();
287
+ });
288
+ }
289
+ generateArrayType(ctx, builder, schema) {
290
+ builder.append('List').parenthesize('<>', (builder) => builder.applyIfElse(schema.items === undefined, (builder) => builder.append('Any?'), (builder) => this.generateType(ctx, builder, schema.items)));
291
+ }
292
+ generateDocumentation(ctx, builder, schema) {
293
+ var _a, _b;
294
+ const propertiesWithDescription = Array.from((_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : []).filter((p) => p.schema.description !== undefined);
295
+ if (schema.description !== undefined || propertiesWithDescription.length > 0) {
296
+ builder
297
+ .ensurePreviousLineEmpty()
298
+ .appendLine('/**')
299
+ .applyWithLinePrefix(' * ', (builder) => builder
300
+ .appendLineIf(!!schema.description, schema.description)
301
+ .forEach(propertiesWithDescription, (builder, property) => { var _a; return builder.appendLine(`@param ${(0, core_1.toCasing)(property.name, 'camel')} ${(_a = property.schema.description) === null || _a === void 0 ? void 0 : _a.trim()}`); }))
302
+ .appendLine(' */');
303
+ }
304
+ }
305
+ shouldGenerateTypeDeclaration(ctx, schema) {
306
+ // All enum types should have its own type declaration
307
+ if (schema.enum !== undefined && schema.enum.length > 0) {
308
+ return true;
309
+ }
310
+ // All primitive types already exist and do not need its own type declaration
311
+ if (schema.kind !== 'combined' &&
312
+ schema.kind !== 'multi-type' &&
313
+ schema.kind !== 'object' &&
314
+ schema.kind !== 'oneOf') {
315
+ return false;
316
+ }
317
+ // Only object types with properties should have its own type declaration
318
+ if (schema.kind === 'object' &&
319
+ schema.properties.size === 0 &&
320
+ schema.anyOf.length === 0 &&
321
+ schema.allOf.length === 0) {
322
+ return false;
323
+ }
324
+ return true;
325
+ }
326
+ getDeclarationTypeName(ctx) {
327
+ return (0, core_1.toCasing)(ctx.schema.name, 'pascal');
328
+ }
329
+ sortProperties(ctx, schema, properties) {
330
+ return [...properties].sort((a, b) => {
331
+ const aRequired = schema.required.has(a.name) ? 1 : 0;
332
+ const bRequired = schema.required.has(b.name) ? 1 : 0;
333
+ return bRequired - aRequired;
334
+ });
335
+ }
336
+ }
337
+ exports.DefaultKotlinModelGenerator = DefaultKotlinModelGenerator;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KotlinModelsGenerator = void 0;
4
+ const core_1 = require("@goast/core");
5
+ const model_generator_1 = require("./model-generator");
6
+ const models_1 = require("./models");
7
+ class KotlinModelsGenerator extends core_1.OpenApiSchemasGenerationProviderBase {
8
+ constructor(modelGeneratorFactory) {
9
+ super();
10
+ this._modelGeneratorFactory = modelGeneratorFactory !== null && modelGeneratorFactory !== void 0 ? modelGeneratorFactory : core_1.Factory.fromValue(new model_generator_1.DefaultKotlinModelGenerator());
11
+ }
12
+ initResult() {
13
+ return {
14
+ models: {},
15
+ };
16
+ }
17
+ buildContext(context, config) {
18
+ return this.getProviderContext(context, config, models_1.defaultKotlinModelsGeneratorConfig);
19
+ }
20
+ generateSchema(ctx, schema) {
21
+ const modelGenerator = this._modelGeneratorFactory.create();
22
+ return modelGenerator.generate(Object.assign(Object.assign({}, ctx), { schema, getSchemaResult: (schema) => this.getSchemaResult(ctx, schema) }));
23
+ }
24
+ addSchemaResult(ctx, schema, result) {
25
+ ctx.output.models[schema.id] = result;
26
+ }
27
+ }
28
+ exports.KotlinModelsGenerator = KotlinModelsGenerator;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultKotlinModelsGeneratorConfig = void 0;
4
+ const config_1 = require("../../config");
5
+ exports.defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model' });
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./models"), exports);
5
+ tslib_1.__exportStar(require("./spring-controller-generator"), exports);
6
+ tslib_1.__exportStar(require("./spring-controllers-generator"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultKotlinServicesGeneratorConfig = void 0;
4
+ const config_1 = require("../../../config");
5
+ exports.defaultKotlinServicesGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.api' });