@goast/kotlin 0.1.18 → 0.2.0

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 (179) hide show
  1. package/cjs/index.js +3 -0
  2. package/cjs/lib/ast/_index.js +81 -0
  3. package/cjs/lib/ast/common.js +2 -0
  4. package/cjs/lib/ast/index.js +5 -0
  5. package/cjs/lib/ast/node.js +10 -0
  6. package/cjs/lib/ast/nodes/annotation.js +39 -0
  7. package/cjs/lib/ast/nodes/argument.js +32 -0
  8. package/cjs/lib/ast/nodes/call.js +37 -0
  9. package/cjs/lib/ast/nodes/class.js +94 -0
  10. package/cjs/lib/ast/nodes/collection-literal.js +24 -0
  11. package/cjs/lib/ast/nodes/constructor.js +75 -0
  12. package/cjs/lib/ast/nodes/doc-tag.js +60 -0
  13. package/cjs/lib/ast/nodes/doc.js +55 -0
  14. package/cjs/lib/ast/nodes/enum-value.js +50 -0
  15. package/cjs/lib/ast/nodes/enum.js +83 -0
  16. package/cjs/lib/ast/nodes/function.js +105 -0
  17. package/cjs/lib/ast/nodes/generic-parameter.js +29 -0
  18. package/cjs/lib/ast/nodes/init-block.js +19 -0
  19. package/cjs/lib/ast/nodes/interface.js +68 -0
  20. package/cjs/lib/ast/nodes/lambda-type.js +44 -0
  21. package/cjs/lib/ast/nodes/lambda.js +36 -0
  22. package/cjs/lib/ast/nodes/object.js +58 -0
  23. package/cjs/lib/ast/nodes/parameter.js +57 -0
  24. package/cjs/lib/ast/nodes/property.js +142 -0
  25. package/cjs/lib/ast/nodes/reference.js +79 -0
  26. package/cjs/lib/ast/nodes/string.js +87 -0
  27. package/cjs/lib/ast/nodes/types.js +2 -0
  28. package/cjs/lib/ast/references/index.js +12 -0
  29. package/cjs/lib/ast/references/jackson.js +12 -0
  30. package/cjs/lib/ast/references/jakarta.js +10 -0
  31. package/cjs/lib/ast/references/java.js +14 -0
  32. package/cjs/lib/ast/references/kotlin.js +27 -0
  33. package/cjs/lib/ast/references/okhttp3.js +7 -0
  34. package/cjs/lib/ast/references/reactor.js +6 -0
  35. package/cjs/lib/ast/references/spring.js +21 -0
  36. package/cjs/lib/ast/references/swagger.js +11 -0
  37. package/cjs/lib/ast/utils/get-kotlin-builder-options.js +19 -0
  38. package/cjs/lib/ast/utils/to-kt-node.js +22 -0
  39. package/cjs/lib/ast/utils/write-kt-annotations.js +13 -0
  40. package/cjs/lib/ast/utils/write-kt-arguments.js +33 -0
  41. package/cjs/lib/ast/utils/write-kt-enum-values.js +17 -0
  42. package/cjs/lib/ast/utils/write-kt-generic-parameters.js +12 -0
  43. package/cjs/lib/ast/utils/write-kt-members.js +16 -0
  44. package/cjs/lib/ast/utils/write-kt-node.js +24 -0
  45. package/cjs/lib/ast/utils/write-kt-parameters.js +13 -0
  46. package/cjs/lib/config.js +15 -1
  47. package/cjs/lib/file-builder.js +17 -2
  48. package/cjs/lib/generators/models/args.js +2 -0
  49. package/cjs/lib/generators/models/index.js +2 -0
  50. package/cjs/lib/generators/models/model-generator.js +277 -322
  51. package/cjs/lib/generators/services/okhttp3-clients/args.js +2 -0
  52. package/cjs/lib/generators/services/okhttp3-clients/index.js +2 -0
  53. package/cjs/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +240 -348
  54. package/cjs/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
  55. package/cjs/lib/generators/services/okhttp3-clients/refs.js +34 -0
  56. package/cjs/lib/generators/services/spring-controllers/args.js +2 -0
  57. package/cjs/lib/generators/services/spring-controllers/index.js +2 -0
  58. package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +270 -346
  59. package/cjs/lib/import-collection.js +24 -15
  60. package/esm/index.js +3 -0
  61. package/esm/lib/ast/_index.js +27 -0
  62. package/esm/lib/ast/common.js +1 -0
  63. package/esm/lib/ast/index.js +2 -0
  64. package/esm/lib/ast/node.js +6 -0
  65. package/esm/lib/ast/nodes/annotation.js +35 -0
  66. package/esm/lib/ast/nodes/argument.js +28 -0
  67. package/esm/lib/ast/nodes/call.js +33 -0
  68. package/esm/lib/ast/nodes/class.js +90 -0
  69. package/esm/lib/ast/nodes/collection-literal.js +20 -0
  70. package/esm/lib/ast/nodes/constructor.js +71 -0
  71. package/esm/lib/ast/nodes/doc-tag.js +56 -0
  72. package/esm/lib/ast/nodes/doc.js +51 -0
  73. package/esm/lib/ast/nodes/enum-value.js +46 -0
  74. package/esm/lib/ast/nodes/enum.js +79 -0
  75. package/esm/lib/ast/nodes/function.js +101 -0
  76. package/esm/lib/ast/nodes/generic-parameter.js +25 -0
  77. package/esm/lib/ast/nodes/init-block.js +15 -0
  78. package/esm/lib/ast/nodes/interface.js +64 -0
  79. package/esm/lib/ast/nodes/lambda-type.js +40 -0
  80. package/esm/lib/ast/nodes/lambda.js +32 -0
  81. package/esm/lib/ast/nodes/object.js +54 -0
  82. package/esm/lib/ast/nodes/parameter.js +53 -0
  83. package/esm/lib/ast/nodes/property.js +135 -0
  84. package/esm/lib/ast/nodes/reference.js +75 -0
  85. package/esm/lib/ast/nodes/string.js +83 -0
  86. package/esm/lib/ast/nodes/types.js +1 -0
  87. package/esm/lib/ast/references/index.js +15 -0
  88. package/esm/lib/ast/references/jackson.js +9 -0
  89. package/esm/lib/ast/references/jakarta.js +7 -0
  90. package/esm/lib/ast/references/java.js +11 -0
  91. package/esm/lib/ast/references/kotlin.js +24 -0
  92. package/esm/lib/ast/references/okhttp3.js +4 -0
  93. package/esm/lib/ast/references/reactor.js +3 -0
  94. package/esm/lib/ast/references/spring.js +18 -0
  95. package/esm/lib/ast/references/swagger.js +8 -0
  96. package/esm/lib/ast/utils/get-kotlin-builder-options.js +15 -0
  97. package/esm/lib/ast/utils/to-kt-node.js +18 -0
  98. package/esm/lib/ast/utils/write-kt-annotations.js +9 -0
  99. package/esm/lib/ast/utils/write-kt-arguments.js +29 -0
  100. package/esm/lib/ast/utils/write-kt-enum-values.js +13 -0
  101. package/esm/lib/ast/utils/write-kt-generic-parameters.js +8 -0
  102. package/esm/lib/ast/utils/write-kt-members.js +12 -0
  103. package/esm/lib/ast/utils/write-kt-node.js +19 -0
  104. package/esm/lib/ast/utils/write-kt-parameters.js +9 -0
  105. package/esm/lib/config.js +15 -1
  106. package/esm/lib/file-builder.js +16 -2
  107. package/esm/lib/generators/models/args.js +1 -0
  108. package/esm/lib/generators/models/index.js +2 -0
  109. package/esm/lib/generators/models/model-generator.js +278 -323
  110. package/esm/lib/generators/services/okhttp3-clients/args.js +1 -0
  111. package/esm/lib/generators/services/okhttp3-clients/index.js +2 -0
  112. package/esm/lib/generators/services/okhttp3-clients/okhttp3-client-generator.js +242 -350
  113. package/esm/lib/generators/services/okhttp3-clients/okhttp3-clients-generator.js +4 -1
  114. package/esm/lib/generators/services/okhttp3-clients/refs.js +30 -0
  115. package/esm/lib/generators/services/spring-controllers/args.js +1 -0
  116. package/esm/lib/generators/services/spring-controllers/index.js +2 -0
  117. package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +269 -346
  118. package/esm/lib/import-collection.js +23 -14
  119. package/package.json +6 -6
  120. package/types/index.d.ts +2 -0
  121. package/types/lib/ast/_index.d.ts +28 -0
  122. package/types/lib/ast/common.d.ts +1 -0
  123. package/types/lib/ast/index.d.ts +1 -0
  124. package/types/lib/ast/node.d.ts +4 -0
  125. package/types/lib/ast/nodes/annotation.d.ts +23 -0
  126. package/types/lib/ast/nodes/argument.d.ts +22 -0
  127. package/types/lib/ast/nodes/call.d.ts +22 -0
  128. package/types/lib/ast/nodes/class.d.ts +54 -0
  129. package/types/lib/ast/nodes/collection-literal.d.ts +17 -0
  130. package/types/lib/ast/nodes/constructor.d.ts +34 -0
  131. package/types/lib/ast/nodes/doc-tag.d.ts +34 -0
  132. package/types/lib/ast/nodes/doc.d.ts +26 -0
  133. package/types/lib/ast/nodes/enum-value.d.ts +30 -0
  134. package/types/lib/ast/nodes/enum.d.ts +45 -0
  135. package/types/lib/ast/nodes/function.d.ts +58 -0
  136. package/types/lib/ast/nodes/generic-parameter.d.ts +21 -0
  137. package/types/lib/ast/nodes/init-block.d.ts +16 -0
  138. package/types/lib/ast/nodes/interface.d.ts +41 -0
  139. package/types/lib/ast/nodes/lambda-type.d.ts +21 -0
  140. package/types/lib/ast/nodes/lambda.d.ts +20 -0
  141. package/types/lib/ast/nodes/object.d.ts +34 -0
  142. package/types/lib/ast/nodes/parameter.d.ts +48 -0
  143. package/types/lib/ast/nodes/property.d.ts +87 -0
  144. package/types/lib/ast/nodes/reference.d.ts +63 -0
  145. package/types/lib/ast/nodes/string.d.ts +30 -0
  146. package/types/lib/ast/nodes/types.d.ts +10 -0
  147. package/types/lib/ast/references/index.d.ts +8 -0
  148. package/types/lib/ast/references/jackson.d.ts +77 -0
  149. package/types/lib/ast/references/jakarta.d.ts +33 -0
  150. package/types/lib/ast/references/java.d.ts +71 -0
  151. package/types/lib/ast/references/kotlin.d.ts +265 -0
  152. package/types/lib/ast/references/okhttp3.d.ts +22 -0
  153. package/types/lib/ast/references/reactor.d.ts +16 -0
  154. package/types/lib/ast/references/spring.d.ts +126 -0
  155. package/types/lib/ast/references/swagger.d.ts +44 -0
  156. package/types/lib/ast/utils/get-kotlin-builder-options.d.ts +3 -0
  157. package/types/lib/ast/utils/to-kt-node.d.ts +7 -0
  158. package/types/lib/ast/utils/write-kt-annotations.d.ts +5 -0
  159. package/types/lib/ast/utils/write-kt-arguments.d.ts +3 -0
  160. package/types/lib/ast/utils/write-kt-enum-values.d.ts +3 -0
  161. package/types/lib/ast/utils/write-kt-generic-parameters.d.ts +3 -0
  162. package/types/lib/ast/utils/write-kt-members.d.ts +5 -0
  163. package/types/lib/ast/utils/write-kt-node.d.ts +7 -0
  164. package/types/lib/ast/utils/write-kt-parameters.d.ts +3 -0
  165. package/types/lib/config.d.ts +4 -0
  166. package/types/lib/file-builder.d.ts +10 -3
  167. package/types/lib/generators/models/args.d.ts +99 -0
  168. package/types/lib/generators/models/index.d.ts +1 -0
  169. package/types/lib/generators/models/model-generator.d.ts +35 -32
  170. package/types/lib/generators/models/models.d.ts +4 -4
  171. package/types/lib/generators/services/okhttp3-clients/args.d.ts +66 -0
  172. package/types/lib/generators/services/okhttp3-clients/index.d.ts +1 -0
  173. package/types/lib/generators/services/okhttp3-clients/models.d.ts +2 -0
  174. package/types/lib/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +25 -47
  175. package/types/lib/generators/services/okhttp3-clients/refs.d.ts +235 -0
  176. package/types/lib/generators/services/spring-controllers/args.d.ts +70 -0
  177. package/types/lib/generators/services/spring-controllers/index.d.ts +1 -0
  178. package/types/lib/generators/services/spring-controllers/spring-controller-generator.d.ts +37 -51
  179. package/types/lib/import-collection.d.ts +7 -1
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultKotlinModelGenerator = void 0;
4
+ /* eslint-disable unused-imports/no-unused-vars */
4
5
  const path_1 = require("path");
