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