@goast/kotlin 0.7.0 → 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.
Files changed (132) hide show
  1. package/dist/src/assets.d.ts +17 -0
  2. package/dist/src/assets.js +17 -0
  3. package/dist/src/ast/common.d.ts +4 -0
  4. package/dist/src/ast/node.d.ts +11 -0
  5. package/dist/src/ast/node.js +11 -0
  6. package/dist/src/ast/nodes/annotation.d.ts +44 -0
  7. package/dist/src/ast/nodes/annotation.js +40 -0
  8. package/dist/src/ast/nodes/argument.d.ts +33 -0
  9. package/dist/src/ast/nodes/argument.js +33 -0
  10. package/dist/src/ast/nodes/call.d.ts +42 -0
  11. package/dist/src/ast/nodes/call.js +42 -0
  12. package/dist/src/ast/nodes/class.d.ts +96 -0
  13. package/dist/src/ast/nodes/class.js +90 -0
  14. package/dist/src/ast/nodes/collection-literal.d.ts +35 -0
  15. package/dist/src/ast/nodes/collection-literal.js +35 -0
  16. package/dist/src/ast/nodes/constructor.d.ts +65 -0
  17. package/dist/src/ast/nodes/constructor.js +62 -0
  18. package/dist/src/ast/nodes/doc-tag.d.ts +41 -0
  19. package/dist/src/ast/nodes/doc-tag.js +41 -0
  20. package/dist/src/ast/nodes/doc.d.ts +44 -0
  21. package/dist/src/ast/nodes/doc.js +44 -0
  22. package/dist/src/ast/nodes/enum-value.d.ts +50 -0
  23. package/dist/src/ast/nodes/enum-value.js +47 -0
  24. package/dist/src/ast/nodes/enum.d.ts +67 -0
  25. package/dist/src/ast/nodes/enum.js +64 -0
  26. package/dist/src/ast/nodes/function.d.ts +105 -0
  27. package/dist/src/ast/nodes/function.js +105 -0
  28. package/dist/src/ast/nodes/generic-parameter.d.ts +37 -0
  29. package/dist/src/ast/nodes/generic-parameter.js +37 -0
  30. package/dist/src/ast/nodes/init-block.d.ts +32 -0
  31. package/dist/src/ast/nodes/init-block.js +32 -0
  32. package/dist/src/ast/nodes/interface.d.ts +73 -0
  33. package/dist/src/ast/nodes/interface.js +68 -0
  34. package/dist/src/ast/nodes/lambda-type.d.ts +42 -0
  35. package/dist/src/ast/nodes/lambda-type.js +42 -0
  36. package/dist/src/ast/nodes/lambda.d.ts +41 -0
  37. package/dist/src/ast/nodes/lambda.js +41 -0
  38. package/dist/src/ast/nodes/object.d.ts +66 -0
  39. package/dist/src/ast/nodes/object.js +62 -0
  40. package/dist/src/ast/nodes/parameter.d.ts +68 -0
  41. package/dist/src/ast/nodes/parameter.js +68 -0
  42. package/dist/src/ast/nodes/property.d.ts +152 -0
  43. package/dist/src/ast/nodes/property.js +148 -0
  44. package/dist/src/ast/nodes/reference.d.ts +107 -0
  45. package/dist/src/ast/nodes/reference.js +75 -0
  46. package/dist/src/ast/nodes/string.d.ts +57 -0
  47. package/dist/src/ast/nodes/string.js +57 -0
  48. package/dist/src/ast/nodes/types.d.ts +9 -0
  49. package/dist/src/ast/references/jackson.d.ts +67 -0
  50. package/dist/src/ast/references/jackson.js +59 -0
  51. package/dist/src/ast/references/jakarta.d.ts +13 -0
  52. package/dist/src/ast/references/jakarta.js +13 -0
  53. package/dist/src/ast/references/java.d.ts +19 -0
  54. package/dist/src/ast/references/java.js +19 -0
  55. package/dist/src/ast/references/kotlin.d.ts +28 -0
  56. package/dist/src/ast/references/kotlin.js +28 -0
  57. package/dist/src/ast/references/kotlinx.d.ts +8 -0
  58. package/dist/src/ast/references/kotlinx.js +8 -0
  59. package/dist/src/ast/references/okhttp3.d.ts +8 -0
  60. package/dist/src/ast/references/okhttp3.js +8 -0
  61. package/dist/src/ast/references/reactor.d.ts +8 -0
  62. package/dist/src/ast/references/reactor.js +8 -0
  63. package/dist/src/ast/references/spring-reactive.d.ts +18 -0
  64. package/dist/src/ast/references/spring-reactive.js +18 -0
  65. package/dist/src/ast/references/spring.d.ts +27 -0
  66. package/dist/src/ast/references/spring.js +27 -0
  67. package/dist/src/ast/references/swagger.d.ts +13 -0
  68. package/dist/src/ast/references/swagger.js +13 -0
  69. package/dist/src/ast/utils/get-kotlin-builder-options.d.ts +10 -0
  70. package/dist/src/ast/utils/get-kotlin-builder-options.js +10 -0
  71. package/dist/src/ast/utils/to-kt-node.d.ts +40 -0
  72. package/dist/src/ast/utils/write-kt-annotations.d.ts +13 -0
  73. package/dist/src/ast/utils/write-kt-annotations.js +13 -0
  74. package/dist/src/ast/utils/write-kt-arguments.d.ts +15 -0
  75. package/dist/src/ast/utils/write-kt-arguments.js +15 -0
  76. package/dist/src/ast/utils/write-kt-enum-values.d.ts +13 -0
  77. package/dist/src/ast/utils/write-kt-enum-values.js +13 -0
  78. package/dist/src/ast/utils/write-kt-generic-parameters.d.ts +10 -0
  79. package/dist/src/ast/utils/write-kt-generic-parameters.js +10 -0
  80. package/dist/src/ast/utils/write-kt-members.d.ts +16 -0
  81. package/dist/src/ast/utils/write-kt-members.js +16 -0
  82. package/dist/src/ast/utils/write-kt-node.d.ts +29 -0
  83. package/dist/src/ast/utils/write-kt-node.js +24 -0
  84. package/dist/src/ast/utils/write-kt-parameters.d.ts +13 -0
  85. package/dist/src/ast/utils/write-kt-parameters.js +13 -0
  86. package/dist/src/common-results.d.ts +9 -0
  87. package/dist/src/config.d.ts +72 -0
  88. package/dist/src/config.js +5 -0
  89. package/dist/src/file-builder.d.ts +91 -0
  90. package/dist/src/file-builder.js +81 -0
  91. package/dist/src/generators/file-generator.d.ts +12 -0
  92. package/dist/src/generators/file-generator.js +7 -0
  93. package/dist/src/generators/models/args.d.ts +233 -0
  94. package/dist/src/generators/models/model-generator.d.ts +25 -0
  95. package/dist/src/generators/models/model-generator.js +14 -0
  96. package/dist/src/generators/models/models-generator.d.ts +15 -0
  97. package/dist/src/generators/models/models-generator.js +15 -0
  98. package/dist/src/generators/models/models.d.ts +93 -2
  99. package/dist/src/generators/models/models.js +5 -0
  100. package/dist/src/generators/services/okhttp3-clients/args.d.ts +138 -0
  101. package/dist/src/generators/services/okhttp3-clients/models.d.ts +83 -0
  102. package/dist/src/generators/services/okhttp3-clients/models.js +5 -0
  103. package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +33 -0
  104. package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +20 -0
  105. package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts +21 -0
  106. package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +21 -0
  107. package/dist/src/generators/services/okhttp3-clients/refs.d.ts +25 -0
  108. package/dist/src/generators/services/okhttp3-clients/refs.js +7 -0
  109. package/dist/src/generators/services/spring-controllers/args.d.ts +169 -0
  110. package/dist/src/generators/services/spring-controllers/models.d.ts +120 -0
  111. package/dist/src/generators/services/spring-controllers/models.js +4 -0
  112. package/dist/src/generators/services/spring-controllers/refs.d.ts +9 -0
  113. package/dist/src/generators/services/spring-controllers/refs.js +9 -0
  114. package/dist/src/generators/services/spring-controllers/spring-controller-generator.d.ts +29 -0
  115. package/dist/src/generators/services/spring-controllers/spring-controller-generator.js +19 -0
  116. package/dist/src/generators/services/spring-controllers/spring-controllers-generator.d.ts +22 -0
  117. package/dist/src/generators/services/spring-controllers/spring-controllers-generator.js +22 -0
  118. package/dist/src/generators/services/spring-reactive-web-clients/args.d.ts +224 -0
  119. package/dist/src/generators/services/spring-reactive-web-clients/models.d.ts +86 -0
  120. package/dist/src/generators/services/spring-reactive-web-clients/models.js +4 -0
  121. package/dist/src/generators/services/spring-reactive-web-clients/refs.d.ts +7 -0
  122. package/dist/src/generators/services/spring-reactive-web-clients/refs.js +7 -0
  123. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +36 -0
  124. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +25 -0
  125. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.d.ts +20 -0
  126. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.js +20 -0
  127. package/dist/src/import-collection.d.ts +64 -0
  128. package/dist/src/import-collection.js +46 -0
  129. package/dist/src/types.d.ts +4 -0
  130. package/dist/src/utils.d.ts +52 -0
  131. package/dist/src/utils.js +52 -0
  132. package/package.json +2 -2