5
6
  const fs_extra_1 = require("fs-extra");
6
7
  const core_1 = require("@goast/core");
8
+ const ast_1 = require("../../ast");
7
9
  const file_builder_1 = require("../../file-builder");
8
10
  const file_generator_1 = require("../file-generator");
9
11
  class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
10
12
  generate(ctx) {
11
13
  if (/\/(anyOf|allOf)(\/[0-9]+)?$/.test(ctx.schema.$src.path)) {
12
14
  // Do not generate types that are only used for anyOf and/or allOf
13
- return { typeName: 'Any?', packageName: undefined, additionalImports: [] };
15
+ return { type: ast_1.kt.refs.any({ nullable: true }) };
14
16
  }
15
17
  if (ctx.schema.id === ctx.schema.name) {
16
18
  // TODO: Add this to @goast/core
@@ -30,356 +32,306 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
30
32
  }
31
33
  }
32
34
  }
33
- if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
34
- const typeName = this.getDeclarationTypeName(ctx, ctx.schema);
35
- const packageName = this.getPackageName(ctx, ctx.schema);
35
+ if (this.shouldGenerateTypeDeclaration(ctx, { schema: ctx.schema })) {
36
+ const typeName = this.getDeclarationTypeName(ctx, { schema: ctx.schema });
37
+ const packageName = this.getPackageName(ctx, { schema: ctx.schema });
36
38
  const filePath = `${ctx.config.outputDir}/${packageName.replace(/\./g, '/')}/${typeName}.kt`;
37
39
  console.log(`Generating model ${packageName}.${typeName} to ${filePath}...`);
38
40
  (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: [] };
41
+ (0, fs_extra_1.writeFileSync)(filePath, new file_builder_1.KotlinFileBuilder(packageName, ctx.config).append(this.getFileContent(ctx, {})).toString());
42
+ return { type: ast_1.kt.reference(typeName, packageName) };
43
43
  }
