@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,94 +1,263 @@
|
|
|
1
1
|
import type { ApiEndpoint, ApiResponse, ApiSchema, SourceBuilder } from '@goast/core';
|
|
2
2
|
import type { kt } from '../../../ast/index.ts';
|
|
3
3
|
import type { ApiParameterWithMultipartInfo } from '../../../types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Arguments for writing a file that holds response entity classes. The default generator does not use it, because it
|
|
6
|
+
* nests the response entity classes in the API interface.
|
|
7
|
+
*/
|
|
4
8
|
export type GenerateApiResponseEntitiesFile = {
|
|
9
|
+
/**
|
|
10
|
+
* The directory the file is written to, such as `{outputDir}/com/openapi/generated/api` with the default settings.
|
|
11
|
+
*/
|
|
5
12
|
dirPath: string;
|
|
13
|
+
/**
|
|
14
|
+
* The package the file is declared in, with `packageSuffix` already applied.
|
|
15
|
+
*/
|
|
6
16
|
packageName: string;
|
|
7
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Arguments for building the content of a response entities file. The default generator does not use it. The
|
|
20
|
+
* `packageName` is the package declared at the top of the file, with `packageSuffix` already applied.
|
|
21
|
+
*/
|
|
8
22
|
export type GetApiResponseEntitiesFileContent = {
|
|
9
23
|
packageName: string;
|
|
10
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Arguments for building the response entity classes of a file. It takes no properties, and the default generator
|
|
27
|
+
* does not call it.
|
|
28
|
+
*/
|
|
11
29
|
export type GetApiResponseEntities = object;
|
|
30
|
+
/**
|
|
31
|
+
* Arguments for writing the API interface file of a service.
|
|
32
|
+
*/
|
|
12
33
|
export type GenerateApiInterfaceFile = {
|
|
34
|
+
/**
|
|
35
|
+
* The directory the interface file is written to, such as `{outputDir}/com/openapi/generated/api`.
|
|
36
|
+
*/
|
|
13
37
|
dirPath: string;
|
|
38
|
+
/**
|
|
39
|
+
* The package the interface is declared in, with `packageSuffix` already applied.
|
|
40
|
+
*/
|
|
14
41
|
packageName: string;
|
|
15
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Arguments for building the content of the API interface file. Its `interfaceName` is the name of the interface
|
|
45
|
+
* declared in the file.
|
|
46
|
+
*/
|
|
16
47
|
export type GetApiInterfaceFileContent = {
|
|
17
48
|
interfaceName: string;
|
|
18
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Arguments for building the API interface declaration, including its functions and path constants. Its
|
|
52
|
+
* `interfaceName` is the name of the interface, already converted with `typeNameCasing`.
|
|
53
|
+
*/
|
|
19
54
|
export type GetApiInterface = {
|
|
20
55
|
interfaceName: string;
|
|
21
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Arguments for building the interface function of one endpoint. Its `endpoint` is the endpoint whose parameters and
|
|
59
|
+
* responses determine the signature.
|
|
60
|
+
*/
|
|
22
61
|
export type GetApiInterfaceEndpointMethod = {
|
|
23
62
|
endpoint: ApiEndpoint;
|
|
24
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Arguments for building the `{Endpoint}_ResponseEntity` class of one endpoint, which is nested in the API interface.
|
|
66
|
+
* Its `endpoint` is the endpoint whose response status codes add static factory functions.
|
|
67
|
+
*/
|
|
25
68
|
export type GetApiResponseEntityClass = {
|
|
26
69
|
endpoint: ApiEndpoint;
|
|
27
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Arguments for writing the controller file of a service.
|
|
73
|
+
*/
|
|
28
74
|
export type GenerateApiControllerFile = {
|
|
75
|
+
/**
|
|
76
|
+
* The directory the controller file is written to, derived from its package below `outputDir`.
|
|
77
|
+
*/
|
|
29
78
|
dirPath: string;
|
|
79
|
+
/**
|
|
80
|
+
* The package the controller class is declared in, with `packageSuffix` already applied.
|
|
81
|
+
*/
|
|
30
82
|
packageName: string;
|
|
31
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* Arguments for building the content of the controller file. Its `controllerName` is the name of the controller class
|
|
86
|
+
* declared in the file.
|
|
87
|
+
*/
|
|
32
88
|
export type GetApiControllerFileContent = {
|
|
33
89
|
controllerName: string;
|
|
34
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Arguments for building the controller class, which implements the API interface and forwards to the delegate.
|
|
93
|
+
* Its `controllerName` is the name of the class, already converted with `typeNameCasing`.
|
|
94
|
+
*/
|
|
35
95
|
export type GetApiController = {
|
|
36
96
|
controllerName: string;
|
|
37
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Arguments for writing the delegate interface file of a service.
|
|
100
|
+
*/
|
|
38
101
|
export type GenerateApiDelegateInterfaceFile = {
|
|
102
|
+
/**
|
|
103
|
+
* The directory the delegate file is written to. It is the same directory as the API interface file.
|
|
104
|
+
*/
|
|
39
105
|
dirPath: string;
|
|
106
|
+
/**
|
|
107
|
+
* The package the delegate interface is declared in, with `packageSuffix` already applied.
|
|
108
|
+
*/
|
|
40
109
|
packageName: string;
|
|
41
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Arguments for building the content of the delegate interface file. Its `delegateInterfaceName` is the name of the
|
|
113
|
+
* delegate interface declared in the file.
|
|
114
|
+
*/
|
|
42
115
|
export type GetApiDelegateInterfaceFileContent = {
|
|
43
116
|
delegateInterfaceName: string;
|
|
44
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* Arguments for building the delegate interface declaration, which has one function per endpoint. Its
|
|
120
|
+
* `delegateInterfaceName` is the name of the interface, already converted with `typeNameCasing`.
|
|
121
|
+
*/
|
|
45
122
|
export type GetApiDelegateInterface = {
|
|
46
123
|
delegateInterfaceName: string;
|
|
47
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* Arguments for building the delegate function of one endpoint. Its return type follows the endpoint's
|
|
127
|
+
* `strict-response` setting and `strictResponseEntities`. Its `endpoint` is the endpoint whose responses determine the
|
|
128
|
+
* default return type.
|
|
129
|
+
*/
|
|
48
130
|
export type GetApiDelegateInterfaceEndpointMethod = {
|
|
49
131
|
endpoint: ApiEndpoint;
|
|
50
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
* Arguments for resolving the Kotlin type of a parameter.
|
|
135
|
+
*/
|
|
51
136
|
export type GetParameterType = {
|
|
137
|
+
/**
|
|
138
|
+
* The endpoint the parameter belongs to. The default implementation does not read it.
|
|
139
|
+
*/
|
|
52
140
|
endpoint: ApiEndpoint;
|
|
141
|
+
/**
|
|
142
|
+
* The parameter whose type is resolved. Multipart file parts resolve to `FilePart`, and body parameters are
|
|
143
|
+
* adjusted by `arrayType`.
|
|
144
|
+
*/
|
|
53
145
|
parameter: ApiParameterWithMultipartInfo;
|
|
146
|
+
/**
|
|
147
|
+
* A reference that replaces the type derived from the parameter schema, such as `String` for an enum parameter.
|
|
148
|
+
*/
|
|
54
149
|
type?: kt.Reference<SourceBuilder>;
|
|
55
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Arguments for resolving the body type of a response, which becomes the type argument of `ResponseEntity`. Its
|
|
153
|
+
* `endpoint` is the endpoint whose responses are inspected when `response` is not given. Its `response` is the single
|
|
154
|
+
* response whose body type is resolved. When omitted, the body types of all responses are combined, and differing body
|
|
155
|
+
* types resolve to `Any`.
|
|
156
|
+
*/
|
|
56
157
|
export type GetResponseType = {
|
|
57
158
|
endpoint: ApiEndpoint;
|
|
58
159
|
response?: ApiResponse;
|
|
59
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Arguments for resolving the type of a schema in a usage position, such as a parameter or a response body.
|
|
163
|
+
* @template TBuilder The type of the source builder the resolved type is written to.
|
|
164
|
+
*/
|
|
60
165
|
export type GetTypeUsage<TBuilder extends SourceBuilder> = {
|
|
166
|
+
/**
|
|
167
|
+
* The schema the type is derived from. When it is `undefined`, the fallback type is used.
|
|
168
|
+
*/
|
|
61
169
|
schema: ApiSchema | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Overrides the nullability of the resolved type. When omitted, the nullability of the derived type is kept.
|
|
172
|
+
*/
|
|
62
173
|
nullable?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* The type used when no type can be derived from the schema. Defaults to `Any`, nullable when `nullable` is set.
|
|
176
|
+
*/
|
|
63
177
|
fallback?: kt.Type<TBuilder>;
|
|
178
|
+
/**
|
|
179
|
+
* A reference that replaces the type derived from the schema.
|
|
180
|
+
*/
|
|
64
181
|
type?: kt.Reference<TBuilder>;
|
|
65
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* Arguments for building the KDoc text of an endpoint function. Its `endpoint` is the endpoint whose description is
|
|
185
|
+
* used, with its source location appended when `includeSourceInDocs` is set.
|
|
186
|
+
*/
|
|
66
187
|
export type GetEndpointDocDescription = {
|
|
67
188
|
endpoint: ApiEndpoint;
|
|
68
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Arguments for looking up the type that the models generator assigned to a schema. Its `schema` is looked up in the
|
|
192
|
+
* `kotlin.models` output by `id`, and `undefined` yields `undefined`.
|
|
193
|
+
*/
|
|
69
194
|
export type GetSchemaType = {
|
|
70
195
|
schema: ApiSchema | undefined;
|
|
71
196
|
};
|
|
197
|
+
/**
|
|
198
|
+
* Arguments for building the `@RequestMapping` value of the API interface or the controller. Its `prefix` is the
|
|
199
|
+
* property prefix of the base path placeholder, such as `openapi.pet` in `propertyNameCasing`. The API interface passes
|
|
200
|
+
* `api`, and the default is `openapi.<service>`.
|
|
201
|
+
*/
|
|
72
202
|
export type GetControllerRequestMapping = {
|
|
73
203
|
prefix?: string;
|
|
74
204
|
};
|
|
205
|
+
/**
|
|
206
|
+
* Arguments for resolving the base path of a service. It takes no properties, and the service comes from the context.
|
|
207
|
+
*/
|
|
75
208
|
export type GetBasePath = object;
|
|
209
|
+
/**
|
|
210
|
+
* Arguments for resolving the path of an endpoint as it is written to the path constant. Its `endpoint` is the endpoint
|
|
211
|
+
* whose path is passed through `pathModifier` first.
|
|
212
|
+
*/
|
|
76
213
|
export type GetEndpointPath = {
|
|
77
214
|
endpoint: ApiEndpoint;
|
|
78
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* Arguments for resolving the directory that the files of a package are written to. Its `packageName` is the package
|
|
218
|
+
* whose dots become `/`, below `outputDir`.
|
|
219
|
+
*/
|
|
79
220
|
export type GetDirectoryPath = {
|
|
80
221
|
packageName: string;
|
|
81
222
|
};
|
|
223
|
+
/**
|
|
224
|
+
* Arguments for naming the constant that holds an endpoint's path in the API interface companion object. Its `endpoint`
|
|
225
|
+
* is the endpoint whose constant is named: the endpoint name followed by `_path`, in `constantNameCasing`.
|
|
226
|
+
*/
|
|
82
227
|
export type GetPathConstantName = {
|
|
83
228
|
endpoint: ApiEndpoint;
|
|
84
229
|
};
|
|
230
|
+
/**
|
|
231
|
+
* Arguments for resolving the package of a service's files, with `packageSuffix` applied. It takes no properties, and
|
|
232
|
+
* the service comes from the context.
|
|
233
|
+
*/
|
|
85
234
|
export type GetPackageName = object;
|
|
235
|
+
/**
|
|
236
|
+
* Arguments for naming the response entity class of an endpoint. Its `endpoint` is the endpoint whose class is named:
|
|
237
|
+
* the endpoint name plus `_ResponseEntity`.
|
|
238
|
+
*/
|
|
86
239
|
export type GetApiResponseEntityName = {
|
|
87
240
|
endpoint: ApiEndpoint;
|
|
88
241
|
};
|
|
242
|
+
/**
|
|
243
|
+
* Arguments for naming the API interface of a service. It takes no properties, and the service comes from the context.
|
|
244
|
+
*/
|
|
89
245
|
export type GetApiInterfaceName = object;
|
|
246
|
+
/**
|
|
247
|
+
* Arguments for naming the delegate interface of a service. It takes no properties, and the service comes from the
|
|
248
|
+
* context.
|
|
249
|
+
*/
|
|
90
250
|
export type GetApiDelegateInterfaceName = object;
|
|
251
|
+
/**
|
|
252
|
+
* Arguments for naming the controller class of a service. It takes no properties, and the service comes from the
|
|
253
|
+
* context.
|
|
254
|
+
*/
|
|
91
255
|
export type GetApiControllerName = object;
|
|
256
|
+
/**
|
|
257
|
+
* Arguments for collecting the parameters of an endpoint, in the order of the generated function signature. Its
|
|
258
|
+
* `endpoint` is the endpoint whose parameters are collected: path, query and header parameters first, then the request
|
|
259
|
+
* body, or one parameter per multipart part for `multipart/form-data`.
|
|
260
|
+
*/
|
|
92
261
|
export type GetAllParameters = {
|
|
93
262
|
endpoint: ApiEndpoint;
|
|
94
263
|
};
|
|
@@ -3,35 +3,155 @@ import type { KotlinImport } from '../../../common-results.ts';
|
|
|
3
3
|
import { type KotlinGeneratorConfig } from '../../../config.ts';
|
|
4
4
|
import type { KotlinModelsGeneratorOutput } from '../../models/index.ts';
|
|
5
5
|
import type { getReferenceFactories } from './refs.ts';
|
|
6
|
+
/**
|
|
7
|
+
* The configuration of the spring controllers generator. It extends `KotlinGeneratorConfig`, so the common Kotlin
|
|
8
|
+
* options apply as well. This generator reads `typeNameCasing` (interface, controller, delegate and response
|
|
9
|
+
* entity names),
|
|
10
|
+
* `parameterNameCasing` (parameter names), `functionNameCasing` (functions and status code factories),
|
|
11
|
+
* `propertyNameCasing` (the base path property prefix), `constantNameCasing` (path constants), `includeSourceInDocs`
|
|
12
|
+
* (endpoint docs) and `globalImports` (imports).
|
|
13
|
+
*
|
|
14
|
+
* `springBootVersion` (`KotlinGeneratorConfig`, `@default 3`) changes this generator's output in these places only:
|
|
15
|
+
* - `3`: the `T` of a response entity class has no bound, its body parameter is non-null, and the status code factories
|
|
16
|
+
* without a body take `Unit?`. Responses whose body types differ resolve to `Any?`.
|
|
17
|
+
* - `4`: the `T` of a response entity class is bounded by `Any`, its body parameter is `T?`, the status code factories
|
|
18
|
+
* without a body take `Unit`, and responses whose body types differ resolve to `Any`. This matches the non-null
|
|
19
|
+
* `ResponseEntity<T : Any>` bound of Spring Framework 7.
|
|
20
|
+
* The Spring types it references come from the same packages for both values, so the imports do not change.
|
|
21
|
+
* @see KotlinGeneratorConfig
|
|
22
|
+
*/
|
|
6
23
|
export type KotlinServicesGeneratorConfig = KotlinGeneratorConfig & {
|
|
24
|
+
/**
|
|
25
|
+
* The base package name. Combined with `packageSuffix`, it gives the package of each service's files and of the
|
|
26
|
+
* shared `ApiExceptionHandler`.
|
|
27
|
+
* @default 'com.openapi.generated'
|
|
28
|
+
*/
|
|
7
29
|
packageName: string;
|
|
30
|
+
/**
|
|
31
|
+
* The suffix appended to `packageName`, including the leading `.`. A function receives each service and returns the
|
|
32
|
+
* suffix for that service's files. It receives `null` when `ApiExceptionHandler` is placed, because no service is in
|
|
33
|
+
* scope there.
|
|
34
|
+
* @default '.api'
|
|
35
|
+
*/
|
|
8
36
|
packageSuffix: string | ((service: ApiService | null) => string);
|
|
37
|
+
/**
|
|
38
|
+
* The base path of each service. It becomes the default of the `${...base-path:...}` placeholder in the
|
|
39
|
+
* `@RequestMapping` annotations, so Spring can still override it with a property. A string replaces the base path
|
|
40
|
+
* verbatim. A regular expression is matched against the base path, and its first match replaces it; without a match
|
|
41
|
+
* the base path is kept. A function receives the base path and the service and returns the new base path. When not
|
|
42
|
+
* set, the first server URL of the service's document is used, or `/` when there is none.
|
|
43
|
+
* @default undefined
|
|
44
|
+
*/
|
|
9
45
|
basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
|
|
46
|
+
/**
|
|
47
|
+
* Rewrites the path of each endpoint before it is written to the path constants of the API interface. A regular
|
|
48
|
+
* expression is matched against the path, and its first match replaces the whole path; without a match the path is
|
|
49
|
+
* kept. A function receives the path and the endpoint and returns the new path.
|
|
50
|
+
* @default undefined
|
|
51
|
+
*/
|
|
10
52
|
pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
|
|
53
|
+
/**
|
|
54
|
+
* Whether the API interface gets Swagger annotations: `@Operation`, `@ApiResponses` and `@Parameter` on its functions
|
|
55
|
+
* and parameters, plus the `@Schema` annotations of parameters. Controllers and delegates get none of them.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
11
58
|
addSwaggerAnnotations: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Whether Jakarta annotations are added. `@Valid` goes on each parameter whose type is not from
|
|
61
|
+
* the `kotlin` or `java` packages, and `@Generated` goes on the controller and the delegate interface.
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
12
64
|
addJakartaValidationAnnotations: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* How array types are written for request bodies and response bodies. `'flux'` writes them as `Flux<T>`, and `'list'`
|
|
67
|
+
* keeps them as `List<T>`. Query, path and header parameters are not affected.
|
|
68
|
+
* @default 'flux'
|
|
69
|
+
*/
|
|
13
70
|
arrayType: 'list' | 'flux';
|
|
71
|
+
/**
|
|
72
|
+
* Whether the endpoint functions of the API interface and the delegate, and `handleApiException` of
|
|
73
|
+
* `ApiExceptionHandler`, are written with the `suspend` modifier.
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
14
76
|
suspendingFunctions: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether each endpoint gets its own `{Endpoint}_ResponseEntity` class, nested in the API interface. The delegate
|
|
79
|
+
* function of that endpoint then returns this class, and its default body is the 501 entity of the class. The
|
|
80
|
+
* endpoint's `strict-response` custom property overrides this setting per endpoint.
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
15
83
|
strictResponseEntities: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The status codes that get a static factory function in each `{Endpoint}_ResponseEntity` class, named after their
|
|
86
|
+
* reason phrase, such as `badRequest`. Code 501 is always added, as are the codes of the endpoint's own responses.
|
|
87
|
+
* Only used when response entity classes are generated, see `strictResponseEntities`.
|
|
88
|
+
* @default [400, 401, 403, 500, 501]
|
|
89
|
+
*/
|
|
16
90
|
defaultStatusCodes: number[];
|
|
17
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* The default configuration of the spring controllers generator. It extends `defaultKotlinGeneratorConfig`.
|
|
94
|
+
* @see KotlinServicesGeneratorConfig
|
|
95
|
+
*/
|
|
18
96
|
export declare const defaultKotlinServicesGeneratorConfig: DefaultGenerationProviderConfig<KotlinServicesGeneratorConfig>;
|
|
97
|
+
/**
|
|
98
|
+
* The input of the spring controllers generator, which is the output of the models generator. The type of each request
|
|
99
|
+
* and response body is looked up in its `kotlin.models` output.
|
|
100
|
+
* @see KotlinModelsGeneratorOutput
|
|
101
|
+
*/
|
|
19
102
|
export type KotlinServicesGeneratorInput = KotlinModelsGeneratorOutput;
|
|
103
|
+
/**
|
|
104
|
+
* The output of the spring controllers generator, which later generators read from `kotlin.services`.
|
|
105
|
+
* @see KotlinServiceGeneratorOutput
|
|
106
|
+
*/
|
|
20
107
|
export type KotlinServicesGeneratorOutput = {
|
|
108
|
+
/**
|
|
109
|
+
* The Kotlin output, under which the spring controllers generator publishes `services`.
|
|
110
|
+
*/
|
|
21
111
|
kotlin: {
|
|
112
|
+
/**
|
|
113
|
+
* The generated files of each service, keyed by the service id (`ApiService.id`).
|
|
114
|
+
*/
|
|
22
115
|
services: {
|
|
23
116
|
[serviceId: string]: KotlinServiceGeneratorOutput;
|
|
24
117
|
};
|
|
25
118
|
};
|
|
26
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* The files written for one service. Each entry gives the type name and package of one generated file.
|
|
122
|
+
*/
|
|
27
123
|
export type KotlinServiceGeneratorOutput = {
|
|
124
|
+
/**
|
|
125
|
+
* The API interface, named after the service with an `_Api` suffix.
|
|
126
|
+
*/
|
|
28
127
|
apiInterface: KotlinImport;
|
|
128
|
+
/**
|
|
129
|
+
* The controller class, which implements the API interface and forwards each call to the delegate.
|
|
130
|
+
*/
|
|
29
131
|
apiController: KotlinImport;
|
|
132
|
+
/**
|
|
133
|
+
* The delegate interface, which has one function per endpoint for the implementation to override.
|
|
134
|
+
*/
|
|
30
135
|
apiDelegate: KotlinImport;
|
|
31
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* The context of the spring controllers generator for all services.
|
|
139
|
+
* @see KotlinServicesGeneratorConfig
|
|
140
|
+
*/
|
|
32
141
|
export type KotlinServicesGeneratorContext = OpenApiServicesGenerationProviderContext<KotlinServicesGeneratorInput, KotlinServicesGeneratorOutput, KotlinServicesGeneratorConfig, KotlinServiceGeneratorOutput> & {
|
|
142
|
+
/**
|
|
143
|
+
* The factories for the references to the shared types, created from the configuration.
|
|
144
|
+
* @see getReferenceFactories
|
|
145
|
+
*/
|
|
33
146
|
refs: ReturnType<typeof getReferenceFactories>;
|
|
34
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* The context of the spring controllers generator for one service.
|
|
150
|
+
* @see KotlinServicesGeneratorContext
|
|
151
|
+
*/
|
|
35
152
|
export type KotlinServiceGeneratorContext = KotlinServicesGeneratorContext & {
|
|
153
|
+
/**
|
|
154
|
+
* The service whose files are generated.
|
|
155
|
+
*/
|
|
36
156
|
service: ApiService;
|
|
37
157
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { defaultKotlinGeneratorConfig } from '../../../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default configuration of the spring controllers generator. It extends `defaultKotlinGeneratorConfig`.
|
|
4
|
+
* @see KotlinServicesGeneratorConfig
|
|
5
|
+
*/
|
|
2
6
|
export const defaultKotlinServicesGeneratorConfig = {
|
|
3
7
|
...defaultKotlinGeneratorConfig,
|
|
4
8
|
packageName: 'com.openapi.generated',
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { kt } from '../../../ast/index.ts';
|
|
2
2
|
import type { KotlinServicesGeneratorConfig } from './models.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the factories for the references to the types that all services share. These types are written once per
|
|
5
|
+
* run, not once per service, and live in the base package: `packageName` followed by `packageSuffix`.
|
|
6
|
+
*
|
|
7
|
+
* A `packageSuffix` function is called with `null` here, because no service is in scope.
|
|
8
|
+
*
|
|
9
|
+
* @param options The services generator configuration. Uses `packageName`, `packageSuffix` and `typeNameCasing`.
|
|
10
|
+
* @returns The reference factories, keyed by reference name. `apiExceptionHandler` references `ApiExceptionHandler`.
|
|
11
|
+
*/
|
|
3
12
|
export declare function getReferenceFactories(options: KotlinServicesGeneratorConfig): {
|
|
4
13
|
apiExceptionHandler: kt.ReferenceFactory;
|
|
5
14
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { toCasing } from '@goast/core';
|
|
2
2
|
import { kt } from '../../../ast/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the factories for the references to the types that all services share. These types are written once per
|
|
5
|
+
* run, not once per service, and live in the base package: `packageName` followed by `packageSuffix`.
|
|
6
|
+
*
|
|
7
|
+
* A `packageSuffix` function is called with `null` here, because no service is in scope.
|
|
8
|
+
*
|
|
9
|
+
* @param options The services generator configuration. Uses `packageName`, `packageSuffix` and `typeNameCasing`.
|
|
10
|
+
* @returns The reference factories, keyed by reference name. `apiExceptionHandler` references `ApiExceptionHandler`.
|
|
11
|
+
*/
|
|
3
12
|
export function getReferenceFactories(options) {
|
|
4
13
|
const packageSuffix = typeof options.packageSuffix === 'string' ? options.packageSuffix : options.packageSuffix(null);
|
|
5
14
|
const packageName = options.packageName + packageSuffix;
|
|
@@ -9,10 +9,31 @@ import type { KotlinServiceGeneratorContext, KotlinServiceGeneratorOutput } from
|
|
|
9
9
|
type Context = KotlinServiceGeneratorContext;
|
|
10
10
|
type Output = KotlinServiceGeneratorOutput;
|
|
11
11
|
type Builder = KotlinFileBuilder;
|
|
12
|
+
/**
|
|
13
|
+
* Generates the controller files of one service. Implement it to replace the generation of a service's controllers.
|
|
14
|
+
* @template TOutput The type of the result, which describes the files that were written.
|
|
15
|
+
* @see DefaultKotlinSpringControllerGenerator
|
|
16
|
+
*/
|
|
12
17
|
export interface KotlinSpringControllerGenerator<TOutput extends Output = Output> {
|
|
18
|
+
/**
|
|
19
|
+
* Writes the files of the service in the context and describes them.
|
|
20
|
+
* @param ctx The context of the service to generate.
|
|
21
|
+
* @returns The output that describes the written files, or a promise that resolves to it.
|
|
22
|
+
*/
|
|
13
23
|
generate(ctx: Context): MaybePromise<TOutput>;
|
|
14
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The default generator of the Spring MVC controller files of one service. It writes `{Service}_Api.kt`,
|
|
27
|
+
* `{Service}_ApiController.kt` and `{Service}_ApiDelegate.kt` into the package directory of the service, below
|
|
28
|
+
* `{outputDir}`. Each part of the output is built by a protected method, so subclasses can change one part at a time.
|
|
29
|
+
* @see KotlinSpringControllersGenerator
|
|
30
|
+
*/
|
|
15
31
|
export declare class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator<Context, Output> implements KotlinSpringControllerGenerator {
|
|
32
|
+
/**
|
|
33
|
+
* Writes the API interface, the controller and the delegate interface of the service.
|
|
34
|
+
* @param ctx The context of the service to generate.
|
|
35
|
+
* @returns The imports of the three written files, as `apiInterface`, `apiController` and `apiDelegate`.
|
|
36
|
+
*/
|
|
16
37
|
generate(ctx: KotlinServiceGeneratorContext): MaybePromise<KotlinServiceGeneratorOutput>;
|
|
17
38
|
protected generateApiInterfaceFile(ctx: Context, args: Args.GenerateApiInterfaceFile): KotlinImport;
|
|
18
39
|
protected getApiInterfaceFileContent(ctx: Context, args: Args.GetApiInterfaceFileContent): AppendValueGroup<Builder>;
|
|
@@ -53,5 +74,13 @@ export declare class DefaultKotlinSpringControllerGenerator extends KotlinFileGe
|
|
|
53
74
|
protected getAllParameters(ctx: Context, args: Args.GetAllParameters): ApiParameterWithMultipartInfo[];
|
|
54
75
|
private createApiParameter;
|
|
55
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Adjusts an array type for the `arrayType` setting. With `'flux'`, a `List<T>` becomes `Flux<T>`. With `'list'`, or for
|
|
79
|
+
* any type that is not a `List`, the type is returned unchanged.
|
|
80
|
+
* @template T The type of the value to adjust, which is a `kt.Type` or a reference to one.
|
|
81
|
+
* @param ctx The context of the service, which provides `arrayType`.
|
|
82
|
+
* @param type The type to adjust.
|
|
83
|
+
* @returns The adjusted type.
|
|
84
|
+
*/
|
|
56
85
|
export declare function adjustListType<T>(ctx: Context, type: T): T;
|
|
57
86
|
export {};
|
|
@@ -5,7 +5,18 @@ import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
|
5
5
|
import { getArrayItemStringEnumSchema, getSourceDocLine, getStringEnumSchema, modifyString } from '../../../utils.js';
|
|
6
6
|
import { KotlinFileGenerator } from '../../file-generator.js';
|
|
7
7
|
const strictResponseCustomProperty = 'strict-response';
|
|
8
|
+
/**
|
|
9
|
+
* The default generator of the Spring MVC controller files of one service. It writes `{Service}_Api.kt`,
|
|
10
|
+
* `{Service}_ApiController.kt` and `{Service}_ApiDelegate.kt` into the package directory of the service, below
|
|
11
|
+
* `{outputDir}`. Each part of the output is built by a protected method, so subclasses can change one part at a time.
|
|
12
|
+
* @see KotlinSpringControllersGenerator
|
|
13
|
+
*/
|
|
8
14
|
export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator {
|
|
15
|
+
/**
|
|
16
|
+
* Writes the API interface, the controller and the delegate interface of the service.
|
|
17
|
+
* @param ctx The context of the service to generate.
|
|
18
|
+
* @returns The imports of the three written files, as `apiInterface`, `apiController` and `apiDelegate`.
|
|
19
|
+
*/
|
|
9
20
|
generate(ctx) {
|
|
10
21
|
const packageName = this.getPackageName(ctx, {});
|
|
11
22
|
const dirPath = this.getDirectoryPath(ctx, { packageName });
|
|
@@ -609,6 +620,14 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
609
620
|
};
|
|
610
621
|
}
|
|
611
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Adjusts an array type for the `arrayType` setting. With `'flux'`, a `List<T>` becomes `Flux<T>`. With `'list'`, or for
|
|
625
|
+
* any type that is not a `List`, the type is returned unchanged.
|
|
626
|
+
* @template T The type of the value to adjust, which is a `kt.Type` or a reference to one.
|
|
627
|
+
* @param ctx The context of the service, which provides `arrayType`.
|
|
628
|
+
* @param type The type to adjust.
|
|
629
|
+
* @returns The adjusted type.
|
|
630
|
+
*/
|
|
612
631
|
export function adjustListType(ctx, type) {
|
|
613
632
|
if (!kt.refs.list.matches(type))
|
|
614
633
|
return type;
|
|
@@ -8,8 +8,30 @@ type Output = KotlinServicesGeneratorOutput;
|
|
|
8
8
|
type Config = KotlinServicesGeneratorConfig;
|
|
9
9
|
type ServiceOutput = KotlinServiceGeneratorOutput;
|
|
10
10
|
type Context = KotlinServicesGeneratorContext;
|
|
11
|
+
/**
|
|
12
|
+
* Generates the Spring MVC controllers of all services. For each service it writes three Kotlin files into
|
|
13
|
+
* `{outputDir}/{packageDir}`, where `{packageDir}` is `packageName` followed by the service's `packageSuffix`,
|
|
14
|
+
* with each `.` replaced by `/`. With the default settings this is `{outputDir}/com/openapi/generated/api`.
|
|
15
|
+
* - `{Service}_Api.kt`: the API interface, with `@RequestMapping` and the path constants in its companion object.
|
|
16
|
+
* - `{Service}_ApiController.kt`: the `@Controller` class that implements the interface and forwards to the delegate.
|
|
17
|
+
* - `{Service}_ApiDelegate.kt`: the delegate interface, with one function per endpoint to override.
|
|
18
|
+
*
|
|
19
|
+
* The names are the service name plus the `_Api`, `_ApiController` or `_ApiDelegate` suffix, converted with
|
|
20
|
+
* `typeNameCasing`. Once per run it also writes `{outputDir}/{basePackageDir}/ApiExceptionHandler.kt`, where the base
|
|
21
|
+
* package is `packageName` followed by the `packageSuffix` for no service. Services named `exclude-from-generation`
|
|
22
|
+
* are removed from `data.services` before generation.
|
|
23
|
+
*
|
|
24
|
+
* Publishes `kotlin.services`, keyed by service id, with `apiInterface`, `apiController` and `apiDelegate`. Each entry
|
|
25
|
+
* is a `KotlinImport` (`typeName` and `packageName`) that later generators use to reference the file.
|
|
26
|
+
* @see DefaultKotlinSpringControllerGenerator
|
|
27
|
+
* @see KotlinServicesGeneratorConfig
|
|
28
|
+
*/
|
|
11
29
|
export declare class KotlinSpringControllersGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
|
|
12
30
|
private readonly _serviceGeneratorFactory;
|
|
31
|
+
/**
|
|
32
|
+
* Initializes a new instance of the KotlinSpringControllersGenerator class.
|
|
33
|
+
* @param serviceGeneratorFactory Creates the generator of each service. Defaults to the default generator.
|
|
34
|
+
*/
|
|
13
35
|
constructor(serviceGeneratorFactory?: Factory<KotlinSpringControllerGenerator, []>);
|
|
14
36
|
protected initResult(): Output;
|
|
15
37
|
protected generateService(ctx: Context, service: ApiService): MaybePromise<ServiceOutput>;
|
|
@@ -4,8 +4,30 @@ import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
|
4
4
|
import { defaultKotlinServicesGeneratorConfig, } from './models.js';
|
|
5
5
|
import { getReferenceFactories } from './refs.js';
|
|
6
6
|
import { DefaultKotlinSpringControllerGenerator, } from './spring-controller-generator.js';
|
|
7
|
+
/**
|
|
8
|
+
* Generates the Spring MVC controllers of all services. For each service it writes three Kotlin files into
|
|
9
|
+
* `{outputDir}/{packageDir}`, where `{packageDir}` is `packageName` followed by the service's `packageSuffix`,
|
|
10
|
+
* with each `.` replaced by `/`. With the default settings this is `{outputDir}/com/openapi/generated/api`.
|
|
11
|
+
* - `{Service}_Api.kt`: the API interface, with `@RequestMapping` and the path constants in its companion object.
|
|
12
|
+
* - `{Service}_ApiController.kt`: the `@Controller` class that implements the interface and forwards to the delegate.
|
|
13
|
+
* - `{Service}_ApiDelegate.kt`: the delegate interface, with one function per endpoint to override.
|
|
14
|
+
*
|
|
15
|
+
* The names are the service name plus the `_Api`, `_ApiController` or `_ApiDelegate` suffix, converted with
|
|
16
|
+
* `typeNameCasing`. Once per run it also writes `{outputDir}/{basePackageDir}/ApiExceptionHandler.kt`, where the base
|
|
17
|
+
* package is `packageName` followed by the `packageSuffix` for no service. Services named `exclude-from-generation`
|
|
18
|
+
* are removed from `data.services` before generation.
|
|
19
|
+
*
|
|
20
|
+
* Publishes `kotlin.services`, keyed by service id, with `apiInterface`, `apiController` and `apiDelegate`. Each entry
|
|
21
|
+
* is a `KotlinImport` (`typeName` and `packageName`) that later generators use to reference the file.
|
|
22
|
+
* @see DefaultKotlinSpringControllerGenerator
|
|
23
|
+
* @see KotlinServicesGeneratorConfig
|
|
24
|
+
*/
|
|
7
25
|
export class KotlinSpringControllersGenerator extends OpenApiServicesGenerationProviderBase {
|
|
8
26
|
_serviceGeneratorFactory;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes a new instance of the KotlinSpringControllersGenerator class.
|
|
29
|
+
* @param serviceGeneratorFactory Creates the generator of each service. Defaults to the default generator.
|
|
30
|
+
*/
|
|
9
31
|
constructor(serviceGeneratorFactory) {
|
|
10
32
|
super();
|
|
11
33
|
this._serviceGeneratorFactory =
|