@@ -1,86 +1,224 @@
1
1
  import type { ApiEndpoint, ApiParameter, 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 of `getClientFileContent`, which builds the content of a client file. It has no properties, because the
6
+ * generator context provides everything the method needs.
7
+ */
4
8
  export type GetClientFileContent = object;
9
+ /**
10
+ * Arguments of `getClientClass`, which builds the client class with its primary constructor, companion object and
11
+ * members. It has no properties.
12
+ */
5
13
  export type GetClientClass = object;
14
+ /**
15
+ * Arguments of `getClientCompanionObject`, which builds the companion object that holds `defaultBasePath`.
16
+ * It has no properties.
17
+ */
6
18
  export type GetClientCompanionObject = object;
19
+ /**
20
+ * Arguments of `getEndpointClientMembers`, which returns the three members generated for one endpoint: the endpoint
21
+ * method, its `WithHttpInfo` method and its private `RequestConfig` method.
22
+ * @property endpoint The endpoint to generate the members for.
23
+ * @property parameters The method parameters of the endpoint, as returned by `getAllParameters`.
24
+ */
7
25
  export type GetEndpointClientMembers = {
8
26
  endpoint: ApiEndpoint;
9
27
  parameters: ApiParameter[];
10
28
  };
29
+ /**
30
+ * Arguments of `getEndpointClientMethod`, which builds the endpoint method that returns the response data directly.
31
+ */
11
32
  export type GetEndpointClientMethod = {
33
+ /** The endpoint the method is generated for. */
12
34
  endpoint: ApiEndpoint;
35
+ /** The method parameters, with required parameters first, as returned by `getAllParameters`. */
13
36
  parameters: ApiParameter[];
37
+ /** The schema of the 2xx or default response, or `undefined` when that response has no schema. */
14
38
  responseSchema: ApiSchema | undefined;
15
39
  };
40
+ /**
41
+ * Arguments of `getEndpointClientMethodBody`, which builds the body of the endpoint method. The body calls the
42
+ * `WithHttpInfo` method and returns its data, or throws for error responses.
43
+ */
16
44
  export type GetEndpointClientMethodBody = {
45
+ /** The endpoint whose method body is generated. */
17
46
  endpoint: ApiEndpoint;
47
+ /** The parameters to pass on to the `WithHttpInfo` method, in the same order. */
18
48
  parameters: ApiParameter[];
49
+ /** The schema that the successful response data is cast to. `undefined` makes the method return `Unit`. */
19
50
  responseSchema: ApiSchema | undefined;
20
51
  };
52
+ /**
53
+ * Arguments of `getEndpointClientHttpInfoMethod`, which builds the `{name}WithHttpInfo` method. Unlike the endpoint
54
+ * method, it returns the whole `ApiResponse`, not only its data.
55
+ */
21
56
  export type GetEndpointClientHttpInfoMethod = {
57
+ /** The endpoint the method is generated for. */
22
58
  endpoint: ApiEndpoint;
59
+ /** The method parameters, which keep their names and types in the generated method. */
23
60
  parameters: ApiParameter[];
61
+ /**
62
+ * The schema of the response data. The data type of the generated return type is always nullable, and `undefined`
63
+ * falls back to `Unit?`.
64
+ */
24
65
  responseSchema: ApiSchema | undefined;
25
66
  };
67
+ /**
68
+ * Arguments of `getEndpointClientHttpInfoMethodBody`, which builds the body of the `WithHttpInfo` method. The body
69
+ * creates the request config with the `RequestConfig` method and sends it with `request`.
70
+ */
26
71
  export type GetEndpointClientHttpInfoMethodBody = {
72
+ /** The endpoint whose request is sent. */
27
73
  endpoint: ApiEndpoint;
74
+ /** The parameters to forward to the private `RequestConfig` method. */
28
75
  parameters: ApiParameter[];
76
+ /** The schema used as the response type argument of `request`. `undefined` uses `Unit`. */
29
77
  responseSchema: ApiSchema | undefined;
30
78
  };
79
+ /**
80
+ * Arguments of `getEndpointClientRequestConfigMethod`, which builds the private `{name}RequestConfig` method. That
81
+ * method returns the `RequestConfig` for one call of the endpoint.
82
+ */
31
83
  export type GetEndpointClientRequestConfigMethod = {
84
+ /** The endpoint the request config is built for. */
32
85
  endpoint: ApiEndpoint;
86
+ /** The method parameters, including the path parameters that the request path interpolates. */
33
87
  parameters: ApiParameter[];
34
88
  };
89
+ /**
90
+ * Arguments of `getEndpointClientRequestConfigMethodBody`, which builds the body of the `RequestConfig` method. It
91
+ * collects the query, header and body values, and sets the HTTP method and the interpolated path.
92
+ */
35
93
  export type GetEndpointClientRequestConfigMethodBody = {
94
+ /** The endpoint whose HTTP method and path the request config uses. */
36
95
  endpoint: ApiEndpoint;
96
+ /** The parameters whose values are written to the query, header or body. Multipart fields carry `multipart` info. */
37
97
  parameters: ApiParameterWithMultipartInfo[];
38
98
  };
99
+ /**
100
+ * Arguments of `getParameterToString`, which returns the expression that converts a parameter value into a string.
101
+ */
39
102
  export type GetParameterToString = {
103
+ /** The endpoint that declares the parameter. */
40
104
  endpoint: ApiEndpoint;
105
+ /**
106
+ * The parameter whose value is converted. String enums use `.value`, arrays are joined with `,`, and other values
107
+ * use `.toString()`.
108
+ */
41
109
  parameter: ApiParameter;
42
110
  };
111
+ /**
112
+ * Arguments of `getAdditionalClientMembers`, which returns extra members added to every client class, such as the
113
+ * private `encodeURIComponent` helper. It has no properties.
114
+ */
43
115
  export type GetAdditionalClientMembers = object;
116
+ /**
117
+ * Arguments of `getParameterType`, which returns the Kotlin type of a method parameter.
118
+ * @property endpoint The endpoint that declares the parameter.
119
+ * @property parameter The parameter to type. A file part of a multipart request becomes `java.io.File`.
120
+ */
44
121
  export type GetParameterType = {
45
122
  endpoint: ApiEndpoint;
46
123
  parameter: ApiParameterWithMultipartInfo;
47
124
  };
125
+ /**
126
+ * Arguments of `getRequestBodyType`, which returns the Kotlin type of the request body. A `multipart/form-data` body
127
+ * becomes a map of part configs.
128
+ * @property endpoint The endpoint whose request body type is returned.
129
+ */
48
130
  export type GetRequestBodyType = {
49
131
  endpoint: ApiEndpoint;
50
132
  };
133
+ /**
134
+ * Arguments of `getParameterDefaultValue`, which returns the default value expression of a parameter.
135
+ */
51
136
  export type GetParameterDefaultValue = {
137
+ /** The endpoint that declares the parameter. */
52
138
  endpoint: ApiEndpoint;
139
+ /** The parameter whose default value is returned. Required parameters have no default value. */
53
140
  parameter: ApiParameter;
54
141
  };
142
+ /**
143
+ * Arguments of `getTypeUsage`, which returns the Kotlin type used for a schema.
144
+ * @template TBuilder The type of the source builder the type is written to.
145
+ */
55
146
  export type GetTypeUsage<TBuilder extends SourceBuilder> = {
147
+ /** The schema to map to a Kotlin type. `undefined` uses `fallback`. */
56
148
  schema: ApiSchema | undefined;
149
+ /** Whether the type is nullable. When omitted, the nullability of the mapped type is kept. */
57
150
  nullable?: boolean;
151
+ /** The type to use when no type is mapped. Defaults to `Any`, nullable when `nullable` is set. */
58
152
  fallback?: kt.Type<TBuilder>;
59
153
  };
154
+ /**
155
+ * Arguments of `getPackageName`, which returns the package of the client class. It has no properties.
156
+ */
60
157
  export type GetPackageName = object;
158
+ /**
159
+ * Arguments of `getPathWithInterpolation`, which returns the endpoint path with each path parameter replaced by an
160
+ * `encodeURIComponent` template expression.
161
+ * @property endpoint The endpoint whose path is interpolated.
162
+ */
61
163
  export type GetPathWithInterpolation = {
62
164
  endpoint: ApiEndpoint;
63
165
  };
166
+ /**
167
+ * Arguments of `getResponseSchema`, which returns the schema of the successful response.
168
+ * @property endpoint The endpoint whose response schema is looked up. The first 2xx or default response is used.
169
+ */
64
170
  export type GetResponseSchema = {
65
171
  endpoint: ApiEndpoint;
66
172
  };
173
+ /**
174
+ * Arguments of `getSchemaType`, which returns the Kotlin type reference of a schema.
175
+ * @property schema The schema to look up in the models output. `undefined` yields `undefined`.
176
+ */
67
177
  export type GetSchemaType = {
68
178
  schema: ApiSchema | undefined;
69
179
  };
180
+ /**
181
+ * Arguments of `getAllParameters`, which returns the method parameters of an endpoint.
182
+ * @property endpoint The endpoint whose query, path and header parameters and request body are returned.
183
+ */
70
184
  export type GetAllParameters = {
71
185
  endpoint: ApiEndpoint;
72
186
  };
187
+ /**
188
+ * Arguments of `getRequestBodyParamName`, which returns the name of the request body parameter.
189
+ * @property endpoint The endpoint whose request body parameter is named.
190
+ */
73
191
  export type GetRequestBodyParamName = {
74
192
  endpoint: ApiEndpoint;
75
193
  };
194
+ /**
195
+ * Arguments of `getEndpointDocDescription`, which returns the doc text of an endpoint method.
196
+ * @property endpoint The endpoint whose description is used. The source path is appended when `includeSourceInDocs`
197
+ * is set.
198
+ */
76
199
  export type GetEndpointDocDescription = {
77
200
  endpoint: ApiEndpoint;
78
201
  };
202
+ /**
203
+ * Arguments of `getBasePath`, which returns the base path of a client. It has no properties, because the service is
204
+ * read from the generator context.
205
+ */
79
206
  export type GetBasePath = object;
207
+ /**
208
+ * Arguments of `getEndpointPath`, which returns an endpoint path after `pathModifier` is applied.
209
+ * @property endpoint The endpoint whose path is modified.
210
+ */
80
211
  export type GetEndpointPath = {
81
212
  endpoint: ApiEndpoint;
82
213
  };
214
+ /**
215
+ * Arguments of `getFilePath`, which returns the output file path of a client class.
216
+ * @property packageName The package of the client class, which becomes the directory below `outputDir`.
217
+ */
83
218
  export type GetFilePath = {
84
219
  packageName: string;
85
220
  };
221
+ /**
222
+ * Arguments of `getApiClientName`, which returns the class name of a client. It has no properties.
223
+ */
86
224
  export type GetApiClientName = object;
@@ -4,15 +4,70 @@ import { type KotlinGeneratorConfig } from '../../../config.ts';
4
4
  import type { KotlinFileBuilder } from '../../../file-builder.ts';
5
5
  import type { KotlinModelsGeneratorOutput } from '../../models/index.ts';
6
6
  import type { getReferenceFactories } from './refs.ts';
7
+ /**
8
+ * The configuration of the `KotlinOkHttp3ClientsGenerator`. It extends the common Kotlin generator configuration with
9
+ * the client-specific options declared below.
10
+ *
11
+ * Of the common options, `typeNameCasing` names the client classes, `functionNameCasing` names the endpoint methods,
12
+ * `parameterNameCasing` names their parameters, `includeSourceInDocs` adds the source path to the endpoint docs, and
13
+ * `springBootVersion` selects the Jackson packages in the infrastructure files.
14
+ * @see defaultKotlinOkHttp3ClientsGeneratorConfig
15
+ */
7
16
  export type KotlinOkHttp3ClientsGeneratorConfig = KotlinGeneratorConfig & {
17
+ /**
18
+ * The base package name for the generated client classes.
19
+ * Each client file is placed in `{outputDir}/{packagePath}`, where `packagePath` is `packageName` followed by
20
+ * `packageSuffix`, with the dots replaced by slashes. The same package is written as the `package` declaration.
21
+ * @default 'com.openapi.generated'
22
+ */
8
23
  packageName: string;
24
+ /**
25
+ * The suffix appended to `packageName` for the generated client classes. Include the leading `.`, because the suffix
26
+ * is appended as written. A function receives the service and returns the suffix for it, so each service can be
27
+ * placed in its own package. The infrastructure package also uses the suffix when `infrastructurePackageName` is in
28
+ * `append-full-package-name` mode, and then the function is called without a service.
29
+ * @default '.api.client'
30
+ */
9
31
  packageSuffix: string | ((service?: ApiService) => string);
32
+ /**
33
+ * The package of the shared infrastructure files, such as `ApiClient`, `ApiResponse` and `Serializer`. The files are
34
+ * written to `{outputDir}/{infrastructurePackagePath}`, and the client classes refer to their types by this package.
35
+ * - A string is used as the package name as written.
36
+ * - `{ mode: 'append-package-name', value }` appends `value` to `packageName`.
37
+ * - `{ mode: 'append-full-package-name', value }` appends `value` to `packageName` followed by `packageSuffix`.
38
+ * - `{ mode: 'replace', value }` uses `value` as written.
39
+ * @default { mode: 'append-full-package-name', value: '.infrastructure' }
40
+ */
10
41
  infrastructurePackageName: string | {
11
42
  mode: 'append-package-name' | 'append-full-package-name' | 'replace';
12
43
  value: string;
13
44
  };
45
+ /**
46
+ * The base path that the generated clients use as the prefix of every request URL. It is the fallback of the
47
+ * `defaultBasePath` property in each client's companion object, which the system property named by
48
+ * `ApiClient.baseUrlKey` overrides at runtime.
49
+ * - A string replaces the base path as written.
50
+ * - A RegExp replaces the base path with the text it matches, and keeps the base path when nothing matches.
51
+ * - A function receives the base path and the service, and returns the new base path.
52
+ * @default The URL of the first server in the source OpenAPI document, or `'/'` when it defines none.
53
+ */
14
54
  basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
55
+ /**
56
+ * Changes the path of each endpoint before its request URL is built. The `{name}` placeholders of path parameters
57
+ * must remain in the modified path, because the path parameters are substituted into them afterwards.
58
+ * - A string replaces the path as written.
59
+ * - A RegExp replaces the path with the text it matches, and keeps the path when nothing matches.
60
+ * - A function receives the path and the endpoint, and returns the new path.
61
+ * @default undefined, so the endpoint path is used as written.
62
+ */
15
63
  pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
64
+ /**
65
+ * The Jackson inclusion rule of the default `Serializer` object, which decides which null or empty values are left
66
+ * out of the serialized JSON. The value becomes a `JsonInclude.Include` constant in upper snake case, so
67
+ * `non-absent` becomes `NON_ABSENT`. It only applies to the default factory of a `'static'` serializer. It has no
68
+ * effect when `serializer` is `'parameter'`, or when it provides its own factory.
69
+ * @default 'non-absent'
70
+ */
16
71
  serializerJsonInclude: 'always' | 'non-null' | 'non-absent' | 'non-default' | 'non-empty' | 'use-defaults';
17
72
  /**
18
73
  * Determines how the serializer is provided to the client.
@@ -26,20 +81,48 @@ export type KotlinOkHttp3ClientsGeneratorConfig = KotlinGeneratorConfig & {
26
81
  factory: AppendValue<KotlinFileBuilder>;
27
82
  };
28
83
  };
84
+ /**
85
+ * The default configuration of the `KotlinOkHttp3ClientsGenerator`. It is merged with the common Kotlin defaults from
86
+ * `defaultKotlinGeneratorConfig`, and the options passed to the generator are merged on top of these.
87
+ * @see KotlinOkHttp3ClientsGeneratorConfig
88
+ */
29
89
  export declare const defaultKotlinOkHttp3ClientsGeneratorConfig: DefaultGenerationProviderConfig<KotlinOkHttp3ClientsGeneratorConfig>;
90
+ /**
91
+ * The input of the `KotlinOkHttp3ClientsGenerator`, which is the output of the `KotlinModelsGenerator`. The client
92
+ * methods use the model types it publishes under `kotlin.models` for their parameter and response types.
93
+ */
30
94
  export type KotlinOkHttp3ClientsGeneratorInput = KotlinModelsGeneratorOutput;
95
+ /**
96
+ * The output of the `KotlinOkHttp3ClientsGenerator`. Later generators read the generated clients from `kotlin.clients`.
97
+ */
31
98
  export type KotlinOkHttp3ClientsGeneratorOutput = {
99
+ /** The Kotlin results of the generator. */
32
100
  kotlin: {
101
+ /** The generated client classes, keyed by service id. Each entry holds the type name and package of its client. */
33
102
  clients: {
34
103
  [serviceId: string]: KotlinOkHttp3ClientGeneratorOutput;
35
104
  };
36
105
  };
37
106
  };
107
+ /**
108
+ * The result of generating the client for one service: the name and package of the generated client class. It is the
109
+ * entry stored under `kotlin.clients[serviceId]`.
110
+ */
38
111
  export type KotlinOkHttp3ClientGeneratorOutput = KotlinImport;
112
+ /**
113
+ * The context of the `KotlinOkHttp3ClientsGenerator`. It extends the services generation context with the resolved
114
+ * infrastructure package name and the reference factories for the infrastructure types.
115
+ */
39
116
  export type KotlinOkHttp3ClientsGeneratorContext = OpenApiServicesGenerationProviderContext<KotlinOkHttp3ClientsGeneratorInput, KotlinOkHttp3ClientsGeneratorOutput, KotlinOkHttp3ClientsGeneratorConfig, KotlinOkHttp3ClientGeneratorOutput> & {
117
+ /** The package of the shared infrastructure files, resolved from `infrastructurePackageName`. */
40
118
  infrastructurePackageName: string;
119
+ /** The reference factories for the types in the infrastructure package, from `getReferenceFactories`. */
41
120
  refs: ReturnType<typeof getReferenceFactories>;
42
121
  };
122
+ /**
123
+ * The context of the `DefaultKotlinOkHttp3Generator` for one service. It extends the clients context with the service.
124
+ */
43
125
  export type KotlinOkHttp3ClientGeneratorContext = KotlinOkHttp3ClientsGeneratorContext & {
126
+ /** The service to generate the client class for, with its endpoints. */
44
127
  service: ApiService;
45
128
  };
@@ -1,4 +1,9 @@
1
1
  import { defaultKotlinGeneratorConfig } from '../../../config.js';
2
+ /**
3
+ * The default configuration of the `KotlinOkHttp3ClientsGenerator`. It is merged with the common Kotlin defaults from
4
+ * `defaultKotlinGeneratorConfig`, and the options passed to the generator are merged on top of these.
5
+ * @see KotlinOkHttp3ClientsGeneratorConfig
6
+ */
2
7
  export const defaultKotlinOkHttp3ClientsGeneratorConfig = {
3
8
  ...defaultKotlinGeneratorConfig,
4
9
  packageName: 'com.openapi.generated',
@@ -8,10 +8,43 @@ import type { KotlinOkHttp3ClientGeneratorContext, KotlinOkHttp3ClientGeneratorO
8
8
  type Context = KotlinOkHttp3ClientGeneratorContext;
9
9
  type Output = KotlinOkHttp3ClientGeneratorOutput;
10
10
  type Builder = KotlinFileBuilder;
11
+ /**
12
+ * Generates the API client class of one service. Implement this interface to replace the default client generation,
13
+ * and pass the implementation to the `KotlinOkHttp3ClientsGenerator` constructor.
14
+ *
15
+ * @template TOutput The type of the result that the generation returns.
16
+ * @see DefaultKotlinOkHttp3Generator
17
+ */
11
18
  export interface KotlinOkHttp3Generator<TOutput extends Output = Output> {
19
+ /**
20
+ * Generates the client class for the service in `ctx.service`.
21
+ *
22
+ * @param ctx The context of the service, with its endpoints, the generator configuration and the reference factories.
23
+ * @returns The name and package of the generated client class.
24
+ */
12
25
  generate(ctx: Context): MaybePromise<TOutput>;
13
26
  }
27
+ /**
28
+ * The default generator of a service's API client. It writes one Kotlin class to
29
+ * `{outputDir}/{packagePath}/{ClientName}.kt`, where `packagePath` is `packageName` followed by `packageSuffix`,
30
+ * with the dots replaced by slashes, and `ClientName` is the service name in `typeNameCasing` followed by `ApiClient`.
31
+ * With the default configuration, the service `pet` is written to
32
+ * `{outputDir}/com/openapi/generated/api/client/PetApiClient.kt`.
33
+ *
34
+ * The generated class extends `ApiClient`. For each endpoint it has the endpoint method, a `{name}WithHttpInfo`
35
+ * method that returns the whole `ApiResponse`, and a private `{name}RequestConfig` method that builds the request.
36
+ * It returns
37
+ * `{ typeName, packageName }`, which `KotlinOkHttp3ClientsGenerator` publishes under `kotlin.clients[serviceId]`.
38
+ *
39
+ * @see KotlinOkHttp3ClientsGenerator
40
+ */
14
41
  export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context, Output> implements KotlinOkHttp3Generator {
42
+ /**
43
+ * Generates the client class file for the service in `ctx.service` and writes it to disk.
44
+ *
45
+ * @param ctx The context of the service to generate the client for.
46
+ * @returns The `typeName` and `packageName` of the generated client class.
47
+ */
15
48
  generate(ctx: KotlinOkHttp3ClientGeneratorContext): MaybePromise<Output>;
16
49
  protected getClientFileContent(ctx: Context, _args: Args.GetClientFileContent): AppendValueGroup<Builder>;
17
50
  /**
@@ -3,7 +3,27 @@ import { kt } from '../../../ast/index.js';
3
3
  import { KotlinFileBuilder } from '../../../file-builder.js';
4
4
  import { getArrayItemStringEnumSchema, getSourceDocLine, getStringEnumSchema, modifyString } from '../../../utils.js';
5
5
  import { KotlinFileGenerator } from '../../file-generator.js';
6
+ /**
7
+ * The default generator of a service's API client. It writes one Kotlin class to
8
+ * `{outputDir}/{packagePath}/{ClientName}.kt`, where `packagePath` is `packageName` followed by `packageSuffix`,
9
+ * with the dots replaced by slashes, and `ClientName` is the service name in `typeNameCasing` followed by `ApiClient`.
10
+ * With the default configuration, the service `pet` is written to
11
+ * `{outputDir}/com/openapi/generated/api/client/PetApiClient.kt`.
12
+ *
13
+ * The generated class extends `ApiClient`. For each endpoint it has the endpoint method, a `{name}WithHttpInfo`
14
+ * method that returns the whole `ApiResponse`, and a private `{name}RequestConfig` method that builds the request.
15
+ * It returns
16
+ * `{ typeName, packageName }`, which `KotlinOkHttp3ClientsGenerator` publishes under `kotlin.clients[serviceId]`.
17
+ *
18
+ * @see KotlinOkHttp3ClientsGenerator
19
+ */
6
20
  export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator {
21
+ /**
22
+ * Generates the client class file for the service in `ctx.service` and writes it to disk.
23
+ *
24
+ * @param ctx The context of the service to generate the client for.
25
+ * @returns The `typeName` and `packageName` of the generated client class.
26
+ */
7
27
  generate(ctx) {
8
28
  const typeName = this.getApiClientName(ctx, {});
9
29
  const packageName = this.getPackageName(ctx, {});
@@ -7,8 +7,29 @@ type Output = KotlinOkHttp3ClientsGeneratorOutput;
7
7
  type Config = KotlinOkHttp3ClientsGeneratorConfig;
8
8
  type ServiceOutput = KotlinOkHttp3ClientGeneratorOutput;
9
9
  type Context = KotlinOkHttp3ClientsGeneratorContext;
10
+ /**
11
+ * Generates the OkHttp3 client infrastructure and one API client class per service.
12
+ *
13
+ * These files are written to `{outputDir}/{infrastructurePackagePath}/`, where `infrastructurePackagePath` is
14
+ * `infrastructurePackageName` with the dots replaced by slashes:
15
+ * - `ApiAbstractions.kt`, `ApiClient.kt`, `ApiResponse.kt`, `Errors.kt`, `PartConfig.kt`, `RequestConfig.kt`,
16
+ * `RequestMethod.kt` and `ResponseExtensions.kt`, copied from the bundled `client/okhttp3` assets with the package
17
+ * name filled in. With `springBootVersion: 4`, their Jackson imports are rewritten to `tools.jackson`.
18
+ * - `Serializer.kt`, only when `serializer` is `'static'` or an object with `mode: 'static'`.
19
+ *
20
+ * Each service is generated by a `KotlinOkHttp3Generator`, which writes its client class to
21
+ * `{outputDir}/{packagePath}/{ClientName}.kt`. Services named `exclude-from-generation` are skipped. The result of each
22
+ * service is published under `kotlin.clients[serviceId]` as `{ typeName, packageName }`.
23
+ *
24
+ * @see DefaultKotlinOkHttp3Generator
25
+ */
10
26
  export declare class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
11
27
  private readonly _serviceGeneratorFactory;
28
+ /**
29
+ * Creates the generator.
30
+ *
31
+ * @param serviceGeneratorFactory Creates the generator for each service. Defaults to the default generator.
32
+ */
12
33
  constructor(serviceGeneratorFactory?: Factory<KotlinOkHttp3Generator, []>);
13
34
  protected generateAdditionalFiles(ctx: KotlinOkHttp3ClientsGeneratorContext): Promise<void>;
14
35
  protected initResult(): Output;
@@ -6,8 +6,29 @@ import { KotlinFileBuilder } from '../../../file-builder.js';
6
6
  import { defaultKotlinOkHttp3ClientsGeneratorConfig, } from './models.js';
7
7
  import { DefaultKotlinOkHttp3Generator } from './okhttp3-client-generator.js';
8
8
  import { getReferenceFactories } from './refs.js';
9
+ /**
10
+ * Generates the OkHttp3 client infrastructure and one API client class per service.
11
+ *
12
+ * These files are written to `{outputDir}/{infrastructurePackagePath}/`, where `infrastructurePackagePath` is
13
+ * `infrastructurePackageName` with the dots replaced by slashes:
14
+ * - `ApiAbstractions.kt`, `ApiClient.kt`, `ApiResponse.kt`, `Errors.kt`, `PartConfig.kt`, `RequestConfig.kt`,
15
+ * `RequestMethod.kt` and `ResponseExtensions.kt`, copied from the bundled `client/okhttp3` assets with the package
16
+ * name filled in. With `springBootVersion: 4`, their Jackson imports are rewritten to `tools.jackson`.
17
+ * - `Serializer.kt`, only when `serializer` is `'static'` or an object with `mode: 'static'`.
18
+ *
19
+ * Each service is generated by a `KotlinOkHttp3Generator`, which writes its client class to
20
+ * `{outputDir}/{packagePath}/{ClientName}.kt`. Services named `exclude-from-generation` are skipped. The result of each
21
+ * service is published under `kotlin.clients[serviceId]` as `{ typeName, packageName }`.
22
+ *
23
+ * @see DefaultKotlinOkHttp3Generator
24
+ */
9
25
  export class KotlinOkHttp3ClientsGenerator extends OpenApiServicesGenerationProviderBase {
10
26
  _serviceGeneratorFactory;
27
+ /**
28
+ * Creates the generator.
29
+ *
30
+ * @param serviceGeneratorFactory Creates the generator for each service. Defaults to the default generator.
31
+ */
11
32
  constructor(serviceGeneratorFactory) {
12
33
  super();
13
34
  this._serviceGeneratorFactory = serviceGeneratorFactory ?? Factory.fromValue(new DefaultKotlinOkHttp3Generator());
@@ -1,21 +1,46 @@
1
1
  import { kt } from '../../../ast/index.ts';
2
+ /**
3
+ * Creates the reference factories for the types of the OkHttp3 client infrastructure. Each factory writes a reference
4
+ * to a type in the infrastructure package, so the generated clients import the types from there.
5
+ *
6
+ * @param infrastructurePackageName The package that the infrastructure files are written to.
7
+ * @returns The reference factories, keyed by the name of the type they refer to.
8
+ */
2
9
  export declare function getReferenceFactories(infrastructurePackageName: string): {
10
+ /** The `MultiValueMap` type alias for query and header values. Declared in `ApiAbstractions.kt`. */
3
11
  multiValueMap: kt.ReferenceFactory;
12
+ /** The `collectionDelimiter` function, which returns the separator of a collection format. `ApiAbstractions.kt`. */
4
13
  collectionDelimiter: kt.ReferenceFactory;
14
+ /** The `defaultMultiValueConverter` value, which converts an item to a string. Declared in `ApiAbstractions.kt`. */
5
15
  defaultMultiValueConverter: kt.ReferenceFactory;
16
+ /** The `toMultiValueMap` function. The generator does not use it, and no bundled asset declares it. */
6
17
  toMultiValueMap: kt.GenericReferenceFactory<1>;
18
+ /** The `ApiClient` base class that every generated client extends. Declared in `ApiClient.kt`. */
7
19
  apiClient: kt.ReferenceFactory;
20
+ /** The `ResponseType` enum that tells the response kinds apart. Declared in `ApiResponse.kt`. */
8
21
  responseType: kt.ReferenceFactory;
22
+ /** The generic `ApiResponse<T>` base class of every response. Declared in `ApiResponse.kt`. */
9
23
  apiResponse: kt.GenericReferenceFactory<1>;
24
+ /** The generic `Success<T>` response, which holds the response data. Declared in `ApiResponse.kt`. */
10
25
  success: kt.GenericReferenceFactory<1>;
26
+ /** The generic `Informational<T>` response. Declared in `ApiResponse.kt`. */
11
27
  informational: kt.GenericReferenceFactory<1>;
28
+ /** The generic `Redirection<T>` response. Declared in `ApiResponse.kt`. */
12
29
  redirection: kt.GenericReferenceFactory<1>;
30
+ /** The generic `ClientError<T>` response for 4xx status codes. Declared in `ApiResponse.kt`. */
13
31
  clientError: kt.GenericReferenceFactory<1>;
32
+ /** The generic `ServerError<T>` response for 5xx status codes. Declared in `ApiResponse.kt`. */
14
33
  serverError: kt.GenericReferenceFactory<1>;
34
+ /** The `ClientException` thrown for client error responses. Declared in `Errors.kt`. */
15
35
  clientException: kt.ReferenceFactory;
36
+ /** The `ServerException` thrown for server error responses. Declared in `Errors.kt`. */
16
37
  serverException: kt.ReferenceFactory;
38
+ /** The generic `PartConfig<T>` of one part of a multipart request. Declared in `PartConfig.kt`. */
17
39
  partConfig: kt.GenericReferenceFactory<1>;
40
+ /** The generic `RequestConfig<T>` that describes one request. Declared in `RequestConfig.kt`. */
18
41
  requestConfig: kt.GenericReferenceFactory<1>;
42
+ /** The `RequestMethod` enum of HTTP methods. Declared in `RequestMethod.kt`. */
19
43
  requestMethod: kt.ReferenceFactory;
44
+ /** The `Serializer` object with the default object mapper. It is generated only for a `'static'` serializer. */
20
45
  serializer: kt.ReferenceFactory;
21
46
  };
@@ -1,5 +1,12 @@
1
1
  import { kt } from '../../../ast/index.js';
2
2
  // See packages/kotlin/assets/client/okhttp3 for reference
3
+ /**
4
+ * Creates the reference factories for the types of the OkHttp3 client infrastructure. Each factory writes a reference
5
+ * to a type in the infrastructure package, so the generated clients import the types from there.
6
+ *
7
+ * @param infrastructurePackageName The package that the infrastructure files are written to.
8
+ * @returns The reference factories, keyed by the name of the type they refer to.
9
+ */
3
10
  export function getReferenceFactories(infrastructurePackageName) {
4
11
  return {
5
12
  // ApiAbstractions.kt