@goast/kotlin 0.7.0-beta.2 → 0.7.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.
- package/dist/src/assets.d.ts +17 -0
- package/dist/src/assets.js +17 -0
- package/dist/src/ast/common.d.ts +4 -0
- package/dist/src/ast/node.d.ts +11 -0
- package/dist/src/ast/node.js +11 -0
- package/dist/src/ast/nodes/annotation.d.ts +44 -0
- package/dist/src/ast/nodes/annotation.js +40 -0
- package/dist/src/ast/nodes/argument.d.ts +33 -0
- package/dist/src/ast/nodes/argument.js +33 -0
- package/dist/src/ast/nodes/call.d.ts +42 -0
- package/dist/src/ast/nodes/call.js +42 -0
- package/dist/src/ast/nodes/class.d.ts +96 -0
- package/dist/src/ast/nodes/class.js +90 -0
- package/dist/src/ast/nodes/collection-literal.d.ts +35 -0
- package/dist/src/ast/nodes/collection-literal.js +35 -0
- package/dist/src/ast/nodes/constructor.d.ts +65 -0
- package/dist/src/ast/nodes/constructor.js +62 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +41 -0
- package/dist/src/ast/nodes/doc-tag.js +41 -0
- package/dist/src/ast/nodes/doc.d.ts +44 -0
- package/dist/src/ast/nodes/doc.js +44 -0
- package/dist/src/ast/nodes/enum-value.d.ts +50 -0
- package/dist/src/ast/nodes/enum-value.js +47 -0
- package/dist/src/ast/nodes/enum.d.ts +67 -0
- package/dist/src/ast/nodes/enum.js +64 -0
- package/dist/src/ast/nodes/function.d.ts +105 -0
- package/dist/src/ast/nodes/function.js +105 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/generic-parameter.js +37 -0
- package/dist/src/ast/nodes/init-block.d.ts +32 -0
- package/dist/src/ast/nodes/init-block.js +32 -0
- package/dist/src/ast/nodes/interface.d.ts +73 -0
- package/dist/src/ast/nodes/interface.js +68 -0
- package/dist/src/ast/nodes/lambda-type.d.ts +42 -0
- package/dist/src/ast/nodes/lambda-type.js +42 -0
- package/dist/src/ast/nodes/lambda.d.ts +41 -0
- package/dist/src/ast/nodes/lambda.js +41 -0
- package/dist/src/ast/nodes/object.d.ts +66 -0
- package/dist/src/ast/nodes/object.js +62 -0
- package/dist/src/ast/nodes/parameter.d.ts +68 -0
- package/dist/src/ast/nodes/parameter.js +68 -0
- package/dist/src/ast/nodes/property.d.ts +152 -0
- package/dist/src/ast/nodes/property.js +148 -0
- package/dist/src/ast/nodes/reference.d.ts +107 -0
- package/dist/src/ast/nodes/reference.js +75 -0
- package/dist/src/ast/nodes/string.d.ts +57 -0
- package/dist/src/ast/nodes/string.js +57 -0
- package/dist/src/ast/nodes/types.d.ts +9 -0
- package/dist/src/ast/references/jackson.d.ts +67 -0
- package/dist/src/ast/references/jackson.js +59 -0
- package/dist/src/ast/references/jakarta.d.ts +13 -0
- package/dist/src/ast/references/jakarta.js +13 -0
- package/dist/src/ast/references/java.d.ts +19 -0
- package/dist/src/ast/references/java.js +19 -0
- package/dist/src/ast/references/kotlin.d.ts +28 -0
- package/dist/src/ast/references/kotlin.js +28 -0
- package/dist/src/ast/references/kotlinx.d.ts +8 -0
- package/dist/src/ast/references/kotlinx.js +8 -0
- package/dist/src/ast/references/okhttp3.d.ts +8 -0
- package/dist/src/ast/references/okhttp3.js +8 -0
- package/dist/src/ast/references/reactor.d.ts +8 -0
- package/dist/src/ast/references/reactor.js +8 -0
- package/dist/src/ast/references/spring-reactive.d.ts +18 -0
- package/dist/src/ast/references/spring-reactive.js +18 -0
- package/dist/src/ast/references/spring.d.ts +27 -0
- package/dist/src/ast/references/spring.js +27 -0
- package/dist/src/ast/references/swagger.d.ts +13 -0
- package/dist/src/ast/references/swagger.js +13 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.d.ts +10 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.js +10 -0
- package/dist/src/ast/utils/to-kt-node.d.ts +40 -0
- package/dist/src/ast/utils/write-kt-annotations.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-annotations.js +13 -0
- package/dist/src/ast/utils/write-kt-arguments.d.ts +15 -0
- package/dist/src/ast/utils/write-kt-arguments.js +15 -0
- package/dist/src/ast/utils/write-kt-enum-values.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-enum-values.js +13 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.d.ts +10 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.js +10 -0
- package/dist/src/ast/utils/write-kt-members.d.ts +16 -0
- package/dist/src/ast/utils/write-kt-members.js +16 -0
- package/dist/src/ast/utils/write-kt-node.d.ts +29 -0
- package/dist/src/ast/utils/write-kt-node.js +24 -0
- package/dist/src/ast/utils/write-kt-parameters.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-parameters.js +13 -0
- package/dist/src/common-results.d.ts +9 -0
- package/dist/src/config.d.ts +72 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +91 -0
- package/dist/src/file-builder.js +81 -0
- package/dist/src/generators/file-generator.d.ts +12 -0
- package/dist/src/generators/file-generator.js +7 -0
- package/dist/src/generators/models/args.d.ts +233 -0
- package/dist/src/generators/models/model-generator.d.ts +25 -0
- package/dist/src/generators/models/model-generator.js +14 -0
- package/dist/src/generators/models/models-generator.d.ts +15 -0
- package/dist/src/generators/models/models-generator.js +15 -0
- package/dist/src/generators/models/models.d.ts +93 -2
- package/dist/src/generators/models/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/args.d.ts +138 -0
- package/dist/src/generators/services/okhttp3-clients/models.d.ts +83 -0
- package/dist/src/generators/services/okhttp3-clients/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +33 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +20 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts +21 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +21 -0
- package/dist/src/generators/services/okhttp3-clients/refs.d.ts +25 -0
- package/dist/src/generators/services/okhttp3-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-controllers/args.d.ts +169 -0
- package/dist/src/generators/services/spring-controllers/models.d.ts +120 -0
- package/dist/src/generators/services/spring-controllers/models.js +4 -0
- package/dist/src/generators/services/spring-controllers/refs.d.ts +9 -0
- package/dist/src/generators/services/spring-controllers/refs.js +9 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.d.ts +29 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.js +19 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.d.ts +22 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.js +22 -0
- package/dist/src/generators/services/spring-reactive-web-clients/args.d.ts +224 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.d.ts +86 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.js +4 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +36 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +25 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.d.ts +20 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.js +20 -0
- package/dist/src/import-collection.d.ts +64 -0
- package/dist/src/import-collection.js +46 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/utils.d.ts +52 -0
- package/dist/src/utils.js +52 -0
- package/package.json +2 -2
|
@@ -1,109 +1,342 @@
|
|
|
1
1
|
import type { ApiSchema, ApiSchemaProperty } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Arguments of `getFileContent`. The method takes no arguments beyond its context, so this type has no properties.
|
|
4
|
+
*/
|
|
2
5
|
export type GetFileContent = object;
|
|
6
|
+
/**
|
|
7
|
+
* Arguments of `getSchemaDeclaration`, which writes the declaration of a schema into a model file.
|
|
8
|
+
*/
|
|
3
9
|
export type GetSchemaDeclaration = {
|
|
10
|
+
/**
|
|
11
|
+
* The normalized schema to declare as a class, interface or enum.
|
|
12
|
+
*/
|
|
4
13
|
schema: ApiSchema;
|
|
5
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Arguments of `getClass`, which declares an object schema without a discriminator as a Kotlin class.
|
|
17
|
+
*/
|
|
6
18
|
export type GetClass = {
|
|
19
|
+
/**
|
|
20
|
+
* The object schema to declare as a class. Its properties become the constructor parameters.
|
|
21
|
+
*/
|
|
7
22
|
schema: ApiSchema<'object'>;
|
|
8
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Arguments of `getInterface`, which declares a discriminated object schema as a Kotlin interface.
|
|
26
|
+
*/
|
|
9
27
|
export type GetInterface = {
|
|
28
|
+
/**
|
|
29
|
+
* The discriminated object schema to declare as an interface. Its properties become interface members.
|
|
30
|
+
*/
|
|
10
31
|
schema: ApiSchema<'object'>;
|
|
11
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Arguments of `getEnum`, which declares a string enum schema as a Kotlin enum class.
|
|
35
|
+
*/
|
|
12
36
|
export type GetEnum = {
|
|
37
|
+
/**
|
|
38
|
+
* The schema with a non-empty `enum` list to declare as an enum class.
|
|
39
|
+
*/
|
|
13
40
|
schema: ApiSchema;
|
|
14
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Arguments of `getSchemaDocDescription`, which builds the text of the doc comment of a schema or property.
|
|
44
|
+
*/
|
|
15
45
|
export type GetSchemaDocDescription = {
|
|
46
|
+
/**
|
|
47
|
+
* The schema whose description is used. Its source location is added when `includeSourceInDocs` is set.
|
|
48
|
+
*/
|
|
16
49
|
schema: ApiSchema;
|
|
17
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Arguments of `getType`, which maps a schema to the Kotlin type used to reference it.
|
|
53
|
+
*/
|
|
18
54
|
export type GetType = {
|
|
55
|
+
/**
|
|
56
|
+
* The schema to map to a Kotlin type.
|
|
57
|
+
*/
|
|
19
58
|
schema: ApiSchema;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the type is nullable. When omitted, the schema's own `nullable` flag decides.
|
|
61
|
+
*/
|
|
20
62
|
nullable?: boolean;
|
|
21
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Arguments of `getGeneratedType`, which looks up the type of a schema that has its own generated declaration.
|
|
66
|
+
*/
|
|
22
67
|
export type GetGeneratedType = {
|
|
68
|
+
/**
|
|
69
|
+
* The schema to look up. A reference to another schema is resolved to the schema it points to first.
|
|
70
|
+
*/
|
|
23
71
|
schema: ApiSchema;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the reference is nullable. When omitted, the schema's own `nullable` flag decides.
|
|
74
|
+
*/
|
|
24
75
|
nullable?: boolean;
|
|
25
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Arguments of `getAdditionalPropertiesType`, which resolves the value type of an object's `additionalProperties`.
|
|
79
|
+
*/
|
|
26
80
|
export type GetAdditionalPropertiesType = {
|
|
81
|
+
/**
|
|
82
|
+
* The object schema whose `additionalProperties` value type is resolved. A nullable `Any` is used when the
|
|
83
|
+
* value is not a schema.
|
|
84
|
+
*/
|
|
27
85
|
schema: ApiSchema<'object'>;
|
|
28
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Arguments of `getDefaultValue`, which renders the `default` of a schema as a Kotlin expression.
|
|
89
|
+
*/
|
|
29
90
|
export type GetDefaultValue = {
|
|
91
|
+
/**
|
|
92
|
+
* The schema whose `default` value is rendered. A missing default is rendered as `null`.
|
|
93
|
+
*/
|
|
30
94
|
schema: ApiSchema;
|
|
31
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Arguments of `getClassParameter`, which declares one property as a constructor parameter of a class.
|
|
98
|
+
*/
|
|
32
99
|
export type GetClassParameter = {
|
|
100
|
+
/**
|
|
101
|
+
* The object schema that declares the class. Its `required` set decides whether the parameter is nullable.
|
|
102
|
+
*/
|
|
33
103
|
schema: ApiSchema<'object'>;
|
|
104
|
+
/**
|
|
105
|
+
* The schemas the class inherits from. A parameter that one of them also declares is marked as an override.
|
|
106
|
+
*/
|
|
34
107
|
inheritedSchemas: ApiSchema[];
|
|
108
|
+
/**
|
|
109
|
+
* All constructor parameters of the class, in the order they are written.
|
|
110
|
+
*/
|
|
35
111
|
parameters: ApiSchemaProperty[];
|
|
112
|
+
/**
|
|
113
|
+
* The property to declare as the constructor parameter.
|
|
114
|
+
*/
|
|
36
115
|
property: ApiSchemaProperty;
|
|
37
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* Arguments of `getInterfaceProperty`, which declares one property as a member of an interface.
|
|
119
|
+
*/
|
|
38
120
|
export type GetInterfaceProperty = {
|
|
121
|
+
/**
|
|
122
|
+
* The discriminated object schema that declares the interface. Its `required` set decides whether the property
|
|
123
|
+
* is nullable.
|
|
124
|
+
*/
|
|
39
125
|
schema: ApiSchema<'object'>;
|
|
126
|
+
/**
|
|
127
|
+
* The property to declare as an interface member.
|
|
128
|
+
*/
|
|
40
129
|
property: ApiSchemaProperty;
|
|
41
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* Arguments of `getAdditionalPropertiesProperty`, which declares the `additionalProperties` map of a class.
|
|
133
|
+
*/
|
|
42
134
|
export type GetAdditionalPropertiesProperty = {
|
|
135
|
+
/**
|
|
136
|
+
* The object schema whose `additionalProperties` are declared as a mutable map.
|
|
137
|
+
*/
|
|
43
138
|
schema: ApiSchema<'object'>;
|
|
44
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Arguments of `getAdditionalPropertiesSetter`, which declares the `set` function that stores an additional property.
|
|
142
|
+
*/
|
|
45
143
|
export type GetAdditionalPropertiesSetter = {
|
|
144
|
+
/**
|
|
145
|
+
* The object schema whose `additionalProperties` the setter writes to.
|
|
146
|
+
*/
|
|
46
147
|
schema: ApiSchema<'object'>;
|
|
47
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Arguments of `getAdditionalPropertiesGetter`, which declares the `getMap` function that returns the additional
|
|
151
|
+
* properties.
|
|
152
|
+
*/
|
|
48
153
|
export type GetAdditionalPropertiesGetter = {
|
|
154
|
+
/**
|
|
155
|
+
* The object schema whose `additionalProperties` the getter returns.
|
|
156
|
+
*/
|
|
49
157
|
schema: ApiSchema<'object'>;
|
|
50
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Arguments of `getJacksonJsonTypeInfoAnnotation`, which builds the `@JsonTypeInfo` annotation of an interface.
|
|
161
|
+
*/
|
|
51
162
|
export type GetJacksonJsonTypeInfoAnnotation = {
|
|
163
|
+
/**
|
|
164
|
+
* The schema whose `discriminator` names the property that selects the subtype.
|
|
165
|
+
*/
|
|
52
166
|
schema: ApiSchema;
|
|
53
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Arguments of `getJacksonJsonSubTypesAnnotation`, which builds the `@JsonSubTypes` annotation of an interface.
|
|
170
|
+
*/
|
|
54
171
|
export type GetJacksonJsonSubTypesAnnotation = {
|
|
172
|
+
/**
|
|
173
|
+
* The discriminated schema whose `discriminator.mapping` entries are listed as subtypes.
|
|
174
|
+
*/
|
|
55
175
|
schema: ApiSchema;
|
|
56
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* Arguments of `getJacksonJsonClassDescriptionAnnotation`, which builds the `@JsonClassDescription` annotation.
|
|
179
|
+
*/
|
|
57
180
|
export type GetJacksonJsonClassDescriptionAnnotation = {
|
|
181
|
+
/**
|
|
182
|
+
* The schema whose `description` is written into the annotation.
|
|
183
|
+
*/
|
|
58
184
|
schema: ApiSchema;
|
|
59
185
|
};
|
|
186
|
+
/**
|
|
187
|
+
* Arguments of `getJacksonJsonPropertyAnnotation`, which builds the `@JsonProperty` annotation of a property.
|
|
188
|
+
*/
|
|
60
189
|
export type GetJacksonJsonPropertyAnnotation = {
|
|
190
|
+
/**
|
|
191
|
+
* The schema that declares the property. Its `required` set adds `required = true` to the annotation.
|
|
192
|
+
*/
|
|
61
193
|
schema: ApiSchema;
|
|
194
|
+
/**
|
|
195
|
+
* The property whose name is written into the annotation.
|
|
196
|
+
*/
|
|
62
197
|
property: ApiSchemaProperty;
|
|
63
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* Arguments of `getJacksonJsonPropertyDescriptionAnnotation`, which builds the `@JsonPropertyDescription` annotation.
|
|
201
|
+
*/
|
|
64
202
|
export type GetJacksonJsonPropertyDescriptionAnnotation = {
|
|
203
|
+
/**
|
|
204
|
+
* The schema that declares the property. The default implementation does not read it.
|
|
205
|
+
*/
|
|
65
206
|
schema: ApiSchema;
|
|
207
|
+
/**
|
|
208
|
+
* The property whose `description` is written into the annotation.
|
|
209
|
+
*/
|
|
66
210
|
property: ApiSchemaProperty;
|
|
67
211
|
};
|
|
212
|
+
/**
|
|
213
|
+
* Arguments of `getJacksonJsonIncludeAnnotation`, which builds the `@JsonInclude` annotation of a property.
|
|
214
|
+
*/
|
|
68
215
|
export type GetJacksonJsonIncludeAnnotation = {
|
|
216
|
+
/**
|
|
217
|
+
* The schema that declares the property. The default implementation does not read it.
|
|
218
|
+
*/
|
|
69
219
|
schema: ApiSchema;
|
|
220
|
+
/**
|
|
221
|
+
* The property whose `exclude-when-null` custom flag selects `@JsonInclude(NON_NULL)`.
|
|
222
|
+
*/
|
|
70
223
|
property: ApiSchemaProperty;
|
|
71
224
|
};
|
|
225
|
+
/**
|
|
226
|
+
* Arguments of `getJakartaValidationAnnotations`, which builds the Jakarta Validation annotations of a property.
|
|
227
|
+
*/
|
|
72
228
|
export type GetJakartaValidationAnnotations = {
|
|
229
|
+
/**
|
|
230
|
+
* The schema that declares the property. The default implementation does not read it.
|
|
231
|
+
*/
|
|
73
232
|
schema: ApiSchema;
|
|
233
|
+
/**
|
|
234
|
+
* The property whose constraints (pattern, length, size and range) and generated type determine the annotations.
|
|
235
|
+
*/
|
|
74
236
|
property: ApiSchemaProperty;
|
|
75
237
|
};
|
|
238
|
+
/**
|
|
239
|
+
* Arguments of `getSwaggerSchemaAnnotation`, which builds the Swagger `@Schema` annotation of a property.
|
|
240
|
+
*/
|
|
76
241
|
export type GetSwaggerSchemaAnnotation = {
|
|
242
|
+
/**
|
|
243
|
+
* The schema that declares the property. Its `required` set adds `required = true` to the annotation.
|
|
244
|
+
*/
|
|
77
245
|
schema: ApiSchema;
|
|
246
|
+
/**
|
|
247
|
+
* The property whose example, description and deprecation flag are written into the annotation.
|
|
248
|
+
*/
|
|
78
249
|
property: ApiSchemaProperty;
|
|
79
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* Arguments of `getPackageName`, which resolves the package the model of a schema is generated in.
|
|
253
|
+
*/
|
|
80
254
|
export type GetPackageName = {
|
|
255
|
+
/**
|
|
256
|
+
* The schema whose package is resolved. It is passed to `packageSuffix` when that option is a function.
|
|
257
|
+
*/
|
|
81
258
|
schema: ApiSchema;
|
|
82
259
|
};
|
|
260
|
+
/**
|
|
261
|
+
* Arguments of `shouldGenerateTypeDeclaration`, which decides whether a schema gets its own declaration and file.
|
|
262
|
+
*/
|
|
83
263
|
export type ShouldGenerateTypeDeclaration = {
|
|
264
|
+
/**
|
|
265
|
+
* The schema to check. Enum schemas always get a declaration, and primitive schemas never do.
|
|
266
|
+
*/
|
|
84
267
|
schema: ApiSchema;
|
|
85
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* Arguments of `getDeclarationTypeName`, which derives the Kotlin type name of a schema.
|
|
271
|
+
*/
|
|
86
272
|
export type GetDeclarationTypeName = {
|
|
273
|
+
/**
|
|
274
|
+
* The schema whose `name` is converted with the `typeNameCasing` option.
|
|
275
|
+
*/
|
|
87
276
|
schema: ApiSchema;
|
|
88
277
|
};
|
|
278
|
+
/**
|
|
279
|
+
* Arguments of `getInheritedSchemas`, which collects the schemas a class inherits from.
|
|
280
|
+
*/
|
|
89
281
|
export type GetInheritedSchemas = {
|
|
282
|
+
/**
|
|
283
|
+
* The schema whose inherited schemas are collected. Only those that get their own named declaration are kept.
|
|
284
|
+
*/
|
|
90
285
|
schema: ApiSchema;
|
|
91
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* Arguments of `getClassProperties`, which collects the constructor parameters of a class.
|
|
289
|
+
*/
|
|
92
290
|
export type GetClassProperties = {
|
|
291
|
+
/**
|
|
292
|
+
* The object schema whose properties are collected. A discriminator property that the mapping of an inherited
|
|
293
|
+
* schema fixes to this schema gets that value as its default and is moved to the end.
|
|
294
|
+
*/
|
|
93
295
|
schema: ApiSchema<'object'>;
|
|
94
296
|
};
|
|
297
|
+
/**
|
|
298
|
+
* Arguments of `sortProperties`, which orders the properties of a class or interface.
|
|
299
|
+
*/
|
|
95
300
|
export type SortProperties = {
|
|
301
|
+
/**
|
|
302
|
+
* The schema whose `required` set and defaults determine the order.
|
|
303
|
+
*/
|
|
96
304
|
schema: ApiSchema;
|
|
305
|
+
/**
|
|
306
|
+
* The properties to sort. The iterable is copied, so it is not modified.
|
|
307
|
+
*/
|
|
97
308
|
properties: Iterable<ApiSchemaProperty>;
|
|
98
309
|
};
|
|
310
|
+
/**
|
|
311
|
+
* Arguments of `normalizeSchema`, which turns a schema into the form that is declared.
|
|
312
|
+
*/
|
|
99
313
|
export type NormalizeSchema = {
|
|
314
|
+
/**
|
|
315
|
+
* The schema to normalize. A `oneOf` is turned into `anyOf` or `allOf` according to `oneOfBehavior`, and object
|
|
316
|
+
* compositions are merged into one object where possible.
|
|
317
|
+
*/
|
|
100
318
|
schema: ApiSchema;
|
|
101
319
|
};
|
|
320
|
+
/**
|
|
321
|
+
* Arguments of `normalizeDiscriminatedBases`, which rewrites discriminated `oneOf` bases into objects.
|
|
322
|
+
*/
|
|
102
323
|
export type NormalizeDiscriminatedBases = {
|
|
324
|
+
/**
|
|
325
|
+
* The schema whose compositions are searched for discriminated `oneOf` bases to rewrite.
|
|
326
|
+
*/
|
|
103
327
|
schema: ApiSchema;
|
|
104
328
|
};
|
|
329
|
+
/**
|
|
330
|
+
* Arguments of `hasProperty`, which checks whether a schema declares a property, directly or through its compositions.
|
|
331
|
+
*/
|
|
105
332
|
export type HasProperty = {
|
|
333
|
+
/**
|
|
334
|
+
* The schema to search, including the schemas it composes with `allOf`, `anyOf` and undiscriminated `oneOf`.
|
|
335
|
+
*/
|
|
106
336
|
schema: ApiSchema;
|
|
337
|
+
/**
|
|
338
|
+
* The name of the property to look for.
|
|
339
|
+
*/
|
|
107
340
|
propertyName: string;
|
|
108
341
|
/** The schemas already inspected, so a composition that cycles back on itself terminates. */
|
|
109
342
|
visited?: Set<ApiSchema>;
|
|
@@ -7,10 +7,35 @@ import type { KotlinModelGeneratorContext, KotlinModelGeneratorOutput } from './
|
|
|
7
7
|
type Context = KotlinModelGeneratorContext;
|
|
8
8
|
type Output = KotlinModelGeneratorOutput;
|
|
9
9
|
type Builder = KotlinFileBuilder;
|
|
10
|
+
/**
|
|
11
|
+
* Generates the model for one schema. Implement this interface to replace the default model generation, or extend
|
|
12
|
+
* `DefaultKotlinModelGenerator` to change parts of it.
|
|
13
|
+
* @template TOutput The type of the result the generator returns. It extends `KotlinModelGeneratorOutput`.
|
|
14
|
+
* @see DefaultKotlinModelGenerator
|
|
15
|
+
*/
|
|
10
16
|
export interface KotlinModelGenerator<TOutput extends Output = Output> {
|
|
17
|
+
/**
|
|
18
|
+
* Generates the model for the schema in the context.
|
|
19
|
+
* @param ctx The context containing the schema to generate the model for.
|
|
20
|
+
* @returns The result for the schema, or a promise of it.
|
|
21
|
+
*/
|
|
11
22
|
generate(ctx: Context): MaybePromise<TOutput>;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The default model generator. A schema that gets its own declaration is written to
|
|
26
|
+
* `{outputDir}/{packagePath}/{TypeName}.kt` as a `data class`, a plain class, an interface for a discriminated base
|
|
27
|
+
* or an enum, depending on the schema.
|
|
28
|
+
* Any other schema is mapped to a built-in Kotlin type and no file is written. Schemas that exist only as `anyOf` or
|
|
29
|
+
* `allOf` members resolve to a nullable `Any`.
|
|
30
|
+
* @see KotlinModelGenerator
|
|
31
|
+
* @see KotlinModelsGenerator
|
|
32
|
+
*/
|
|
13
33
|
export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Context, Output> implements KotlinModelGenerator {
|
|
34
|
+
/**
|
|
35
|
+
* Generates the model for the schema in the context. Writes the model file when the schema gets its own declaration.
|
|
36
|
+
* @param ctx The context containing the schema to generate the model for.
|
|
37
|
+
* @returns The Kotlin type the schema maps to, which is a reference to the generated declaration or a built-in type.
|
|
38
|
+
*/
|
|
14
39
|
generate(ctx: Context): MaybePromise<KotlinModelGeneratorOutput>;
|
|
15
40
|
protected getFileContent(ctx: Context, _args: Args.GetFileContent): AppendValueGroup<Builder>;
|
|
16
41
|
protected getSchemaDeclaration(ctx: Context, args: Args.GetSchemaDeclaration): AppendValue<Builder>;
|
|
@@ -3,7 +3,21 @@ import { kt } from '../../ast/index.js';
|
|
|
3
3
|
import { KotlinFileBuilder } from '../../file-builder.js';
|
|
4
4
|
import { getSourceDocLine, getStringEnumSchema } from '../../utils.js';
|
|
5
5
|
import { KotlinFileGenerator } from '../file-generator.js';
|
|
6
|
+
/**
|
|
7
|
+
* The default model generator. A schema that gets its own declaration is written to
|
|
8
|
+
* `{outputDir}/{packagePath}/{TypeName}.kt` as a `data class`, a plain class, an interface for a discriminated base
|
|
9
|
+
* or an enum, depending on the schema.
|
|
10
|
+
* Any other schema is mapped to a built-in Kotlin type and no file is written. Schemas that exist only as `anyOf` or
|
|
11
|
+
* `allOf` members resolve to a nullable `Any`.
|
|
12
|
+
* @see KotlinModelGenerator
|
|
13
|
+
* @see KotlinModelsGenerator
|
|
14
|
+
*/
|
|
6
15
|
export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
16
|
+
/**
|
|
17
|
+
* Generates the model for the schema in the context. Writes the model file when the schema gets its own declaration.
|
|
18
|
+
* @param ctx The context containing the schema to generate the model for.
|
|
19
|
+
* @returns The Kotlin type the schema maps to, which is a reference to the generated declaration or a built-in type.
|
|
20
|
+
*/
|
|
7
21
|
generate(ctx) {
|
|
8
22
|
if (/\/(anyOf|allOf)(\/[0-9]+)?$/.test(ctx.schema.$src.path)) {
|
|
9
23
|
// Do not generate types that are only used for anyOf and/or allOf
|
|
@@ -6,8 +6,23 @@ type Output = KotlinModelsGeneratorOutput;
|
|
|
6
6
|
type Config = KotlinModelsGeneratorConfig;
|
|
7
7
|
type SchemaOutput = KotlinModelGeneratorOutput;
|
|
8
8
|
type Context = KotlinModelsGeneratorContext;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a Kotlin model for each schema of the document and publishes the results under `kotlin.models`.
|
|
11
|
+
*
|
|
12
|
+
* Each schema is passed to the `KotlinModelGenerator` created by the model generator factory. A schema that gets its
|
|
13
|
+
* own declaration is written to `{outputDir}/{packagePath}/{TypeName}.kt`, where `packagePath` is the model package
|
|
14
|
+
* (`packageName` followed by `packageSuffix`) with the dots replaced by slashes. Other schemas get no file.
|
|
15
|
+
* The result of every schema is stored under `kotlin.models`, keyed by the schema ID. No index file is generated.
|
|
16
|
+
* @see KotlinModelsGeneratorConfig
|
|
17
|
+
* @see DefaultKotlinModelGenerator
|
|
18
|
+
*/
|
|
9
19
|
export declare class KotlinModelsGenerator extends OpenApiSchemasGenerationProviderBase<Input, Output, Config, SchemaOutput, Context> {
|
|
10
20
|
private readonly _modelGeneratorFactory;
|
|
21
|
+
/**
|
|
22
|
+
* Initializes a new instance of the KotlinModelsGenerator class.
|
|
23
|
+
* @param modelGeneratorFactory Creates the generator used for each schema. Defaults to a
|
|
24
|
+
* `DefaultKotlinModelGenerator`.
|
|
25
|
+
*/
|
|
11
26
|
constructor(modelGeneratorFactory?: Factory<KotlinModelGenerator, []>);
|
|
12
27
|
protected initResult(): Output;
|
|
13
28
|
protected buildContext(context: OpenApiGeneratorContext<KotlinModelsGeneratorInput>, config?: Partial<Config> | undefined): Context;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { Factory, OpenApiSchemasGenerationProviderBase, } from '@goast/core';
|
|
2
2
|
import { DefaultKotlinModelGenerator } from './model-generator.js';
|
|
3
3
|
import { defaultKotlinModelsGeneratorConfig, } from './models.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a Kotlin model for each schema of the document and publishes the results under `kotlin.models`.
|
|
6
|
+
*
|
|
7
|
+
* Each schema is passed to the `KotlinModelGenerator` created by the model generator factory. A schema that gets its
|
|
8
|
+
* own declaration is written to `{outputDir}/{packagePath}/{TypeName}.kt`, where `packagePath` is the model package
|
|
9
|
+
* (`packageName` followed by `packageSuffix`) with the dots replaced by slashes. Other schemas get no file.
|
|
10
|
+
* The result of every schema is stored under `kotlin.models`, keyed by the schema ID. No index file is generated.
|
|
11
|
+
* @see KotlinModelsGeneratorConfig
|
|
12
|
+
* @see DefaultKotlinModelGenerator
|
|
13
|
+
*/
|
|
4
14
|
export class KotlinModelsGenerator extends OpenApiSchemasGenerationProviderBase {
|
|
5
15
|
_modelGeneratorFactory;
|
|
16
|
+
/**
|
|
17
|
+
* Initializes a new instance of the KotlinModelsGenerator class.
|
|
18
|
+
* @param modelGeneratorFactory Creates the generator used for each schema. Defaults to a
|
|
19
|
+
* `DefaultKotlinModelGenerator`.
|
|
20
|
+
*/
|
|
6
21
|
constructor(modelGeneratorFactory) {
|
|
7
22
|
super();
|
|
8
23
|
this._modelGeneratorFactory = modelGeneratorFactory ?? Factory.fromValue(new DefaultKotlinModelGenerator());
|
|
@@ -1,19 +1,56 @@
|
|
|
1
1
|
import type { ApiSchema, DefaultGenerationProviderConfig, OpenApiSchemasGenerationProviderContext, SourceBuilder } from '@goast/core';
|
|
2
2
|
import type { kt } from '../../ast/index.ts';
|
|
3
3
|
import { type KotlinGeneratorConfig } from '../../config.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The configuration of the `KotlinModelsGenerator`. It extends the common Kotlin generator configuration with the
|
|
6
|
+
* model-specific options declared below.
|
|
7
|
+
*
|
|
8
|
+
* The common options are declared on `KotlinGeneratorConfig`. Their effect on the generated models is:
|
|
9
|
+
* - `outputDir`: The root directory of the model files, which are placed in a package-based subdirectory.
|
|
10
|
+
* Default `'generated'`.
|
|
11
|
+
* - `clearOutputDir`: Empties `outputDir` once before any model is written, so it also removes files written by other
|
|
12
|
+
* generators. Default `true`.
|
|
13
|
+
* - `existingFileBehavior`: What happens when a model file already exists at its path. Default `'error'`.
|
|
14
|
+
* - `indent`: The indentation of the generated Kotlin code. Default four spaces (`{ type: 'spaces', count: 4 }`).
|
|
15
|
+
* - `newLine`: The line separator of the generated files. Default `os.EOL`.
|
|
16
|
+
* - `typeNameCasing`: The casing of type names, which also determines the model file names. Default `'pascal'`.
|
|
17
|
+
* - `parameterNameCasing`: The casing of the parameters of the generated `set` function for `additionalProperties`.
|
|
18
|
+
* Default `'camel'`.
|
|
19
|
+
* - `functionNameCasing`: The casing of the generated `set` and `getMap` functions for `additionalProperties`.
|
|
20
|
+
* Default `'camel'`.
|
|
21
|
+
* - `propertyNameCasing`: The casing of property names, the `value` property of enums and `additionalProperties`.
|
|
22
|
+
* Default `'camel'`.
|
|
23
|
+
* - `enumValueNameCasing`: The casing of enum constant names, so the value `available` becomes `AVAILABLE`.
|
|
24
|
+
* Default `'snake'`.
|
|
25
|
+
* - `constantNameCasing`: No effect on this generator. Default `'snake'`.
|
|
26
|
+
* - `globalImports`: Imports that are not written to the generated files, such as the standard `kotlin.*`,
|
|
27
|
+
* `java.lang.*` and `kotlin.jvm.*` packages. Default: `defaultKotlinGeneratorConfig.globalImports`.
|
|
28
|
+
* - `includeSourceInDocs`: Adds the source document path to the doc comments of generated classes, interfaces, enums
|
|
29
|
+
* and interface properties. Default `false`.
|
|
30
|
+
* - `springBootVersion`: No effect on this generator, because the Jackson annotations it writes are the same for both
|
|
31
|
+
* versions. Default `3`.
|
|
32
|
+
* @see defaultKotlinModelsGeneratorConfig
|
|
33
|
+
*/
|
|
4
34
|
export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
|
|
5
35
|
/**
|
|
6
36
|
* The package name for generated models.
|
|
37
|
+
* The model files are placed in `{outputDir}/{packagePath}`, where `packagePath` is `packageName` followed by
|
|
38
|
+
* `packageSuffix` with the dots replaced by slashes. The same package is written as the `package` declaration.
|
|
7
39
|
* @default 'com.openapi.generated'
|
|
8
40
|
*/
|
|
9
41
|
packageName: string;
|
|
10
42
|
/**
|
|
11
43
|
* The suffix to append to the package name for generated models.
|
|
44
|
+
* Include the leading `.`, because the suffix is appended as written. A function receives the schema of each model
|
|
45
|
+
* and returns the suffix for it, which allows models to be split across packages. The resulting package determines
|
|
46
|
+
* the model's file path and its `package` declaration.
|
|
12
47
|
* @default '.model'
|
|
13
48
|
*/
|
|
14
49
|
packageSuffix: string | ((schema: ApiSchema) => string);
|
|
15
50
|
/**
|
|
16
51
|
* Determines how `oneOf` schemas should be treated.
|
|
52
|
+
* This changes which properties the generated class or interface declares. Under `treat-as-any-of` the properties of
|
|
53
|
+
* the branches are merged as optional properties, and under `treat-as-all-of` they are merged as `allOf` members.
|
|
17
54
|
* - `treat-as-any-of`: Treat `oneOf` schemas as `anyOf` schemas.
|
|
18
55
|
* - `treat-as-all-of`: Treat `oneOf` schemas as `allOf` schemas.
|
|
19
56
|
* @default 'treat-as-any-of'
|
|
@@ -21,40 +58,94 @@ export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
|
|
|
21
58
|
oneOfBehavior: 'treat-as-any-of' | 'treat-as-all-of';
|
|
22
59
|
/**
|
|
23
60
|
* Determines how schemas of type `object` without properties should be treated.
|
|
24
|
-
*
|
|
25
|
-
*
|
|
61
|
+
* Empty object schemas that allow additional properties always become `Map<String, ...>`, and discriminated base
|
|
62
|
+
* schemas always get their own file, regardless of this setting.
|
|
63
|
+
* - `use-any`: Generate `Any` type for empty object schemas. No file is generated for them.
|
|
64
|
+
* - `generate-empty-class`: Generate an empty class for empty object schemas. The class is not a `data class`.
|
|
26
65
|
* @default 'generate-empty-class'
|
|
27
66
|
*/
|
|
28
67
|
emptyObjectTypeBehavior: 'use-any' | 'generate-empty-class';
|
|
29
68
|
/**
|
|
30
69
|
* Whether to add Jackson annotations to generated models.
|
|
70
|
+
* When `true`, classes and interfaces get `@JsonClassDescription`, interfaces also get `@JsonTypeInfo` and
|
|
71
|
+
* `@JsonSubTypes`, and properties get `@JsonProperty`, `@JsonPropertyDescription` and `@JsonInclude` where
|
|
72
|
+
* applicable. When `false`, these are omitted. Enum constants keep their `@JsonProperty` annotation, and
|
|
73
|
+
* `additionalProperties` keep `@JsonIgnore`, `@JsonAnySetter` and `@JsonAnyGetter` either way.
|
|
31
74
|
* @default true
|
|
32
75
|
*/
|
|
33
76
|
addJacksonAnnotations: boolean;
|
|
34
77
|
/**
|
|
35
78
|
* Whether to add Jakarta Validation annotations to generated models.
|
|
79
|
+
* When `true`, constructor parameters of generated classes get `@Pattern`, `@NotEmpty`, `@Size`, `@Min` and `@Max`
|
|
80
|
+
* from the property's constraints, and `@Valid` when the property refers to a generated model. Interface properties
|
|
81
|
+
* do not receive them. When `false`, none of these are added.
|
|
36
82
|
* @default true
|
|
37
83
|
*/
|
|
38
84
|
addJakartaValidationAnnotations: boolean;
|
|
39
85
|
/**
|
|
40
86
|
* Whether to add Swagger annotations to generated models.
|
|
87
|
+
* When `true`, each constructor parameter of a generated class gets a `@Schema` annotation with its example,
|
|
88
|
+
* `required` flag, description and deprecation. Interface properties do not receive it. When `false`, none is added.
|
|
41
89
|
* @default true
|
|
42
90
|
*/
|
|
43
91
|
addSwaggerAnnotations: boolean;
|
|
44
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* The default configuration of the `KotlinModelsGenerator`. Options passed to the generator are merged on top of these.
|
|
95
|
+
* It includes the common Kotlin defaults from `defaultKotlinGeneratorConfig`.
|
|
96
|
+
* @see KotlinModelsGeneratorConfig
|
|
97
|
+
*/
|
|
45
98
|
export declare const defaultKotlinModelsGeneratorConfig: DefaultGenerationProviderConfig<KotlinModelsGeneratorConfig>;
|
|
99
|
+
/**
|
|
100
|
+
* The input of the `KotlinModelsGenerator`. The generator does not use any input data, so this type has no properties.
|
|
101
|
+
*/
|
|
46
102
|
export type KotlinModelsGeneratorInput = {};
|
|
103
|
+
/**
|
|
104
|
+
* The output of the `KotlinModelsGenerator`. It is merged into the generation result, where the models are published
|
|
105
|
+
* under the `kotlin.models` key.
|
|
106
|
+
* @see KotlinModelGeneratorOutput
|
|
107
|
+
*/
|
|
47
108
|
export type KotlinModelsGeneratorOutput = {
|
|
109
|
+
/**
|
|
110
|
+
* The Kotlin results of the generator, grouped under the `kotlin` key.
|
|
111
|
+
*/
|
|
48
112
|
kotlin: {
|
|
113
|
+
/**
|
|
114
|
+
* The generated models, keyed by the ID of their schema. Each entry describes the Kotlin type the schema maps to.
|
|
115
|
+
*/
|
|
49
116
|
models: {
|
|
117
|
+
/**
|
|
118
|
+
* The result for the schema with the given ID. Schemas that get no file are included as well.
|
|
119
|
+
*/
|
|
50
120
|
[schemaId: string]: KotlinModelGeneratorOutput;
|
|
51
121
|
};
|
|
52
122
|
};
|
|
53
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* The result of generating one schema. Its `type` property is the Kotlin type the schema maps to: for a model with
|
|
126
|
+
* its own file, a reference to the generated class, interface or enum in its package. For any other schema, the
|
|
127
|
+
* built-in type it was mapped to, such as `String`, `List<...>`, `Map<String, ...>` or `Any`. The file path is not
|
|
128
|
+
* part of the result.
|
|
129
|
+
* @see KotlinModelsGeneratorOutput
|
|
130
|
+
*/
|
|
54
131
|
export type KotlinModelGeneratorOutput = {
|
|
55
132
|
type: kt.Reference<SourceBuilder>;
|
|
56
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* The context of the `KotlinModelsGenerator`. Besides the generator configuration (`config`) and the parsed document
|
|
136
|
+
* (`data`), it holds the `output` being built, which contains the `kotlin.models` entries, and the results already
|
|
137
|
+
* generated per schema (`existingSchemaResults`).
|
|
138
|
+
* @see KotlinModelGeneratorContext
|
|
139
|
+
*/
|
|
57
140
|
export type KotlinModelsGeneratorContext = OpenApiSchemasGenerationProviderContext<KotlinModelsGeneratorInput, KotlinModelsGeneratorOutput, KotlinModelsGeneratorConfig, KotlinModelGeneratorOutput>;
|
|
141
|
+
/**
|
|
142
|
+
* The context passed to a `KotlinModelGenerator` for one schema. It extends the `KotlinModelsGeneratorContext` with
|
|
143
|
+
* the schema to generate.
|
|
144
|
+
* @see KotlinModelsGeneratorContext
|
|
145
|
+
*/
|
|
58
146
|
export type KotlinModelGeneratorContext = KotlinModelsGeneratorContext & {
|
|
147
|
+
/**
|
|
148
|
+
* The schema to generate the model for. Its `$src` path identifies where it appears in the document.
|
|
149
|
+
*/
|
|
59
150
|
schema: ApiSchema;
|
|
60
151
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { defaultKotlinGeneratorConfig } from '../../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default configuration of the `KotlinModelsGenerator`. Options passed to the generator are merged on top of these.
|
|
4
|
+
* It includes the common Kotlin defaults from `defaultKotlinGeneratorConfig`.
|
|
5
|
+
* @see KotlinModelsGeneratorConfig
|
|
6
|
+
*/
|
|
2
7
|
export const defaultKotlinModelsGeneratorConfig = {
|
|
3
8
|
...defaultKotlinGeneratorConfig,
|
|
4
9
|
packageName: 'com.openapi.generated',
|