@goast/kotlin 0.6.0-beta.1 → 0.6.0-beta.2
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/LICENSE +21 -21
- package/README.md +45 -45
- package/assets/client/okhttp3/ApiAbstractions.kt +30 -30
- package/assets/client/okhttp3/ApiClient.kt +252 -252
- package/assets/client/okhttp3/ApiResponse.kt +43 -43
- package/assets/client/okhttp3/Errors.kt +21 -21
- package/assets/client/okhttp3/PartConfig.kt +11 -11
- package/assets/client/okhttp3/RequestConfig.kt +18 -18
- package/assets/client/okhttp3/RequestMethod.kt +8 -8
- package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
- package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
- package/esm/src/ast/references/jackson.d.ts +8 -0
- package/esm/src/ast/references/jackson.d.ts.map +1 -1
- package/esm/src/ast/references/jackson.js +8 -0
- package/esm/src/generators/file-generator.d.ts +21 -1
- package/esm/src/generators/file-generator.d.ts.map +1 -1
- package/esm/src/generators/file-generator.js +41 -2
- package/esm/src/generators/models/args.d.ts +5 -0
- package/esm/src/generators/models/args.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.d.ts +23 -0
- package/esm/src/generators/models/model-generator.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.js +130 -13
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +9 -0
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +59 -41
- package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
- package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +11 -9
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +53 -35
- package/esm/src/generators/services/spring-reactive-web-clients/args.d.ts +3 -0
- package/esm/src/generators/services/spring-reactive-web-clients/args.d.ts.map +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +7 -0
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +41 -20
- package/esm/src/import-collection.d.ts.map +1 -1
- package/esm/src/import-collection.js +2 -2
- package/esm/src/utils.d.ts +3 -1
- package/esm/src/utils.d.ts.map +1 -1
- package/esm/src/utils.js +7 -0
- package/package.json +2 -2
- package/script/src/ast/references/jackson.d.ts +8 -0
- package/script/src/ast/references/jackson.d.ts.map +1 -1
- package/script/src/ast/references/jackson.js +9 -1
- package/script/src/generators/file-generator.d.ts +21 -1
- package/script/src/generators/file-generator.d.ts.map +1 -1
- package/script/src/generators/file-generator.js +41 -2
- package/script/src/generators/models/args.d.ts +5 -0
- package/script/src/generators/models/args.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.d.ts +23 -0
- package/script/src/generators/models/model-generator.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.js +129 -12
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +9 -0
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +58 -40
- package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +11 -9
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.js +52 -34
- package/script/src/generators/services/spring-reactive-web-clients/args.d.ts +3 -0
- package/script/src/generators/services/spring-reactive-web-clients/args.d.ts.map +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +7 -0
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +40 -19
- package/script/src/import-collection.d.ts.map +1 -1
- package/script/src/import-collection.js +1 -1
- package/script/src/utils.d.ts +3 -1
- package/script/src/utils.d.ts.map +1 -1
- package/script/src/utils.js +9 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
package @PACKAGE_NAME@
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Defines a config object for a given request.
|
|
5
|
-
* NOTE: This object doesn't include 'body' because it
|
|
6
|
-
* allows for caching of the constructed object
|
|
7
|
-
* for many request definitions.
|
|
8
|
-
* NOTE: Headers is a Map<String,String> because rfc2616 defines
|
|
9
|
-
* multi-valued headers as csv-only.
|
|
10
|
-
*/
|
|
11
|
-
data class RequestConfig<T>(
|
|
12
|
-
val method: RequestMethod,
|
|
13
|
-
val path: String,
|
|
14
|
-
val headers: MutableMap<String, String> = mutableMapOf(),
|
|
15
|
-
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
|
16
|
-
val requiresAuthentication: Boolean,
|
|
17
|
-
val body: T? = null
|
|
18
|
-
)
|
|
1
|
+
package @PACKAGE_NAME@
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines a config object for a given request.
|
|
5
|
+
* NOTE: This object doesn't include 'body' because it
|
|
6
|
+
* allows for caching of the constructed object
|
|
7
|
+
* for many request definitions.
|
|
8
|
+
* NOTE: Headers is a Map<String,String> because rfc2616 defines
|
|
9
|
+
* multi-valued headers as csv-only.
|
|
10
|
+
*/
|
|
11
|
+
data class RequestConfig<T>(
|
|
12
|
+
val method: RequestMethod,
|
|
13
|
+
val path: String,
|
|
14
|
+
val headers: MutableMap<String, String> = mutableMapOf(),
|
|
15
|
+
val query: MutableMap<String, List<String>> = mutableMapOf(),
|
|
16
|
+
val requiresAuthentication: Boolean,
|
|
17
|
+
val body: T? = null
|
|
18
|
+
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
package @PACKAGE_NAME@
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Provides enumerated HTTP verbs
|
|
5
|
-
*/
|
|
6
|
-
enum class RequestMethod {
|
|
7
|
-
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
|
8
|
-
}
|
|
1
|
+
package @PACKAGE_NAME@
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provides enumerated HTTP verbs
|
|
5
|
+
*/
|
|
6
|
+
enum class RequestMethod {
|
|
7
|
+
GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT
|
|
8
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
package @PACKAGE_NAME@
|
|
2
|
-
|
|
3
|
-
import okhttp3.Response
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Provides an extension to evaluation whether the response is a 1xx code
|
|
7
|
-
*/
|
|
8
|
-
val Response.isInformational: Boolean get() = this.code in 100..199
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Provides an extension to evaluation whether the response is a 3xx code
|
|
12
|
-
*/
|
|
13
|
-
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
|
14
|
-
val Response.isRedirect: Boolean get() = this.code in 300..399
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Provides an extension to evaluation whether the response is a 4xx code
|
|
18
|
-
*/
|
|
19
|
-
val Response.isClientError: Boolean get() = this.code in 400..499
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
|
23
|
-
*/
|
|
24
|
-
val Response.isServerError: Boolean get() = this.code in 500..999
|
|
1
|
+
package @PACKAGE_NAME@
|
|
2
|
+
|
|
3
|
+
import okhttp3.Response
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides an extension to evaluation whether the response is a 1xx code
|
|
7
|
+
*/
|
|
8
|
+
val Response.isInformational: Boolean get() = this.code in 100..199
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides an extension to evaluation whether the response is a 3xx code
|
|
12
|
+
*/
|
|
13
|
+
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
|
14
|
+
val Response.isRedirect: Boolean get() = this.code in 300..399
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Provides an extension to evaluation whether the response is a 4xx code
|
|
18
|
+
*/
|
|
19
|
+
val Response.isClientError: Boolean get() = this.code in 400..499
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code
|
|
23
|
+
*/
|
|
24
|
+
val Response.isServerError: Boolean get() = this.code in 500..999
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
package @PACKAGE_NAME@
|
|
2
|
-
|
|
3
|
-
import org.springframework.core.io.buffer.DataBuffer
|
|
4
|
-
import org.springframework.http.MediaType
|
|
5
|
-
import org.springframework.http.client.MultipartBodyBuilder
|
|
6
|
-
import org.springframework.http.codec.multipart.FilePart
|
|
7
|
-
import java.io.File
|
|
8
|
-
|
|
9
|
-
interface ApiRequestFile {
|
|
10
|
-
companion object {
|
|
11
|
-
fun from(file: File): ApiRequestFile =
|
|
12
|
-
object : ApiRequestFile {
|
|
13
|
-
override fun addToBuilder(builder: MultipartBodyBuilder) {
|
|
14
|
-
builder
|
|
15
|
-
.part("file", file)
|
|
16
|
-
.filename(file.name)
|
|
17
|
-
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
fun from(filePart: FilePart): ApiRequestFile =
|
|
22
|
-
object : ApiRequestFile {
|
|
23
|
-
override fun addToBuilder(builder: MultipartBodyBuilder) {
|
|
24
|
-
builder
|
|
25
|
-
.asyncPart("file", filePart.content(), DataBuffer::class.java)
|
|
26
|
-
.filename(filePart.filename())
|
|
27
|
-
.contentType(filePart.headers().contentType ?: MediaType.APPLICATION_OCTET_STREAM)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
fun addToBuilder(builder: MultipartBodyBuilder)
|
|
33
|
-
}
|
|
1
|
+
package @PACKAGE_NAME@
|
|
2
|
+
|
|
3
|
+
import org.springframework.core.io.buffer.DataBuffer
|
|
4
|
+
import org.springframework.http.MediaType
|
|
5
|
+
import org.springframework.http.client.MultipartBodyBuilder
|
|
6
|
+
import org.springframework.http.codec.multipart.FilePart
|
|
7
|
+
import java.io.File
|
|
8
|
+
|
|
9
|
+
interface ApiRequestFile {
|
|
10
|
+
companion object {
|
|
11
|
+
fun from(file: File): ApiRequestFile =
|
|
12
|
+
object : ApiRequestFile {
|
|
13
|
+
override fun addToBuilder(builder: MultipartBodyBuilder) {
|
|
14
|
+
builder
|
|
15
|
+
.part("file", file)
|
|
16
|
+
.filename(file.name)
|
|
17
|
+
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun from(filePart: FilePart): ApiRequestFile =
|
|
22
|
+
object : ApiRequestFile {
|
|
23
|
+
override fun addToBuilder(builder: MultipartBodyBuilder) {
|
|
24
|
+
builder
|
|
25
|
+
.asyncPart("file", filePart.content(), DataBuffer::class.java)
|
|
26
|
+
.filename(filePart.filename())
|
|
27
|
+
.contentType(filePart.headers().contentType ?: MediaType.APPLICATION_OCTET_STREAM)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun addToBuilder(builder: MultipartBodyBuilder)
|
|
33
|
+
}
|
|
@@ -13,6 +13,14 @@ export declare const jsonAnyGetter: KtReferenceFactory;
|
|
|
13
13
|
export declare const objectMapper: <TBuilder extends SourceBuilder>(springBootVersion?: SpringBootVersion) => KtReference<TBuilder>;
|
|
14
14
|
export declare const serializationFeature: <TBuilder extends SourceBuilder>(springBootVersion?: SpringBootVersion) => KtReference<TBuilder>;
|
|
15
15
|
export declare const deserializationFeature: <TBuilder extends SourceBuilder>(springBootVersion?: SpringBootVersion) => KtReference<TBuilder>;
|
|
16
|
+
/**
|
|
17
|
+
* `tools.jackson.databind.cfg.DateTimeFeature` — Jackson 3 only.
|
|
18
|
+
*
|
|
19
|
+
* Jackson 3 moved `WRITE_DATES_AS_TIMESTAMPS` off `SerializationFeature` onto this type. Unlike its
|
|
20
|
+
* neighbours it takes no `springBootVersion`, because Jackson 2 has no equivalent type: on the Spring Boot 3
|
|
21
|
+
* line the constant still lives on `SerializationFeature`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const dateTimeFeature: KtReferenceFactory;
|
|
16
24
|
export declare const jacksonObjectMapper: <TBuilder extends SourceBuilder>(springBootVersion?: SpringBootVersion) => KtReference<TBuilder>;
|
|
17
25
|
export declare const jacksonMapperBuilder: <TBuilder extends SourceBuilder>(springBootVersion?: SpringBootVersion) => KtReference<TBuilder>;
|
|
18
26
|
//# sourceMappingURL=jackson.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jackson.d.ts","sourceRoot":"","sources":["../../../../src/src/ast/references/jackson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,KAAK,WAAW,EAAe,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAY/F,eAAO,MAAM,YAAY,EAAE,kBAA4F,CAAC;AACxH,eAAO,MAAM,YAAY,EAAE,kBAA4F,CAAC;AACxH,eAAO,MAAM,oBAAoB,EAAE,kBAGlC,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,kBAA4F,CAAC;AACxH,eAAO,MAAM,uBAAuB,EAAE,kBAGrC,CAAC;AACF,eAAO,MAAM,WAAW,EAAE,kBAA2F,CAAC;AACtH,eAAO,MAAM,UAAU,EAAE,kBAA0F,CA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,SAAS,aAAa,sBAC9C,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CACuE,CAAC;AAC/F,eAAO,MAAM,sBAAsB,GAAI,QAAQ,SAAS,aAAa,sBAChD,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CACyE,CAAC;AACjG;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,kBAG7B,CAAC;AAGF,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,aAAa,sBAC7C,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CAC2E,CAAC;AACnG,eAAO,MAAM,oBAAoB,GAAI,QAAQ,SAAS,aAAa,sBAC9C,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CAC4E,CAAC"}
|
|
@@ -20,6 +20,14 @@ export const jsonAnyGetter = ktReference.factory('JsonAnyGetter', 'com.fasterxml
|
|
|
20
20
|
export const objectMapper = (springBootVersion = 3) => ktReference('ObjectMapper', jacksonPackage('databind', springBootVersion));
|
|
21
21
|
export const serializationFeature = (springBootVersion = 3) => ktReference('SerializationFeature', jacksonPackage('databind', springBootVersion));
|
|
22
22
|
export const deserializationFeature = (springBootVersion = 3) => ktReference('DeserializationFeature', jacksonPackage('databind', springBootVersion));
|
|
23
|
+
/**
|
|
24
|
+
* `tools.jackson.databind.cfg.DateTimeFeature` — Jackson 3 only.
|
|
25
|
+
*
|
|
26
|
+
* Jackson 3 moved `WRITE_DATES_AS_TIMESTAMPS` off `SerializationFeature` onto this type. Unlike its
|
|
27
|
+
* neighbours it takes no `springBootVersion`, because Jackson 2 has no equivalent type: on the Spring Boot 3
|
|
28
|
+
* line the constant still lives on `SerializationFeature`.
|
|
29
|
+
*/
|
|
30
|
+
export const dateTimeFeature = ktReference.factory('DateTimeFeature', 'tools.jackson.databind.cfg');
|
|
23
31
|
// com.fasterxml.jackson.module.kotlin (Jackson 2) / tools.jackson.module.kotlin (Jackson 3, Spring Boot 4)
|
|
24
32
|
export const jacksonObjectMapper = (springBootVersion = 3) => ktReference('jacksonObjectMapper', jacksonPackage('module.kotlin', springBootVersion));
|
|
25
33
|
export const jacksonMapperBuilder = (springBootVersion = 3) => ktReference('jacksonMapperBuilder', jacksonPackage('module.kotlin', springBootVersion));
|
|
@@ -3,7 +3,27 @@ import type { KotlinGeneratorConfig } from '../config.js';
|
|
|
3
3
|
export declare abstract class KotlinFileGenerator<TContext extends OpenApiGenerationProviderContext<OpenApiGeneratorInput, KotlinGeneratorConfig>, TOutput> {
|
|
4
4
|
abstract generate(context: TContext): MaybePromise<TOutput>;
|
|
5
5
|
protected toPropertyName(context: TContext, name: string): string;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The Kotlin constant names for the values of an enum, index-aligned with `values`.
|
|
8
|
+
*
|
|
9
|
+
* `toCasing` cannot be relied on alone: `getWords` strips leading digits and every non-alphanumeric
|
|
10
|
+
* character, so a purely numeric value (`1`, `1.1`), the empty string, or a value written only in
|
|
11
|
+
* punctuation or non-ASCII letters all case to `''` — which renders as a nameless enum constant and an
|
|
12
|
+
* empty `when` branch, neither of which is valid Kotlin. Such a value gets an identifier derived from its
|
|
13
|
+
* raw text instead, always prefixed with `_`. That prefix cannot collide with anything `toCasing`
|
|
14
|
+
* produces, because `getWords` strips leading non-alphanumerics.
|
|
15
|
+
*
|
|
16
|
+
* Names are then de-duplicated in declaration order (`_2`, `_2_2`, `_2_3`, ...), so two distinct raw
|
|
17
|
+
* values — `2` and `'2'`, say — can never share one constant.
|
|
18
|
+
*/
|
|
19
|
+
protected toEnumValueNames(context: TContext, values: Nullable<readonly unknown[]>): string[];
|
|
20
|
+
/**
|
|
21
|
+
* The Kotlin constant name `value` is given among the enum's `values`, so that a reference to an enum
|
|
22
|
+
* constant always agrees with the constant `toEnumValueNames` declared for it. Values are matched by
|
|
23
|
+
* their string form, because that is what the generated enum stores. Falls back to the name `value`
|
|
24
|
+
* would get on its own if it is not among `values`.
|
|
25
|
+
*/
|
|
26
|
+
protected toEnumValueName(context: TContext, values: Nullable<readonly unknown[]>, value: unknown): string;
|
|
7
27
|
protected toStringLiteral(_context: TContext, text: Nullable<string>): string;
|
|
8
28
|
}
|
|
9
29
|
//# sourceMappingURL=file-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-generator.d.ts","sourceRoot":"","sources":["../../../src/src/generators/file-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,gCAAgC,EACrC,KAAK,qBAAqB,EAE3B,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,8BAAsB,mBAAmB,CACvC,QAAQ,SAAS,gCAAgC,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,EAC/F,OAAO;aAES,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC;IAElE,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAIjE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"file-generator.d.ts","sourceRoot":"","sources":["../../../src/src/generators/file-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,gCAAgC,EACrC,KAAK,qBAAqB,EAE3B,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,8BAAsB,mBAAmB,CACvC,QAAQ,SAAS,gCAAgC,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,EAC/F,OAAO;aAES,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC;IAElE,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAIjE;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,OAAO,EAAE,CAAC,GAAG,MAAM,EAAE;IAqB7F;;;;;OAKG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM;IAM1G,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM;CAG9E"}
|
|
@@ -4,8 +4,47 @@ export class KotlinFileGenerator {
|
|
|
4
4
|
toPropertyName(context, name) {
|
|
5
5
|
return toKotlinPropertyName(toCasing(name, context.config.propertyNameCasing));
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The Kotlin constant names for the values of an enum, index-aligned with `values`.
|
|
9
|
+
*
|
|
10
|
+
* `toCasing` cannot be relied on alone: `getWords` strips leading digits and every non-alphanumeric
|
|
11
|
+
* character, so a purely numeric value (`1`, `1.1`), the empty string, or a value written only in
|
|
12
|
+
* punctuation or non-ASCII letters all case to `''` — which renders as a nameless enum constant and an
|
|
13
|
+
* empty `when` branch, neither of which is valid Kotlin. Such a value gets an identifier derived from its
|
|
14
|
+
* raw text instead, always prefixed with `_`. That prefix cannot collide with anything `toCasing`
|
|
15
|
+
* produces, because `getWords` strips leading non-alphanumerics.
|
|
16
|
+
*
|
|
17
|
+
* Names are then de-duplicated in declaration order (`_2`, `_2_2`, `_2_3`, ...), so two distinct raw
|
|
18
|
+
* values — `2` and `'2'`, say — can never share one constant.
|
|
19
|
+
*/
|
|
20
|
+
toEnumValueNames(context, values) {
|
|
21
|
+
const names = [];
|
|
22
|
+
const used = new Set();
|
|
23
|
+
for (const value of values !== null && values !== void 0 ? values : []) {
|
|
24
|
+
const raw = String(value);
|
|
25
|
+
let base = toCasing(raw, context.config.enumValueNameCasing);
|
|
26
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(base) || /^_+$/.test(base)) {
|
|
27
|
+
const sanitized = raw.replace(/[^A-Za-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
|
|
28
|
+
base = sanitized.length > 0 ? `_${sanitized}` : raw.length === 0 ? '_EMPTY' : '_VALUE';
|
|
29
|
+
}
|
|
30
|
+
let name = base;
|
|
31
|
+
for (let i = 2; used.has(name); i++)
|
|
32
|
+
name = `${base}_${i}`;
|
|
33
|
+
used.add(name);
|
|
34
|
+
names.push(name);
|
|
35
|
+
}
|
|
36
|
+
return names;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The Kotlin constant name `value` is given among the enum's `values`, so that a reference to an enum
|
|
40
|
+
* constant always agrees with the constant `toEnumValueNames` declared for it. Values are matched by
|
|
41
|
+
* their string form, because that is what the generated enum stores. Falls back to the name `value`
|
|
42
|
+
* would get on its own if it is not among `values`.
|
|
43
|
+
*/
|
|
44
|
+
toEnumValueName(context, values, value) {
|
|
45
|
+
const all = values !== null && values !== void 0 ? values : [];
|
|
46
|
+
const index = all.findIndex((x) => String(x) === String(value));
|
|
47
|
+
return index < 0 ? this.toEnumValueNames(context, [value])[0] : this.toEnumValueNames(context, all)[index];
|
|
9
48
|
}
|
|
10
49
|
toStringLiteral(_context, text) {
|
|
11
50
|
return toKotlinStringLiteral(text);
|
|
@@ -99,8 +99,13 @@ export type SortProperties = {
|
|
|
99
99
|
export type NormalizeSchema = {
|
|
100
100
|
schema: ApiSchema;
|
|
101
101
|
};
|
|
102
|
+
export type NormalizeDiscriminatedBases = {
|
|
103
|
+
schema: ApiSchema;
|
|
104
|
+
};
|
|
102
105
|
export type HasProperty = {
|
|
103
106
|
schema: ApiSchema;
|
|
104
107
|
propertyName: string;
|
|
108
|
+
/** The schemas already inspected, so a composition that cycles back on itself terminates. */
|
|
109
|
+
visited?: Set<ApiSchema>;
|
|
105
110
|
};
|
|
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GAAG;IACxC,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,6FAA6F;IAC7F,OAAO,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;CAC1B,CAAC"}
|
|
@@ -44,6 +44,29 @@ export declare class DefaultKotlinModelGenerator extends KotlinFileGenerator<Con
|
|
|
44
44
|
protected getClassProperties(ctx: Context, args: Args.GetClassProperties): ApiSchemaProperty[];
|
|
45
45
|
protected sortProperties(_ctx: Context, args: Args.SortProperties): ApiSchemaProperty[];
|
|
46
46
|
protected normalizeSchema(ctx: Context, args: Args.NormalizeSchema): ApiSchema;
|
|
47
|
+
/**
|
|
48
|
+
* Rewrites every discriminated `oneOf` base reachable from the schema through a composition into the
|
|
49
|
+
* `object` it describes, so that the merge in `normalizeSchema` treats it as one.
|
|
50
|
+
*
|
|
51
|
+
* A schema that declares a `oneOf` is of kind `oneOf` even when it also declares `type: object` and
|
|
52
|
+
* properties of its own — `determineSchemaKind` looks at `oneOf` first. For a *discriminated* `oneOf` that
|
|
53
|
+
* loses the very information the Kotlin declarations need, because the branches of such a `oneOf` are the
|
|
54
|
+
* schema's subtypes rather than parts of it (the same distinction `resolveAnyOfAndAllOf` draws for a `oneOf`
|
|
55
|
+
* nested inside a composition):
|
|
56
|
+
*
|
|
57
|
+
* - the base is an object in its own right, described by its own `properties`, `required` and any
|
|
58
|
+
* `allOf`/`anyOf` it composes — so its interface must declare those and nothing else, not the union of
|
|
59
|
+
* what its subtypes declare;
|
|
60
|
+
* - a subtype's `allOf: [Base]` is a composition with that object — so the subtype must inherit the base's
|
|
61
|
+
* own properties, including the discriminator, while inheriting nothing from its siblings.
|
|
62
|
+
*
|
|
63
|
+
* Both follow from turning the base into an `object` before the merge runs: the merge already collects the
|
|
64
|
+
* properties of an `object` branch and already declines to collect the branches of a discriminated `oneOf`.
|
|
65
|
+
* This is why `AllOfInheritanceDiscriminator` in test/specs/v3/discriminator-variants.yml has always been
|
|
66
|
+
* correct — with no `oneOf` keyword it is of kind `object` already — while every `oneOf`-holder base in the
|
|
67
|
+
* same document was not.
|
|
68
|
+
*/
|
|
69
|
+
protected normalizeDiscriminatedBases(_ctx: Context, args: Args.NormalizeDiscriminatedBases): ApiSchema;
|
|
47
70
|
protected hasProperty(ctx: Context, args: Args.HasProperty): boolean;
|
|
48
71
|
}
|
|
49
72
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-generator.d.ts","sourceRoot":"","sources":["../../../../src/src/generators/models/model-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAMrB,KAAK,YAAY,EAKjB,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,+BAA+B,IAAI,IAAI,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE3F,KAAK,OAAO,GAAG,2BAA2B,CAAC;AAC3C,KAAK,MAAM,GAAG,0BAA0B,CAAC;AACzC,KAAK,OAAO,GAAG,iBAAiB,CAAC;AAEjC,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACnE,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED,qBAAa,2BAA4B,SAAQ,mBAAmB,CAAC,OAAO,EAAE,MAA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AE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,cAAc,GAAG,iBAAiB,EAAE;IAUvF,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,eAAe,GAAG,SAAS;IAsB9E;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,2BAA2B,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,2BAA2B,GAAG,SAAS;IAmEvG,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,GAAG,OAAO;CAoBrE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendValueGroup, builderTemplate as s, createOverwriteProxy, DEFAULT_IGNORED_SCHEMA_PROPERTIES, getSchemaReference, getSourceDisplayName, modify, modifyEach, notNullish, resolveAnyOfAndAllOf, toCasing, } from '@goast/core';
|
|
2
2
|
import { kt } from '../../ast/index.js';
|
|
3
3
|
import { KotlinFileBuilder } from '../../file-builder.js';
|
|
4
|
-
import { getSourceDocLine } from '../../utils.js';
|
|
4
|
+
import { getSourceDocLine, getStringEnumSchema } from '../../utils.js';
|
|
5
5
|
import { KotlinFileGenerator } from '../file-generator.js';
|
|
6
6
|
export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
7
7
|
generate(ctx) {
|
|
@@ -83,7 +83,9 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
83
83
|
var _a, _b, _c;
|
|
84
84
|
const { schema } = args;
|
|
85
85
|
const name = this.getDeclarationTypeName(ctx, { schema });
|
|
86
|
-
|
|
86
|
+
// One set of names for both generation sites below, so the constant and its `when` branch agree.
|
|
87
|
+
const valueNames = this.toEnumValueNames(ctx, schema.enum);
|
|
88
|
+
return kt.enum(name, (_b = (_a = schema.enum) === null || _a === void 0 ? void 0 : _a.map((x, i) => kt.enumValue(valueNames[i], {
|
|
87
89
|
annotations: [kt.annotation(kt.refs.jackson.jsonProperty(), [kt.argument(kt.string(String(x)))])],
|
|
88
90
|
arguments: [kt.argument(kt.string(String(x)))],
|
|
89
91
|
}))) !== null && _b !== void 0 ? _b : [], {
|
|
@@ -101,9 +103,9 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
101
103
|
returnType: kt.reference(name, null, { nullable: true }),
|
|
102
104
|
singleExpression: true,
|
|
103
105
|
body: !((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) ? 'null' : s `\nwhen(value) {${s.indent `${appendValueGroup([
|
|
104
|
-
schema.enum.map((x) => s `\n${kt.string(String(x))} -> ${
|
|
105
|
-
])}
|
|
106
|
-
else -> null`}
|
|
106
|
+
schema.enum.map((x, i) => s `\n${kt.string(String(x))} -> ${valueNames[i]}`),
|
|
107
|
+
])}
|
|
108
|
+
else -> null`}
|
|
107
109
|
}`,
|
|
108
110
|
}),
|
|
109
111
|
],
|
|
@@ -210,10 +212,19 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
210
212
|
return String(schema.default);
|
|
211
213
|
case 'string':
|
|
212
214
|
return schema.enum && schema.enum.length > 0
|
|
213
|
-
? kt.call([this.getType(ctx, { schema }),
|
|
215
|
+
? kt.call([this.getType(ctx, { schema }), this.toEnumValueName(ctx, schema.enum, schema.default)])
|
|
214
216
|
: kt.string(String(schema.default));
|
|
215
|
-
case 'array':
|
|
216
|
-
|
|
217
|
+
case 'array': {
|
|
218
|
+
const itemEnumSchema = getStringEnumSchema(schema.items);
|
|
219
|
+
return kt.call(kt.refs.listOf.infer(), Array.isArray(schema.default)
|
|
220
|
+
? schema.default.map((x) => itemEnumSchema
|
|
221
|
+
? kt.call([
|
|
222
|
+
this.getType(ctx, { schema: itemEnumSchema }),
|
|
223
|
+
this.toEnumValueName(ctx, itemEnumSchema.enum, x),
|
|
224
|
+
])
|
|
225
|
+
: kt.toNode(x))
|
|
226
|
+
: []);
|
|
227
|
+
}
|
|
217
228
|
default:
|
|
218
229
|
return 'null';
|
|
219
230
|
}
|
|
@@ -439,11 +450,19 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
439
450
|
if (schema.kind === 'combined' || schema.kind === 'oneOf') {
|
|
440
451
|
return false;
|
|
441
452
|
}
|
|
453
|
+
// A discriminated schema is the supertype its subtypes implement and the carrier of the
|
|
454
|
+
// `@JsonTypeInfo`/`@JsonSubTypes` pair, so it always needs a declaration of its own. The two rules below
|
|
455
|
+
// simplify a schema that nothing refers to as a type; degrading a polymorphic base to `Any` or to a `Map`
|
|
456
|
+
// instead drops the supertype from every subtype and the polymorphism with it. This matters for a base
|
|
457
|
+
// whose `discriminator.propertyName` is declared on the mapping targets rather than on the base, which is
|
|
458
|
+
// legal and leaves the base with no properties of its own.
|
|
459
|
+
const isDiscriminatedBase = schema.kind === 'object' && schema.discriminator !== undefined;
|
|
442
460
|
// Schemas representable by a simple Map type do not need its own type declaration
|
|
443
|
-
if (schema.kind === 'object' && schema.properties.size === 0 && schema.additionalProperties) {
|
|
461
|
+
if (!isDiscriminatedBase && schema.kind === 'object' && schema.properties.size === 0 && schema.additionalProperties) {
|
|
444
462
|
return false;
|
|
445
463
|
}
|
|
446
|
-
if (schema.kind === 'object' &&
|
|
464
|
+
if (!isDiscriminatedBase && schema.kind === 'object' &&
|
|
465
|
+
ctx.config.emptyObjectTypeBehavior === 'use-any' && schema.properties.size === 0) {
|
|
447
466
|
return false;
|
|
448
467
|
}
|
|
449
468
|
// Dynamically generated schemas do not have its own type declaration
|
|
@@ -499,6 +518,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
499
518
|
}
|
|
500
519
|
normalizeSchema(ctx, args) {
|
|
501
520
|
let { schema } = args;
|
|
521
|
+
schema = this.normalizeDiscriminatedBases(ctx, { schema });
|
|
502
522
|
if (schema.kind === 'oneOf') {
|
|
503
523
|
schema = ctx.config.oneOfBehavior === 'treat-as-any-of'
|
|
504
524
|
// deno-lint-ignore no-explicit-any
|
|
@@ -515,10 +535,107 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
515
535
|
}
|
|
516
536
|
return schema;
|
|
517
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Rewrites every discriminated `oneOf` base reachable from the schema through a composition into the
|
|
540
|
+
* `object` it describes, so that the merge in `normalizeSchema` treats it as one.
|
|
541
|
+
*
|
|
542
|
+
* A schema that declares a `oneOf` is of kind `oneOf` even when it also declares `type: object` and
|
|
543
|
+
* properties of its own — `determineSchemaKind` looks at `oneOf` first. For a *discriminated* `oneOf` that
|
|
544
|
+
* loses the very information the Kotlin declarations need, because the branches of such a `oneOf` are the
|
|
545
|
+
* schema's subtypes rather than parts of it (the same distinction `resolveAnyOfAndAllOf` draws for a `oneOf`
|
|
546
|
+
* nested inside a composition):
|
|
547
|
+
*
|
|
548
|
+
* - the base is an object in its own right, described by its own `properties`, `required` and any
|
|
549
|
+
* `allOf`/`anyOf` it composes — so its interface must declare those and nothing else, not the union of
|
|
550
|
+
* what its subtypes declare;
|
|
551
|
+
* - a subtype's `allOf: [Base]` is a composition with that object — so the subtype must inherit the base's
|
|
552
|
+
* own properties, including the discriminator, while inheriting nothing from its siblings.
|
|
553
|
+
*
|
|
554
|
+
* Both follow from turning the base into an `object` before the merge runs: the merge already collects the
|
|
555
|
+
* properties of an `object` branch and already declines to collect the branches of a discriminated `oneOf`.
|
|
556
|
+
* This is why `AllOfInheritanceDiscriminator` in test/specs/v3/discriminator-variants.yml has always been
|
|
557
|
+
* correct — with no `oneOf` keyword it is of kind `object` already — while every `oneOf`-holder base in the
|
|
558
|
+
* same document was not.
|
|
559
|
+
*/
|
|
560
|
+
normalizeDiscriminatedBases(_ctx, args) {
|
|
561
|
+
// `normalizeSchema` runs once per property type via `shouldGenerateTypeDeclaration`, and almost no schema
|
|
562
|
+
// has a discriminated base anywhere below it. Answering that first costs one traversal and one set, and
|
|
563
|
+
// lets the overwhelmingly common case return the schema itself rather than a copy per composing schema.
|
|
564
|
+
//
|
|
565
|
+
// The question is asked once for the whole call rather than again per branch: a per-branch answer would
|
|
566
|
+
// have to be memoised to stay linear, and memoising it is unsound, because a walk truncated by the cycle
|
|
567
|
+
// guard can record `false` for a branch that reaches a base only by going back through an ancestor.
|
|
568
|
+
if (!containsDiscriminatedBase(args.schema, new Set()))
|
|
569
|
+
return args.schema;
|
|
570
|
+
const rewritten = new Map();
|
|
571
|
+
return rewrite(args.schema);
|
|
572
|
+
function rewrite(schema) {
|
|
573
|
+
const existing = rewritten.get(schema);
|
|
574
|
+
if (existing)
|
|
575
|
+
return existing;
|
|
576
|
+
const isBase = isDiscriminatedBase(schema);
|
|
577
|
+
const allOf = branches(schema, 'allOf');
|
|
578
|
+
const anyOf = branches(schema, 'anyOf');
|
|
579
|
+
// The branches of a discriminated `oneOf` are dropped rather than descended into: they are the schema's
|
|
580
|
+
// subtypes, and a subtype is generated from its own file where it is the root of this walk.
|
|
581
|
+
const oneOf = isBase ? [] : branches(schema, 'oneOf');
|
|
582
|
+
if (!isBase && allOf.length === 0 && anyOf.length === 0 && oneOf.length === 0) {
|
|
583
|
+
return schema;
|
|
584
|
+
}
|
|
585
|
+
// Registered before descending, so a branch composing back to one of its own ancestors terminates.
|
|
586
|
+
// deno-lint-ignore no-explicit-any
|
|
587
|
+
const copy = { ...schema };
|
|
588
|
+
rewritten.set(schema, copy);
|
|
589
|
+
if (isBase) {
|
|
590
|
+
copy.kind = 'object';
|
|
591
|
+
copy.type = 'object';
|
|
592
|
+
}
|
|
593
|
+
copy.allOf = allOf.map(rewrite);
|
|
594
|
+
copy.anyOf = anyOf.map(rewrite);
|
|
595
|
+
copy.oneOf = oneOf.map(rewrite);
|
|
596
|
+
return copy;
|
|
597
|
+
}
|
|
598
|
+
/** Whether the schema or anything it composes is a base this walk would rewrite. */
|
|
599
|
+
function containsDiscriminatedBase(schema, visited) {
|
|
600
|
+
if (visited.has(schema))
|
|
601
|
+
return false;
|
|
602
|
+
visited.add(schema);
|
|
603
|
+
if (isDiscriminatedBase(schema))
|
|
604
|
+
return true;
|
|
605
|
+
const contains = (x) => containsDiscriminatedBase(x, visited);
|
|
606
|
+
return branches(schema, 'allOf').some(contains) ||
|
|
607
|
+
branches(schema, 'anyOf').some(contains) ||
|
|
608
|
+
branches(schema, 'oneOf').some(contains);
|
|
609
|
+
}
|
|
610
|
+
function isDiscriminatedBase(schema) {
|
|
611
|
+
return schema.kind === 'oneOf' && schema.discriminator !== undefined;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* The branches a schema composes under one keyword. `normalizeSchema` leaves an explicit
|
|
615
|
+
* `oneOf: undefined` behind when it rewrites a `oneOf` holder, so a keyword can be present with no value.
|
|
616
|
+
*/
|
|
617
|
+
function branches(schema, keyword) {
|
|
618
|
+
var _a;
|
|
619
|
+
const values = schema;
|
|
620
|
+
return (_a = values[keyword]) !== null && _a !== void 0 ? _a : [];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
518
623
|
hasProperty(ctx, args) {
|
|
519
|
-
|
|
624
|
+
// A composition branch may compose back to one of its own ancestors (see test/specs/v3/anyof-cycle.yml).
|
|
625
|
+
// Without this guard such a cycle recurses until the stack overflows. Re-visiting a schema can never
|
|
626
|
+
// change the answer, so returning `false` for one is safe: another path either already found the
|
|
627
|
+
// property or does not contain it at all.
|
|
628
|
+
const { schema, propertyName, visited = new Set() } = args;
|
|
629
|
+
if (visited.has(schema))
|
|
630
|
+
return false;
|
|
631
|
+
visited.add(schema);
|
|
520
632
|
return (('properties' in schema && schema.properties.has(propertyName)) ||
|
|
521
|
-
('anyOf' in schema && schema.anyOf.some((schema) => this.hasProperty(ctx, { schema, propertyName }))) ||
|
|
522
|
-
('allOf' in schema && schema.allOf.some((schema) => this.hasProperty(ctx, { schema, propertyName })))
|
|
633
|
+
('anyOf' in schema && schema.anyOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))) ||
|
|
634
|
+
('allOf' in schema && schema.allOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))) ||
|
|
635
|
+
// Only an undiscriminated `oneOf` composes into the schema that references it, matching which `oneOf`
|
|
636
|
+
// branches `resolveAnyOfAndAllOf` merges. A discriminated one lists subtypes, whose properties are not
|
|
637
|
+
// the referencing schema's, so an inherited property never comes from there.
|
|
638
|
+
('oneOf' in schema && !schema.discriminator &&
|
|
639
|
+
schema.oneOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))));
|
|
523
640
|
}
|
|
524
641
|
}
|
|
@@ -14,6 +14,15 @@ export interface KotlinOkHttp3Generator<TOutput extends Output = Output> {
|
|
|
14
14
|
export declare class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context, Output> implements KotlinOkHttp3Generator {
|
|
15
15
|
generate(ctx: KotlinOkHttp3ClientGeneratorContext): MaybePromise<Output>;
|
|
16
16
|
protected getClientFileContent(ctx: Context, _args: Args.GetClientFileContent): AppendValueGroup<Builder>;
|
|
17
|
+
/**
|
|
18
|
+
* The `super(…)` arguments, in the base class's own parameter order.
|
|
19
|
+
*
|
|
20
|
+
* The base's order is chosen by `serializer`, at the `@API_CLIENT_PARAMETERS@` placeholder substitution in
|
|
21
|
+
* `okhttp3-clients-generator.ts`, and this list is positional, so the two must be derived from the same
|
|
22
|
+
* flag. Defect 27 was this list being a constant that matched only the `'parameter'` shape while every
|
|
23
|
+
* corpus profile uses the default `'static'`.
|
|
24
|
+
*/
|
|
25
|
+
protected getClientDelegateArguments(serializerAsParameter: boolean): string[];
|
|
17
26
|
protected getClientClass(ctx: Context, _args: Args.GetClientClass): kt.Class<Builder>;
|
|
18
27
|
protected getClientCompanionObject(ctx: Context, _args: Args.GetClientCompanionObject): kt.Object<Builder>;
|
|
19
28
|
protected getEndpointClientMembers(ctx: Context, args: Args.GetEndpointClientMembers): kt.ClassMember<Builder>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"okhttp3-client-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/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