44
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 };
45
+ return { type: this.getType(ctx, { schema: ctx.schema }) };
50
46
  }
51
47
  }
52
- generateFileContent(ctx, builder) {
53
- const schema = this.normalizeSchema(ctx, ctx.schema);
48
+ getFileContent(ctx, args) {
49
+ return (0, core_1.appendValueGroup)([this.getSchemaDeclaration(ctx, { schema: this.normalizeSchema(ctx, { schema: ctx.schema }) })], '\n\n');
50
+ }
51
+ getSchemaDeclaration(ctx, args) {
52
+ const { schema } = args;
54
53
  if (schema.kind === 'object') {
55
- this.generateObjectType(ctx, builder, schema);
54
+ return schema.discriminator ? this.getInterface(ctx, { schema }) : this.getClass(ctx, { schema });
56
55
  }
57
56
  else if (schema.enum !== undefined && schema.enum.length > 0) {
58
- this.generateEnum(ctx, builder, schema);
59
- }
60
- else {
61
- this.generateType(ctx, builder, schema);
57
+ return this.getEnum(ctx, { schema });
62
58
  }
59
+ return '// The generator was not able to generate this schema.\n// This should not happend. If you see this comment, please open an Issue on Github.';
63
60
  }
64
- generateTypeUsage(ctx, builder, schema) {
65
- schema = (0, core_1.getSchemaReference)(schema, ['description']);
66
- if (this.shouldGenerateTypeDeclaration(ctx, schema)) {
67
- const name = this.getDeclarationTypeName(ctx, schema);
68
- const packageName = this.getPackageName(ctx, schema);
69
- if (packageName) {
70
- builder.addImport(name, packageName);
71
- }
72
- builder.append(name);
73
- }
74
- else {
75
- this.generateType(ctx, builder, schema);
76
- }
61
+ getClass(ctx, args) {
62
+ var _a;
63
+ const { schema } = args;
64
+ const inheritedSchemas = this.getInheritedSchemas(ctx, { schema });
65
+ const parameters = this.getClassProperties(ctx, { schema });
66
+ return ast_1.kt.class(this.getDeclarationTypeName(ctx, { schema }), {
67
+ doc: ast_1.kt.doc((_a = schema.description) === null || _a === void 0 ? void 0 : _a.trim()),
68
+ classKind: parameters.length === 0 ? null : 'data',
69
+ implements: inheritedSchemas.map((schema) => this.getType(ctx, { schema })),
70
+ primaryConstructor: ast_1.kt.constructor(parameters.map((property) => this.getClassParameter(ctx, Object.assign(Object.assign({}, args), { inheritedSchemas, parameters, property })))),
71
+ members: [
72
+ ...(schema.additionalProperties !== undefined && schema.additionalProperties !== false
73
+ ? [
74
+ this.getAdditionalPropertiesProperty(ctx, { schema }),
75
+ this.getAdditionalPropertiesSetter(ctx, { schema }),
76
+ this.getAdditionalPropertiesGetter(ctx, { schema }),
77
+ ]
78
+ : []),
79
+ ],
80
+ });
77
81
  }
78
- generateObjectType(ctx, builder, schema) {
79
- if (schema.properties.size === 0 && schema.additionalProperties) {
80
- this.generateMapType(ctx, builder, schema);
81
- }
82
- else {
83
- this.generateObjectPackageMember(ctx, builder, schema);
84
- }
82
+ getInterface(ctx, args) {
83
+ var _a;
84
+ const { schema } = args;
85
+ return ast_1.kt.interface(this.getDeclarationTypeName(ctx, { schema }), {
86
+ doc: ast_1.kt.doc((_a = schema.description) === null || _a === void 0 ? void 0 : _a.trim()),
87
+ annotations: [
88
+ this.getJacksonJsonTypeInfoAnnotation(ctx, { schema }),
89
+ this.getJacksonJsonSubTypesAnnotation(ctx, { schema }),
90
+ ].filter(core_1.notNullish),
91
+ members: this.sortProperties(ctx, { schema, properties: schema.properties.values() }).map((property) => this.getInterfaceProperty(ctx, { schema, property })),
92
+ });
85
93
  }
86
- generateObjectPackageMember(ctx, builder, schema) {
87
- if (schema.discriminator) {
88
- this.generateObjectInterface(ctx, builder, schema);
94
+ getEnum(ctx, args) {
95
+ var _a, _b, _c;
96
+ const { schema } = args;
97
+ return ast_1.kt.enum(this.getDeclarationTypeName(ctx, { schema }), (_b = (_a = schema.enum) === null || _a === void 0 ? void 0 : _a.map((x) => ast_1.kt.enumValue((0, core_1.toCasing)(String(x), ctx.config.enumValueNameCasing), {
98
+ annotations: [ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonProperty(), [ast_1.kt.argument(ast_1.kt.string(String(x)))])],
99
+ arguments: [ast_1.kt.argument(ast_1.kt.string(String(x)))],
100
+ }))) !== null && _b !== void 0 ? _b : [], {
101
+ doc: ast_1.kt.doc((_c = schema.description) === null || _c === void 0 ? void 0 : _c.trim()),
102
+ primaryConstructor: ast_1.kt.constructor([
103
+ ast_1.kt.parameter.class((0, core_1.toCasing)('value', ctx.config.propertyNameCasing), ast_1.kt.refs.string(), {
104
+ property: 'readonly',
105
+ }),
106
+ ]),
107
+ });
108
+ }
109
+ getType(ctx, args) {
110
+ var _a;
111
+ const { schema } = args;
112
+ const generatedType = this.getGeneratedType(ctx, { schema, nullable: args.nullable });
113
+ if (generatedType) {
114
+ return generatedType;
89
115
  }
90
- else {
91
- this.generateObjectDataClass(ctx, builder, schema);
116
+ const nullable = (_a = args.nullable) !== null && _a !== void 0 ? _a : schema.nullable;
117
+ switch (schema.kind) {
118
+ case 'boolean':
119
+ return ast_1.kt.refs.boolean({ nullable });
120
+ case 'integer':
121
+ case 'number':
122
+ switch (schema.format) {
123
+ case 'int32':
124
+ return ast_1.kt.refs.int({ nullable });
125
+ case 'int64':
126
+ return ast_1.kt.refs.long({ nullable });
127
+ case 'float':
128
+ return ast_1.kt.refs.float({ nullable });
129
+ case 'double':
130
+ return ast_1.kt.refs.double({ nullable });
131
+ default:
132
+ return schema.kind === 'integer' ? ast_1.kt.refs.int({ nullable }) : ast_1.kt.refs.double({ nullable });
133
+ }
134
+ case 'string':
135
+ switch (schema.format) {
136
+ case 'date-time':
137
+ return ast_1.kt.refs.java.offsetDateTime({ nullable });
138
+ default:
139
+ return ast_1.kt.refs.string({ nullable });
140
+ }
141
+ case 'null':
142
+ return ast_1.kt.refs.nothing({ nullable });
143
+ case 'unknown':
144
+ return ast_1.kt.refs.any({ nullable });
145
+ case 'array':
146
+ return ast_1.kt.refs.list([schema.items ? this.getType(ctx, { schema: schema.items }) : ast_1.kt.refs.any({ nullable: true })], { nullable });
147
+ case 'object':
148
+ return schema.properties.size === 0 && schema.additionalProperties
149
+ ? ast_1.kt.refs.map([ast_1.kt.refs.string(), this.getAdditionalPropertiesType(ctx, { schema })], { nullable })
150
+ : ast_1.kt.refs.any({ nullable });
151
+ default:
152
+ return ast_1.kt.refs.any({ nullable });
92
153
  }
93
154
  }
94
- generateObjectInterface(ctx, builder, schema) {
95
- builder
96
- .append((builder) => this.generateDocumentation(ctx, builder, schema))
97
- .ensureCurrentLineEmpty()
98
- .append((builder) => this.generateObjectInterfaceAnnotations(ctx, builder, schema))
99
- .ensureCurrentLineEmpty()
100
- .append((builder) => this.generateObjectInterfaceSignature(ctx, builder, schema))
101
- .append(' ')
102
- .parenthesize('{}', (builder) => this.generateObjectInterfaceMembers(ctx, builder, schema), { multiline: true });
103
- }
104
- generateObjectInterfaceAnnotations(ctx, builder, schema) {
105
- if (schema.discriminator && ctx.config.addJacksonAnnotations) {
106
- builder.appendAnnotation('JsonTypeInfo', 'com.fasterxml.jackson.annotation', [
107
- ['use', 'JsonTypeInfo.Id.NAME'],
108
- ['include', 'JsonTypeInfo.As.EXISTING_PROPERTY'],
109
- ['property', this.toStringLiteral(ctx, schema.discriminator.propertyName)],
110
- ['visible', 'true'],
111
- ]);
112
- const entries = Object.entries(schema.discriminator.mapping);
113
- if (entries.length > 0) {
114
- builder.appendAnnotation('JsonSubTypes', 'com.fasterxml.jackson.annotation', entries.map(([value, schema]) => (builder) => builder.append('JsonSubTypes.Type(value = ', (builder) => this.generateTypeUsage(ctx, builder, schema), `::class, name = ${this.toStringLiteral(ctx, value)})`)));
115
- }
155
+ getGeneratedType(ctx, args) {
156
+ var _a;
157
+ const schema = (0, core_1.getSchemaReference)(args.schema, ['description']);
158
+ if (this.shouldGenerateTypeDeclaration(ctx, { schema })) {
159
+ return ast_1.kt.reference(this.getDeclarationTypeName(ctx, { schema }), this.getPackageName(ctx, { schema }), {
160
+ nullable: (_a = args.nullable) !== null && _a !== void 0 ? _a : schema.nullable,
161
+ });
116
162
  }
163
+ return null;
117
164
  }
118
- generateObjectInterfaceSignature(ctx, builder, schema) {
119
- builder.append('interface ').append(this.getDeclarationTypeName(ctx, schema));
120
- }
121
- generateObjectInterfaceMembers(ctx, builder, schema) {
122
- builder.forEach(this.sortProperties(ctx, schema, schema.properties.values()), (builder, property) => builder
123
- .ensurePreviousLineEmpty()
124
- .append((builder) => this.generateJsonPropertyAnnotation(ctx, builder, schema, property, 'get'))
125
- .ensureCurrentLineEmpty()
126
- .append(`val ${(0, core_1.toCasing)(property.name, 'camel')}: `)
127
- .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
128
- .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?')));
129
- }
130
- generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property) {
131
- builder
132
- .ensurePreviousLineEmpty()
133
- .append((builder) => this.generateObjectDataClassParameterAnnotations(ctx, builder, schema, property))
134
- .appendIf(inheritedSchemas.some((x) => this.hasProperty(ctx, x, property.name)), 'override ')
135
- .append(`val ${(0, core_1.toCasing)(property.name, 'camel')}: `)
136
- .append((builder) => this.generateTypeUsage(ctx, builder, property.schema))
137
- .if(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?'))
138
- .appendIf(property.schema.default !== undefined || !schema.required.has(property.name), ' = ', (builder) => this.generateDefaultValue(ctx, builder, property.schema));
165
+ getAdditionalPropertiesType(ctx, args) {
166
+ const { schema } = args;
167
+ return typeof schema.additionalProperties === 'object'
168
+ ? this.getType(ctx, { schema: schema.additionalProperties })
169
+ : ast_1.kt.refs.any({ nullable: true });
139
170
  }
140
- generateObjectDataClass(ctx, builder, schema) {
141
- const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
142
- const params = this.getClassProperties(ctx, schema);
143
- builder
144
- .append((builder) => this.generateDocumentation(ctx, builder, schema))
145
- .append(params.length === 0 ? 'class' : 'data class', ' ')
146
- .append(this.getDeclarationTypeName(ctx, schema))
147
- .parenthesizeIf(params.length > 0, '()', (builder) => builder.forEach(params, (builder, property) => this.generateObjectDataClassProperty(ctx, builder, schema, inheritedSchemas, property), { separator: ',\n' }), { multiline: true })
148
- .if(inheritedSchemas.length > 0, (builder) => builder
149
- .append(' : ')
150
- .forEach(inheritedSchemas, (builder, schema) => this.generateTypeUsage(ctx, builder, schema), {
151
- separator: ', ',
152
- }))
153
- .append(' ')
154
- .parenthesizeIf(schema.additionalProperties !== undefined && schema.additionalProperties !== false, '{}', (builder) => builder.if(schema.additionalProperties !== undefined && schema.additionalProperties !== false, (builder) => builder
155
- .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonIgnore').addImport('JsonIgnore', 'com.fasterxml.jackson.annotation'))
156
- .append('val additionalProperties: Mutable')
157
- .append((builder) => this.generateMapType(ctx, builder, schema))
158
- .appendLine(' = mutableMapOf()')
159
- .appendLine()
160
- .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnySetter').addImport('JsonAnySetter', 'com.fasterxml.jackson.annotation'))
161
- .append('fun set')
162
- .parenthesize('()', (builder) => builder.append('name: String, value: ').if(schema.additionalProperties === true, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.additionalProperties)))
163
- .append(' ')
164
- .parenthesize('{}', 'this.additionalProperties[name] = value', { multiline: true })
165
- .appendLine()
166
- .appendLine()
167
- .if(ctx.config.addJacksonAnnotations, (builder) => builder.appendLine('@JsonAnyGetter').addImport('JsonAnyGetter', 'com.fasterxml.jackson.annotation'))
168
- .append('fun getMap(): ')
169
- .append((builder) => this.generateMapType(ctx, builder, schema))
170
- .append(' ')
171
- .parenthesize('{}', 'return this.additionalProperties', { multiline: true })), { multiline: true });
172
- }
173
- generateDefaultValue(ctx, builder, schema) {
171
+ getDefaultValue(ctx, args) {
172
+ const { schema } = args;
174
173
  if (schema.default === null || schema.default === undefined) {
175
- builder.append('null');
174
+ return 'null';
176
175
  }
177
176
  else {
178
177
  switch (schema.kind) {
179
178
  case 'boolean':
180
- builder.append(Boolean(schema.default) || String(schema.default).toLowerCase() === 'true' ? 'true' : 'false');
181
- break;
179
+ return Boolean(schema.default) || String(schema.default).toLowerCase() === 'true' ? 'true' : 'false';
182
180
  case 'integer':
183
181
  case 'number':
184
- builder.append(String(schema.default));
185
- break;
182
+ return String(schema.default);
186
183
  case 'string':
187
- if (schema.enum && schema.enum.length > 0) {
188
- builder
189
- .append((builder) => this.generateTypeUsage(ctx, builder, schema))
190
- .append('.')
191
- .append((0, core_1.toCasing)(String(schema.default), ctx.config.enumValueNameCasing));
192
- }
193
- else {
194
- builder.append(this.toStringLiteral(ctx, String(schema.default)));
195
- }
196
- break;
184
+ return schema.enum && schema.enum.length > 0
185
+ ? ast_1.kt.call([this.getType(ctx, { schema }), (0, core_1.toCasing)(String(schema.default), ctx.config.enumValueNameCasing)])
186
+ : ast_1.kt.string(String(schema.default));
197
187
  default:
198
- builder.append('null');
199
- break;
188
+ return 'null';
200
189
  }
201
190
  }
202
191
  }
203
- generateObjectDataClassParameterAnnotations(ctx, builder, schema, property) {
204
- this.generatePropertyValidationAnnotations(ctx, builder, schema, property);
205
- this.generatePropertySchemaAnnotation(ctx, builder, schema, property);
206
- this.generateJsonPropertyAnnotation(ctx, builder, schema, property);
192
+ // #region Members
193
+ getClassParameter(ctx, args) {
194
+ var _a;
195
+ const { schema, inheritedSchemas, property } = args;
196
+ return ast_1.kt.parameter.class((0, core_1.toCasing)(property.name, ctx.config.propertyNameCasing), this.getType(ctx, { schema: property.schema, nullable: schema.required.has(property.name) ? undefined : true }), {
197
+ description: (_a = property.schema.description) === null || _a === void 0 ? void 0 : _a.trim(),
198
+ annotations: [
199
+ this.getJakartaPatternAnnotation(ctx, { schema, property }),
200
+ this.getJakartaValidAnnotation(ctx, { schema, property }),
201
+ this.getSwaggerSchemaAnnotation(ctx, { schema, property }),
202
+ this.getJacksonJsonPropertyAnnotation(ctx, { schema, property }),
203
+ (0, core_1.modify)(this.getJacksonJsonIncludeAnnotation(ctx, { schema, property }), (x) => (x.target = 'get')),
204
+ ].filter(core_1.notNullish),
205
+ override: inheritedSchemas.some((schema) => this.hasProperty(ctx, { schema, propertyName: property.name })),
206
+ property: 'readonly',
207
+ default: property.schema.default !== undefined || !schema.required.has(property.name)
208
+ ? this.getDefaultValue(ctx, { schema: property.schema })
209
+ : null,
210
+ });
207
211
  }
208
- generatePropertyValidationAnnotations(ctx, builder, schema, property) {
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
- }
221
- }
212
+ getInterfaceProperty(ctx, args) {
213
+ var _a;
214
+ const { schema, property } = args;
215
+ return ast_1.kt.property((0, core_1.toCasing)(property.name, ctx.config.propertyNameCasing), {
216
+ doc: ast_1.kt.doc((_a = property.schema.description) === null || _a === void 0 ? void 0 : _a.trim()),
217
+ annotations: (0, core_1.modifyEach)([
218
+ this.getJacksonJsonPropertyAnnotation(ctx, { schema, property }),
219
+ this.getJacksonJsonIncludeAnnotation(ctx, { schema, property }),
220
+ ].filter(core_1.notNullish), (x) => (x.target = 'get')),
221
+ type: this.getType(ctx, {
222
+ schema: property.schema,
223
+ nullable: schema.required.has(property.name) ? undefined : true,
224
+ }),
225
+ });
222
226
  }
223
- generatePropertySchemaAnnotation(ctx, builder, schema, property) {
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();
242
- }
227
+ getAdditionalPropertiesProperty(ctx, args) {
228
+ const { schema } = args;
229
+ return ast_1.kt.property((0, core_1.toCasing)('additionalProperties', ctx.config.propertyNameCasing), {
230
+ annotations: [ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonIgnore())],
231
+ type: ast_1.kt.reference('MutableMap', null, {
232
+ generics: ['String', this.getAdditionalPropertiesType(ctx, { schema })],
233
+ }),
234
+ default: 'mutableMapOf()',
235
+ });
243
236
  }
244
- generateJsonPropertyAnnotation(ctx, builder, schema, property, scope) {
245
- builder
246
- .if(ctx.config.addJacksonAnnotations, (builder) => builder
247
- .append(`@${scope ? scope + ':' : ''}JsonProperty`)
248
- .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
249
- .parenthesize('()', (builder) => builder
250
- .append(this.toStringLiteral(ctx, property.name))
251
- .appendIf(schema.required.has(property.name), ', required = true'))
252
- .appendLine())
253
- .if(property.schema.custom['exclude-when-null'] === true, (builder) => builder
254
- .if(ctx.config.addJacksonAnnotations, (builder) => builder.append('@get:JsonInclude').addImport('JsonInclude', 'com.fasterxml.jackson.annotation'))
255
- .parenthesize('()', 'JsonInclude.Include.NON_NULL')
256
- .appendLine());
237
+ getAdditionalPropertiesSetter(ctx, args) {
238
+ const { schema } = args;
239
+ return ast_1.kt.function((0, core_1.toCasing)('set', ctx.config.functionNameCasing), {
240
+ annotations: [ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonAnySetter())],
241
+ parameters: [
242
+ ast_1.kt.parameter((0, core_1.toCasing)('name', ctx.config.parameterNameCasing), 'String'),
243
+ ast_1.kt.parameter((0, core_1.toCasing)('value', ctx.config.parameterNameCasing), this.getAdditionalPropertiesType(ctx, { schema })),
244
+ ],
245
+ body: `this.${(0, core_1.toCasing)('additionalProperties', ctx.config.propertyNameCasing)}[name] = value`,
246
+ });
257
247
  }
258
- generateMapType(ctx, builder, schema) {
259
- if (schema.additionalProperties === true) {
260
- builder.append('Map<String, Any?>');
261
- }
262
- else if (typeof schema.additionalProperties === 'object') {
263
- const propertiesType = schema.additionalProperties;
264
- builder
265
- .append('Map')
266
- .parenthesize('<>', (builder) => builder.append('String, ').append((builder) => this.generateTypeUsage(ctx, builder, propertiesType)));
267
- }
248
+ getAdditionalPropertiesGetter(ctx, args) {
249
+ const { schema } = args;
250
+ return ast_1.kt.function((0, core_1.toCasing)('getMap', ctx.config.functionNameCasing), {
251
+ annotations: [ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonAnyGetter())],
252
+ returnType: ast_1.kt.refs.map([ast_1.kt.refs.string(), this.getAdditionalPropertiesType(ctx, { schema })]),
253
+ body: `return this.${(0, core_1.toCasing)('additionalProperties', ctx.config.propertyNameCasing)}`,
254
+ });
268
255
  }
269
- generateType(ctx, builder, schema) {
270
- switch (schema.kind) {
271
- case 'boolean':
272
- builder.append('Boolean');
273
- break;
274
- case 'integer':
275
- case 'number':
276
- this.generateNumberType(ctx, builder, schema);
277
- break;
278
- case 'string':
279
- if (schema.enum !== undefined && schema.enum.length > 0) {
280
- this.generateEnum(ctx, builder, schema);
281
- }
282
- else {
283
- this.generateStringType(ctx, builder, schema);
284
- }
285
- break;
286
- case 'null':
287
- builder.append('Nothing');
288
- break;
289
- case 'unknown':
290
- builder.append('Any');
291
- break;
292
- case 'array':
293
- this.generateArrayType(ctx, builder, schema);
294
- break;
295
- case 'object':
296
- this.generateObjectType(ctx, builder, schema);
297
- break;
298
- case 'combined':
299
- builder.append('Any');
300
- break;
301
- case 'multi-type':
302
- builder.append('Any');
303
- break;
304
- case 'oneOf':
305
- builder.append('Any');
306
- break;
307
- default:
308
- builder.append('Any');
309
- break;
310
- }
311
- if (schema.nullable) {
312
- builder.append('?');
313
- }
256
+ // #endregion
257
+ // #region Annotations
258
+ getJacksonJsonTypeInfoAnnotation(ctx, args) {
259
+ const { schema } = args;
260
+ return ctx.config.addJacksonAnnotations && schema.discriminator
261
+ ? ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonTypeInfo(), [
262
+ ast_1.kt.argument.named('use', 'JsonTypeInfo.Id.NAME'),
263
+ ast_1.kt.argument.named('include', 'JsonTypeInfo.As.EXISTING_PROPERTY'),
264
+ ast_1.kt.argument.named('property', ast_1.kt.string(schema.discriminator.propertyName)),
265
+ ast_1.kt.argument.named('visible', 'true'),
266
+ ])
267
+ : null;
314
268
  }
315
- generateNumberType(ctx, builder, schema) {
316
- switch (schema.format) {
317
- case 'int32':
318
- builder.append('Int');
319
- break;
320
- case 'int64':
321
- builder.append('Long');
322
- break;
323
- case 'float':
324
- builder.append('Float');
325
- break;
326
- case 'double':
327
- builder.append('Double');
328
- break;
329
- default:
330
- builder.append(schema.kind === 'integer' ? 'Int' : 'Double');
331
- break;
332
- }
269
+ getJacksonJsonSubTypesAnnotation(ctx, args) {
270
+ const { schema } = args;
271
+ if (!ctx.config.addJacksonAnnotations || !schema.discriminator)
272
+ return null;
273
+ const entries = Object.entries(schema.discriminator.mapping);
274
+ return entries.length > 0
275
+ ? ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonSubTypes(), entries.map(([value, schema]) => ast_1.kt.argument(ast_1.kt.call([ast_1.kt.refs.jackson.jsonSubTypes(), 'Type'], [
276
+ ast_1.kt.argument.named('value', (0, core_1.modify)(this.getType(ctx, { schema }), (x) => (x.classReference = true))),
277
+ ast_1.kt.argument.named('name', ast_1.kt.string(value)),
278
+ ]))))
279
+ : null;
333
280
  }
334
- generateStringType(ctx, builder, schema) {
335
- switch (schema.format) {
336
- case 'date-time':
337
- builder.append('OffsetDateTime').addImport('OffsetDateTime', 'java.time');
338
- break;
339
- default:
340
- builder.append('String');
341
- break;
342
- }
281
+ getJacksonJsonPropertyAnnotation(ctx, args) {
282
+ const { schema, property } = args;
283
+ return ctx.config.addJacksonAnnotations
284
+ ? ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonProperty(), [
285
+ ast_1.kt.argument(ast_1.kt.string(property.name)),
286
+ schema.required.has(property.name) ? ast_1.kt.argument.named('required', 'true') : null,
287
+ ])
288
+ : null;
343
289
  }
344
- generateEnum(ctx, builder, schema) {
345
- builder
346
- .append((builder) => this.generateDocumentation(ctx, builder, schema))
347
- .append('enum class ')
348
- .append(this.getDeclarationTypeName(ctx, schema))
349
- .append('(val value: String) ')
350
- .parenthesize('{}', (builder) => {
351
- var _a;
352
- return builder.forEach((_a = schema.enum) !== null && _a !== void 0 ? _a : [], (builder, value) => builder
353
- .if(ctx.config.addJacksonAnnotations, (builder) => builder
354
- .append('@JsonProperty')
355
- .addImport('JsonProperty', 'com.fasterxml.jackson.annotation')
356
- .parenthesize('()', this.toStringLiteral(ctx, String(value)))
357
- .appendLine())
358
- .append((0, core_1.toCasing)(String(value), 'snake'))
359
- .parenthesize('()', this.toStringLiteral(ctx, String(value))), { separator: (builder) => builder.appendLine(',').appendLine() });
360
- }, { multiline: true });
290
+ getJacksonJsonIncludeAnnotation(ctx, args) {
291
+ const { property } = args;
292
+ return ctx.config.addJacksonAnnotations && property.schema.custom['exclude-when-null'] === true
293
+ ? ast_1.kt.annotation(ast_1.kt.refs.jackson.jsonInclude(), [
294
+ ast_1.kt.argument(ast_1.kt.call([ast_1.kt.refs.jackson.jsonInclude(), 'Include', 'NON_NULL'])),
295
+ ])
296
+ : null;
361
297
  }
362
- generateArrayType(ctx, builder, schema) {
363
- builder.append('List').parenthesize('<>', (builder) => builder.if(schema.items === undefined, (builder) => builder.append('Any?'), (builder) => this.generateTypeUsage(ctx, builder, schema.items)));
298
+ getJakartaPatternAnnotation(ctx, args) {
299
+ const { property } = args;
300
+ return ctx.config.addJakartaValidationAnnotations && property.schema.kind === 'string' && property.schema.pattern
301
+ ? ast_1.kt.annotation(ast_1.kt.refs.jakarta.pattern(), [ast_1.kt.argument.named('regexp', ast_1.kt.string(property.schema.pattern))], {
302
+ target: 'get',
303
+ })
304
+ : null;
364
305
  }
365
- generateDocumentation(ctx, builder, schema) {
366
- var _a, _b;
367
- 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);
368
- if (schema.description !== undefined || propertiesWithDescription.length > 0) {
369
- builder
370
- .ensurePreviousLineEmpty()
371
- .appendLine('/**')
372
- .appendWithLinePrefix(' * ', (builder) => builder
373
- .appendLineIf(!!schema.description, schema.description)
374
- .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()}`); }))
375
- .appendLine(' */');
376
- }
306
+ getJakartaValidAnnotation(ctx, args) {
307
+ const { property } = args;
308
+ return ctx.config.addJakartaValidationAnnotations &&
309
+ this.shouldGenerateTypeDeclaration(ctx, { schema: property.schema })
310
+ ? ast_1.kt.annotation(ast_1.kt.refs.jakarta.valid(), [], { target: 'field' })
311
+ : null;
312
+ }
313
+ getSwaggerSchemaAnnotation(ctx, args) {
314
+ const { schema, property } = args;
315
+ return ctx.config.addSwaggerAnnotations
316
+ ? ast_1.kt.annotation(ast_1.kt.refs.swagger.schema(), [
317
+ property.schema.example !== undefined
318
+ ? ast_1.kt.argument.named('example', ast_1.kt.string(String(property.schema.example)))
319
+ : null,
320
+ schema.required.has(property.name) ? ast_1.kt.argument.named('required', 'true') : null,
321
+ property.schema.description !== undefined
322
+ ? ast_1.kt.argument.named('description', ast_1.kt.string(property.schema.description))
323
+ : null,
324
+ ])
325
+ : null;
377
326
  }
378
- getPackageName(ctx, schema) {
327
+ // #endregion
328
+ getPackageName(ctx, args) {
329
+ const { schema } = args;
379
330
  const packageSuffix = typeof ctx.config.packageSuffix === 'string' ? ctx.config.packageSuffix : ctx.config.packageSuffix(schema);
380
331
  return ctx.config.packageName + packageSuffix;
381
332
  }
382
- shouldGenerateTypeDeclaration(ctx, schema) {
333
+ shouldGenerateTypeDeclaration(ctx, args) {
334
+ let { schema } = args;
383
335
  // All enum types should have its own type declaration
384
336
  if (schema.enum !== undefined && schema.enum.length > 0) {
385
337
  return true;
@@ -395,7 +347,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
395
347
  if (schema.kind === 'multi-type') {
396
348
  return false;
397
349
  }
398
- schema = this.normalizeSchema(ctx, schema);
350
+ schema = this.normalizeSchema(ctx, { schema });
399
351
  if (schema.kind === 'combined' || schema.kind === 'oneOf') {
400
352
  return false;
401
353
  }
@@ -405,17 +357,18 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
405
357
  }
406
358
  return true;
407
359
  }
408
- getDeclarationTypeName(ctx, schema) {
409
- return (0, core_1.toCasing)(schema.name, 'pascal');
360
+ getDeclarationTypeName(ctx, args) {
361
+ return (0, core_1.toCasing)(args.schema.name, ctx.config.typeNameCasing);
410
362
  }
411
- getInheritedSchemas(ctx, schema) {
412
- return schema.inheritedSchemas
413
- .filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated)
363
+ getInheritedSchemas(ctx, args) {
364
+ return args.schema.inheritedSchemas
365
+ .filter((schema) => this.shouldGenerateTypeDeclaration(ctx, { schema }) && !schema.isNameGenerated)
414
366
  .filter((item, index, self) => self.indexOf(item) === index);
415
367
  }
416
- getClassProperties(ctx, schema) {
368
+ getClassProperties(ctx, args) {
417
369
  var _a;
418
- const inheritedSchemas = this.getInheritedSchemas(ctx, schema);
370
+ const { schema } = args;
371
+ const inheritedSchemas = this.getInheritedSchemas(ctx, { schema });
419
372
  const properties = [];
420
373
  const appendedProperties = [];
421
374
  for (const property of schema.properties.values()) {
@@ -433,19 +386,20 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
433
386
  }
434
387
  properties.push(property);
435
388
  }
436
- return [...this.sortProperties(ctx, schema, properties), ...appendedProperties];
389
+ return [...this.sortProperties(ctx, { schema, properties }), ...appendedProperties];
437
390
  }
438
- sortProperties(ctx, schema, properties) {
439
- return [...properties].sort((a, b) => classify(a) - classify(b));
391
+ sortProperties(ctx, args) {
392
+ return [...args.properties].sort((a, b) => classify(a) - classify(b));
440
393
  function classify(p) {
441
394
  if (p.schema.default !== undefined)
442
395
  return 1;
443
- if (schema.required.has(p.name))
396
+ if (args.schema.required.has(p.name))
444
397
  return 0;
445
398
  return 2;
446
399
  }
447
400
  }
448
- normalizeSchema(ctx, schema) {
401
+ normalizeSchema(ctx, args) {
402
+ let { schema } = args;
449
403
  if (schema.kind === 'oneOf') {
450
404
  schema =
451
405
  ctx.config.oneOfBehavior === 'treat-as-any-of'
@@ -460,10 +414,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
460
414
  }
461
415
  return schema;
462
416
  }
463
- hasProperty(ctx, schema, name) {
464
- return (('properties' in schema && schema.properties.has(name)) ||
465
- ('anyOf' in schema && schema.anyOf.some((x) => this.hasProperty(ctx, x, name))) ||
466
- ('allOf' in schema && schema.allOf.some((x) => this.hasProperty(ctx, x, name))));
417
+ hasProperty(ctx, args) {
418
+ const { schema, propertyName } = args;
419
+ return (('properties' in schema && schema.properties.has(propertyName)) ||
420
+ ('anyOf' in schema && schema.anyOf.some((schema) => this.hasProperty(ctx, { schema, propertyName }))) ||
421
+ ('allOf' in schema && schema.allOf.some((schema) => this.hasProperty(ctx, { schema, propertyName }))));
467
422
  }
468
423
  }
469
424
  exports.DefaultKotlinModelGenerator = DefaultKotlinModelGenerator;