@goast/kotlin 0.6.0-beta.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
- package/src/mod.ts +8 -0
- package/src/src/assets.ts +9 -0
- package/src/src/ast/_index.ts +66 -0
- package/src/src/ast/common.ts +1 -0
- package/src/src/ast/index.ts +1 -0
- package/src/src/ast/node.ts +10 -0
- package/src/src/ast/nodes/annotation.ts +79 -0
- package/src/src/ast/nodes/argument.ts +62 -0
- package/src/src/ast/nodes/call.ts +75 -0
- package/src/src/ast/nodes/class.ts +178 -0
- package/src/src/ast/nodes/collection-literal.ts +49 -0
- package/src/src/ast/nodes/constructor.ts +126 -0
- package/src/src/ast/nodes/doc-tag.ts +138 -0
- package/src/src/ast/nodes/doc.ts +111 -0
- package/src/src/ast/nodes/enum-value.ts +100 -0
- package/src/src/ast/nodes/enum.ts +163 -0
- package/src/src/ast/nodes/function.ts +178 -0
- package/src/src/ast/nodes/generic-parameter.ts +54 -0
- package/src/src/ast/nodes/init-block.ts +38 -0
- package/src/src/ast/nodes/interface.ts +133 -0
- package/src/src/ast/nodes/lambda-type.ts +73 -0
- package/src/src/ast/nodes/lambda.ts +74 -0
- package/src/src/ast/nodes/object.ts +102 -0
- package/src/src/ast/nodes/parameter.ts +118 -0
- package/src/src/ast/nodes/property.ts +225 -0
- package/src/src/ast/nodes/reference.ts +178 -0
- package/src/src/ast/nodes/string.ts +114 -0
- package/src/src/ast/nodes/types.ts +23 -0
- package/src/src/ast/references/index.ts +10 -0
- package/src/src/ast/references/jackson.ts +70 -0
- package/src/src/ast/references/jakarta.ts +14 -0
- package/src/src/ast/references/java.ts +27 -0
- package/src/src/ast/references/kotlin.ts +41 -0
- package/src/src/ast/references/kotlinx.ts +14 -0
- package/src/src/ast/references/okhttp3.ts +5 -0
- package/src/src/ast/references/reactor.ts +5 -0
- package/src/src/ast/references/spring-reactive.ts +37 -0
- package/src/src/ast/references/spring.ts +86 -0
- package/src/src/ast/references/swagger.ts +23 -0
- package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
- package/src/src/ast/utils/to-kt-node.ts +31 -0
- package/src/src/ast/utils/write-kt-annotations.ts +15 -0
- package/src/src/ast/utils/write-kt-arguments.ts +45 -0
- package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
- package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
- package/src/src/ast/utils/write-kt-members.ts +25 -0
- package/src/src/ast/utils/write-kt-node.ts +37 -0
- package/src/src/ast/utils/write-kt-parameters.ts +25 -0
- package/src/src/common-results.ts +4 -0
- package/src/src/config.ts +61 -0
- package/src/src/file-builder.ts +112 -0
- package/src/src/generators/file-generator.ts +71 -0
- package/src/src/generators/index.ts +5 -0
- package/src/src/generators/models/args.ts +142 -0
- package/src/src/generators/models/index.ts +4 -0
- package/src/src/generators/models/model-generator.ts +850 -0
- package/src/src/generators/models/models-generator.ts +65 -0
- package/src/src/generators/models/models.ts +95 -0
- package/src/src/generators/services/okhttp3-clients/args.ts +90 -0
- package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
- package/src/src/generators/services/okhttp3-clients/models.ts +73 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +639 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +190 -0
- package/src/src/generators/services/okhttp3-clients/refs.ts +59 -0
- package/src/src/generators/services/spring-controllers/args.ts +95 -0
- package/src/src/generators/services/spring-controllers/index.ts +4 -0
- package/src/src/generators/services/spring-controllers/models.ts +76 -0
- package/src/src/generators/services/spring-controllers/refs.ts +17 -0
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1129 -0
- package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -0
- package/src/src/generators/services/spring-reactive-web-clients/args.ts +114 -0
- package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
- package/src/src/generators/services/spring-reactive-web-clients/models.ts +78 -0
- package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +657 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -0
- package/src/src/import-collection.ts +98 -0
- package/src/src/types.ts +3 -0
- package/src/src/utils.ts +55 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-collection.d.ts","sourceRoot":"","sources":["../../src/src/import-collection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"import-collection.d.ts","sourceRoot":"","sources":["../../src/src/import-collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,uBAE5C,CAAC;AAEF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAChE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;gBAEvC,OAAO,GAAE,OAAO,CAAC,uBAAuB,CAAM;IAI1D,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED,IAAW,OAAO,IAAI,YAAY,EAAE,CASnC;IAEM,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IACvD,SAAS,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAiBxC,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;IAMzC,KAAK,IAAI,IAAI;IAIb,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,MAAM;IAMzD,OAAO,CAAC,OAAO,EAAE,aAAa;CAuBtC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StringBuilder } from '@goast/core';
|
|
1
|
+
import { compareString, StringBuilder } from '@goast/core';
|
|
2
2
|
import { defaultKotlinGeneratorConfig } from './config.js';
|
|
3
3
|
export const defaultImportCollectionOptions = {
|
|
4
4
|
globalImports: defaultKotlinGeneratorConfig.globalImports,
|
|
@@ -75,7 +75,7 @@ export class ImportCollection {
|
|
|
75
75
|
else if (!isCoreImport(a) && isCoreImport(b)) {
|
|
76
76
|
return -1;
|
|
77
77
|
}
|
|
78
|
-
return a
|
|
78
|
+
return compareString(a, b);
|
|
79
79
|
})
|
|
80
80
|
.forEach((importPath) => builder.appendLine(`import ${importPath}`));
|
|
81
81
|
}
|
package/esm/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { ApiComponent, Nullable } from '@goast/core';
|
|
1
|
+
import type { ApiComponent, ApiSchema, Nullable } from '@goast/core';
|
|
2
2
|
export declare function toKotlinStringLiteral(value: Nullable<string>): string;
|
|
3
3
|
export declare function toKotlinPropertyName(value: string): string;
|
|
4
4
|
export declare function modifyString<TArgs extends unknown[]>(value: string, modifier: string | RegExp | ((value: string, ...args: TArgs) => string) | undefined, ...args: TArgs): string;
|
|
5
5
|
export declare function getSourceDocLine<T>(component: ApiComponent<T>): string;
|
|
6
|
+
export declare function getStringEnumSchema(schema: Nullable<ApiSchema>): ApiSchema<'string'> | undefined;
|
|
7
|
+
export declare function getArrayItemStringEnumSchema(schema: Nullable<ApiSchema>): ApiSchema<'string'> | undefined;
|
|
6
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/esm/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIrE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAWrE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED,wBAAgB,YAAY,CAAC,KAAK,SAAS,OAAO,EAAE,EAClD,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC,GAAG,SAAS,EACnF,GAAG,IAAI,EAAE,KAAK,GACb,MAAM,CAYR;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,CAItE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAEhG;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS,CAEzG"}
|
package/esm/src/utils.js
CHANGED
|
@@ -36,3 +36,10 @@ export function getSourceDocLine(component) {
|
|
|
36
36
|
const { line, col } = component.$src.pos;
|
|
37
37
|
return `Source: ${file}:${line}:${col} (${component.$src.path})`;
|
|
38
38
|
}
|
|
39
|
+
export function getStringEnumSchema(schema) {
|
|
40
|
+
var _a;
|
|
41
|
+
return (schema === null || schema === void 0 ? void 0 : schema.kind) === 'string' && ((_a = schema.enum) === null || _a === void 0 ? void 0 : _a.length) ? schema : undefined;
|
|
42
|
+
}
|
|
43
|
+
export function getArrayItemStringEnumSchema(schema) {
|
|
44
|
+
return (schema === null || schema === void 0 ? void 0 : schema.kind) === 'array' ? getStringEnumSchema(schema.items) : undefined;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/kotlin",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Provides gOAst generators for generating Kotlin code from OpenAPI specifications.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marc Schmidt (MaSch0212)",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"tslib": "^2.6.2",
|
|
27
27
|
"http-status-codes": "^2.3.0",
|
|
28
|
-
"@goast/core": "0.6.0
|
|
28
|
+
"@goast/core": "0.6.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.9.0"
|
|
@@ -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,CAAC;AACpH,eAAO,MAAM,aAAa,EAAE,kBAG3B,CAAC;AACF,eAAO,MAAM,aAAa,EAAE,kBAG3B,CAAC;AAGF,eAAO,MAAM,YAAY,GAAI,QAAQ,SAAS,aAAa,sBACtC,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CAAyF,CAAC;AACjH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,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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a,sBAC9C,iBAAiB,KACnC,WAAW,CAAC,QAAQ,CAC4E,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jacksonMapperBuilder = exports.jacksonObjectMapper = exports.deserializationFeature = exports.serializationFeature = exports.objectMapper = exports.jsonAnyGetter = exports.jsonAnySetter = exports.jsonIgnore = exports.jsonInclude = exports.jsonPropertyDescription = exports.jsonProperty = exports.jsonClassDescription = exports.jsonSubTypes = exports.jsonTypeInfo = void 0;
|
|
3
|
+
exports.jacksonMapperBuilder = exports.jacksonObjectMapper = exports.dateTimeFeature = exports.deserializationFeature = exports.serializationFeature = exports.objectMapper = exports.jsonAnyGetter = exports.jsonAnySetter = exports.jsonIgnore = exports.jsonInclude = exports.jsonPropertyDescription = exports.jsonProperty = exports.jsonClassDescription = exports.jsonSubTypes = exports.jsonTypeInfo = void 0;
|
|
4
4
|
const reference_js_1 = require("../nodes/reference.js");
|
|
5
5
|
/**
|
|
6
6
|
* Resolves a Jackson package name for the targeted Spring Boot version.
|
|
@@ -26,6 +26,14 @@ const serializationFeature = (springBootVersion = 3) => (0, reference_js_1.ktRef
|
|
|
26
26
|
exports.serializationFeature = serializationFeature;
|
|
27
27
|
const deserializationFeature = (springBootVersion = 3) => (0, reference_js_1.ktReference)('DeserializationFeature', jacksonPackage('databind', springBootVersion));
|
|
28
28
|
exports.deserializationFeature = deserializationFeature;
|
|
29
|
+
/**
|
|
30
|
+
* `tools.jackson.databind.cfg.DateTimeFeature` — Jackson 3 only.
|
|
31
|
+
*
|
|
32
|
+
* Jackson 3 moved `WRITE_DATES_AS_TIMESTAMPS` off `SerializationFeature` onto this type. Unlike its
|
|
33
|
+
* neighbours it takes no `springBootVersion`, because Jackson 2 has no equivalent type: on the Spring Boot 3
|
|
34
|
+
* line the constant still lives on `SerializationFeature`.
|
|
35
|
+
*/
|
|
36
|
+
exports.dateTimeFeature = reference_js_1.ktReference.factory('DateTimeFeature', 'tools.jackson.databind.cfg');
|
|
29
37
|
// com.fasterxml.jackson.module.kotlin (Jackson 2) / tools.jackson.module.kotlin (Jackson 3, Spring Boot 4)
|
|
30
38
|
const jacksonObjectMapper = (springBootVersion = 3) => (0, reference_js_1.ktReference)('jacksonObjectMapper', jacksonPackage('module.kotlin', springBootVersion));
|
|
31
39
|
exports.jacksonObjectMapper = jacksonObjectMapper;
|
|
@@ -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"}
|
|
@@ -7,8 +7,47 @@ class KotlinFileGenerator {
|
|
|
7
7
|
toPropertyName(context, name) {
|
|
8
8
|
return (0, utils_js_1.toKotlinPropertyName)((0, core_1.toCasing)(name, context.config.propertyNameCasing));
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The Kotlin constant names for the values of an enum, index-aligned with `values`.
|
|
12
|
+
*
|
|
13
|
+
* `toCasing` cannot be relied on alone: `getWords` strips leading digits and every non-alphanumeric
|
|
14
|
+
* character, so a purely numeric value (`1`, `1.1`), the empty string, or a value written only in
|
|
15
|
+
* punctuation or non-ASCII letters all case to `''` — which renders as a nameless enum constant and an
|
|
16
|
+
* empty `when` branch, neither of which is valid Kotlin. Such a value gets an identifier derived from its
|
|
17
|
+
* raw text instead, always prefixed with `_`. That prefix cannot collide with anything `toCasing`
|
|
18
|
+
* produces, because `getWords` strips leading non-alphanumerics.
|
|
19
|
+
*
|
|
20
|
+
* Names are then de-duplicated in declaration order (`_2`, `_2_2`, `_2_3`, ...), so two distinct raw
|
|
21
|
+
* values — `2` and `'2'`, say — can never share one constant.
|
|
22
|
+
*/
|
|
23
|
+
toEnumValueNames(context, values) {
|
|
24
|
+
const names = [];
|
|
25
|
+
const used = new Set();
|
|
26
|
+
for (const value of values !== null && values !== void 0 ? values : []) {
|
|
27
|
+
const raw = String(value);
|
|
28
|
+
let base = (0, core_1.toCasing)(raw, context.config.enumValueNameCasing);
|
|
29
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(base) || /^_+$/.test(base)) {
|
|
30
|
+
const sanitized = raw.replace(/[^A-Za-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
|
|
31
|
+
base = sanitized.length > 0 ? `_${sanitized}` : raw.length === 0 ? '_EMPTY' : '_VALUE';
|
|
32
|
+
}
|
|
33
|
+
let name = base;
|
|
34
|
+
for (let i = 2; used.has(name); i++)
|
|
35
|
+
name = `${base}_${i}`;
|
|
36
|
+
used.add(name);
|
|
37
|
+
names.push(name);
|
|
38
|
+
}
|
|
39
|
+
return names;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The Kotlin constant name `value` is given among the enum's `values`, so that a reference to an enum
|
|
43
|
+
* constant always agrees with the constant `toEnumValueNames` declared for it. Values are matched by
|
|
44
|
+
* their string form, because that is what the generated enum stores. Falls back to the name `value`
|
|
45
|
+
* would get on its own if it is not among `values`.
|
|
46
|
+
*/
|
|
47
|
+
toEnumValueName(context, values, value) {
|
|
48
|
+
const all = values !== null && values !== void 0 ? values : [];
|
|
49
|
+
const index = all.findIndex((x) => String(x) === String(value));
|
|
50
|
+
return index < 0 ? this.toEnumValueNames(context, [value])[0] : this.toEnumValueNames(context, all)[index];
|
|
12
51
|
}
|
|
13
52
|
toStringLiteral(_context, text) {
|
|
14
53
|
return (0, utils_js_1.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
|
};
|
|
106
111
|
//# sourceMappingURL=args.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../../src/src/generators/models/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC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M,EAAE,SAAS,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,2BAA2B,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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C,CAAC,CAAA;KAAE,CAAC,EAAE;IAM5F,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,EAAE;IA4B9F,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,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"}
|
|
@@ -86,7 +86,9 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
86
86
|
var _a, _b, _c;
|
|
87
87
|
const { schema } = args;
|
|
88
88
|
const name = this.getDeclarationTypeName(ctx, { schema });
|
|
89
|
-
|
|
89
|
+
// One set of names for both generation sites below, so the constant and its `when` branch agree.
|
|
90
|
+
const valueNames = this.toEnumValueNames(ctx, schema.enum);
|
|
91
|
+
return index_js_1.kt.enum(name, (_b = (_a = schema.enum) === null || _a === void 0 ? void 0 : _a.map((x, i) => index_js_1.kt.enumValue(valueNames[i], {
|
|
90
92
|
annotations: [index_js_1.kt.annotation(index_js_1.kt.refs.jackson.jsonProperty(), [index_js_1.kt.argument(index_js_1.kt.string(String(x)))])],
|
|
91
93
|
arguments: [index_js_1.kt.argument(index_js_1.kt.string(String(x)))],
|
|
92
94
|
}))) !== null && _b !== void 0 ? _b : [], {
|
|
@@ -104,9 +106,9 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
104
106
|
returnType: index_js_1.kt.reference(name, null, { nullable: true }),
|
|
105
107
|
singleExpression: true,
|
|
106
108
|
body: !((_c = schema.enum) === null || _c === void 0 ? void 0 : _c.length) ? 'null' : (0, core_1.builderTemplate) `\nwhen(value) {${core_1.builderTemplate.indent `${(0, core_1.appendValueGroup)([
|
|
107
|
-
schema.enum.map((x) => (0, core_1.builderTemplate) `\n${index_js_1.kt.string(String(x))} -> ${
|
|
108
|
-
])}
|
|
109
|
-
else -> null`}
|
|
109
|
+
schema.enum.map((x, i) => (0, core_1.builderTemplate) `\n${index_js_1.kt.string(String(x))} -> ${valueNames[i]}`),
|
|
110
|
+
])}
|
|
111
|
+
else -> null`}
|
|
110
112
|
}`,
|
|
111
113
|
}),
|
|
112
114
|
],
|
|
@@ -213,10 +215,19 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
213
215
|
return String(schema.default);
|
|
214
216
|
case 'string':
|
|
215
217
|
return schema.enum && schema.enum.length > 0
|
|
216
|
-
? index_js_1.kt.call([this.getType(ctx, { schema }), (
|
|
218
|
+
? index_js_1.kt.call([this.getType(ctx, { schema }), this.toEnumValueName(ctx, schema.enum, schema.default)])
|
|
217
219
|
: index_js_1.kt.string(String(schema.default));
|
|
218
|
-
case 'array':
|
|
219
|
-
|
|
220
|
+
case 'array': {
|
|
221
|
+
const itemEnumSchema = (0, utils_js_1.getStringEnumSchema)(schema.items);
|
|
222
|
+
return index_js_1.kt.call(index_js_1.kt.refs.listOf.infer(), Array.isArray(schema.default)
|
|
223
|
+
? schema.default.map((x) => itemEnumSchema
|
|
224
|
+
? index_js_1.kt.call([
|
|
225
|
+
this.getType(ctx, { schema: itemEnumSchema }),
|
|
226
|
+
this.toEnumValueName(ctx, itemEnumSchema.enum, x),
|
|
227
|
+
])
|
|
228
|
+
: index_js_1.kt.toNode(x))
|
|
229
|
+
: []);
|
|
230
|
+
}
|
|
220
231
|
default:
|
|
221
232
|
return 'null';
|
|
222
233
|
}
|
|
@@ -442,11 +453,19 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
442
453
|
if (schema.kind === 'combined' || schema.kind === 'oneOf') {
|
|
443
454
|
return false;
|
|
444
455
|
}
|
|
456
|
+
// A discriminated schema is the supertype its subtypes implement and the carrier of the
|
|
457
|
+
// `@JsonTypeInfo`/`@JsonSubTypes` pair, so it always needs a declaration of its own. The two rules below
|
|
458
|
+
// simplify a schema that nothing refers to as a type; degrading a polymorphic base to `Any` or to a `Map`
|
|
459
|
+
// instead drops the supertype from every subtype and the polymorphism with it. This matters for a base
|
|
460
|
+
// whose `discriminator.propertyName` is declared on the mapping targets rather than on the base, which is
|
|
461
|
+
// legal and leaves the base with no properties of its own.
|
|
462
|
+
const isDiscriminatedBase = schema.kind === 'object' && schema.discriminator !== undefined;
|
|
445
463
|
// Schemas representable by a simple Map type do not need its own type declaration
|
|
446
|
-
if (schema.kind === 'object' && schema.properties.size === 0 && schema.additionalProperties) {
|
|
464
|
+
if (!isDiscriminatedBase && schema.kind === 'object' && schema.properties.size === 0 && schema.additionalProperties) {
|
|
447
465
|
return false;
|
|
448
466
|
}
|
|
449
|
-
if (schema.kind === 'object' &&
|
|
467
|
+
if (!isDiscriminatedBase && schema.kind === 'object' &&
|
|
468
|
+
ctx.config.emptyObjectTypeBehavior === 'use-any' && schema.properties.size === 0) {
|
|
450
469
|
return false;
|
|
451
470
|
}
|
|
452
471
|
// Dynamically generated schemas do not have its own type declaration
|
|
@@ -502,6 +521,7 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
502
521
|
}
|
|
503
522
|
normalizeSchema(ctx, args) {
|
|
504
523
|
let { schema } = args;
|
|
524
|
+
schema = this.normalizeDiscriminatedBases(ctx, { schema });
|
|
505
525
|
if (schema.kind === 'oneOf') {
|
|
506
526
|
schema = ctx.config.oneOfBehavior === 'treat-as-any-of'
|
|
507
527
|
// deno-lint-ignore no-explicit-any
|
|
@@ -518,11 +538,108 @@ class DefaultKotlinModelGenerator extends file_generator_js_1.KotlinFileGenerato
|
|
|
518
538
|
}
|
|
519
539
|
return schema;
|
|
520
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Rewrites every discriminated `oneOf` base reachable from the schema through a composition into the
|
|
543
|
+
* `object` it describes, so that the merge in `normalizeSchema` treats it as one.
|
|
544
|
+
*
|
|
545
|
+
* A schema that declares a `oneOf` is of kind `oneOf` even when it also declares `type: object` and
|
|
546
|
+
* properties of its own — `determineSchemaKind` looks at `oneOf` first. For a *discriminated* `oneOf` that
|
|
547
|
+
* loses the very information the Kotlin declarations need, because the branches of such a `oneOf` are the
|
|
548
|
+
* schema's subtypes rather than parts of it (the same distinction `resolveAnyOfAndAllOf` draws for a `oneOf`
|
|
549
|
+
* nested inside a composition):
|
|
550
|
+
*
|
|
551
|
+
* - the base is an object in its own right, described by its own `properties`, `required` and any
|
|
552
|
+
* `allOf`/`anyOf` it composes — so its interface must declare those and nothing else, not the union of
|
|
553
|
+
* what its subtypes declare;
|
|
554
|
+
* - a subtype's `allOf: [Base]` is a composition with that object — so the subtype must inherit the base's
|
|
555
|
+
* own properties, including the discriminator, while inheriting nothing from its siblings.
|
|
556
|
+
*
|
|
557
|
+
* Both follow from turning the base into an `object` before the merge runs: the merge already collects the
|
|
558
|
+
* properties of an `object` branch and already declines to collect the branches of a discriminated `oneOf`.
|
|
559
|
+
* This is why `AllOfInheritanceDiscriminator` in test/specs/v3/discriminator-variants.yml has always been
|
|
560
|
+
* correct — with no `oneOf` keyword it is of kind `object` already — while every `oneOf`-holder base in the
|
|
561
|
+
* same document was not.
|
|
562
|
+
*/
|
|
563
|
+
normalizeDiscriminatedBases(_ctx, args) {
|
|
564
|
+
// `normalizeSchema` runs once per property type via `shouldGenerateTypeDeclaration`, and almost no schema
|
|
565
|
+
// has a discriminated base anywhere below it. Answering that first costs one traversal and one set, and
|
|
566
|
+
// lets the overwhelmingly common case return the schema itself rather than a copy per composing schema.
|
|
567
|
+
//
|
|
568
|
+
// The question is asked once for the whole call rather than again per branch: a per-branch answer would
|
|
569
|
+
// have to be memoised to stay linear, and memoising it is unsound, because a walk truncated by the cycle
|
|
570
|
+
// guard can record `false` for a branch that reaches a base only by going back through an ancestor.
|
|
571
|
+
if (!containsDiscriminatedBase(args.schema, new Set()))
|
|
572
|
+
return args.schema;
|
|
573
|
+
const rewritten = new Map();
|
|
574
|
+
return rewrite(args.schema);
|
|
575
|
+
function rewrite(schema) {
|
|
576
|
+
const existing = rewritten.get(schema);
|
|
577
|
+
if (existing)
|
|
578
|
+
return existing;
|
|
579
|
+
const isBase = isDiscriminatedBase(schema);
|
|
580
|
+
const allOf = branches(schema, 'allOf');
|
|
581
|
+
const anyOf = branches(schema, 'anyOf');
|
|
582
|
+
// The branches of a discriminated `oneOf` are dropped rather than descended into: they are the schema's
|
|
583
|
+
// subtypes, and a subtype is generated from its own file where it is the root of this walk.
|
|
584
|
+
const oneOf = isBase ? [] : branches(schema, 'oneOf');
|
|
585
|
+
if (!isBase && allOf.length === 0 && anyOf.length === 0 && oneOf.length === 0) {
|
|
586
|
+
return schema;
|
|
587
|
+
}
|
|
588
|
+
// Registered before descending, so a branch composing back to one of its own ancestors terminates.
|
|
589
|
+
// deno-lint-ignore no-explicit-any
|
|
590
|
+
const copy = { ...schema };
|
|
591
|
+
rewritten.set(schema, copy);
|
|
592
|
+
if (isBase) {
|
|
593
|
+
copy.kind = 'object';
|
|
594
|
+
copy.type = 'object';
|
|
595
|
+
}
|
|
596
|
+
copy.allOf = allOf.map(rewrite);
|
|
597
|
+
copy.anyOf = anyOf.map(rewrite);
|
|
598
|
+
copy.oneOf = oneOf.map(rewrite);
|
|
599
|
+
return copy;
|
|
600
|
+
}
|
|
601
|
+
/** Whether the schema or anything it composes is a base this walk would rewrite. */
|
|
602
|
+
function containsDiscriminatedBase(schema, visited) {
|
|
603
|
+
if (visited.has(schema))
|
|
604
|
+
return false;
|
|
605
|
+
visited.add(schema);
|
|
606
|
+
if (isDiscriminatedBase(schema))
|
|
607
|
+
return true;
|
|
608
|
+
const contains = (x) => containsDiscriminatedBase(x, visited);
|
|
609
|
+
return branches(schema, 'allOf').some(contains) ||
|
|
610
|
+
branches(schema, 'anyOf').some(contains) ||
|
|
611
|
+
branches(schema, 'oneOf').some(contains);
|
|
612
|
+
}
|
|
613
|
+
function isDiscriminatedBase(schema) {
|
|
614
|
+
return schema.kind === 'oneOf' && schema.discriminator !== undefined;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* The branches a schema composes under one keyword. `normalizeSchema` leaves an explicit
|
|
618
|
+
* `oneOf: undefined` behind when it rewrites a `oneOf` holder, so a keyword can be present with no value.
|
|
619
|
+
*/
|
|
620
|
+
function branches(schema, keyword) {
|
|
621
|
+
var _a;
|
|
622
|
+
const values = schema;
|
|
623
|
+
return (_a = values[keyword]) !== null && _a !== void 0 ? _a : [];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
521
626
|
hasProperty(ctx, args) {
|
|
522
|
-
|
|
627
|
+
// A composition branch may compose back to one of its own ancestors (see test/specs/v3/anyof-cycle.yml).
|
|
628
|
+
// Without this guard such a cycle recurses until the stack overflows. Re-visiting a schema can never
|
|
629
|
+
// change the answer, so returning `false` for one is safe: another path either already found the
|
|
630
|
+
// property or does not contain it at all.
|
|
631
|
+
const { schema, propertyName, visited = new Set() } = args;
|
|
632
|
+
if (visited.has(schema))
|
|
633
|
+
return false;
|
|
634
|
+
visited.add(schema);
|
|
523
635
|
return (('properties' in schema && schema.properties.has(propertyName)) ||
|
|
524
|
-
('anyOf' in schema && schema.anyOf.some((schema) => this.hasProperty(ctx, { schema, propertyName }))) ||
|
|
525
|
-
('allOf' in schema && schema.allOf.some((schema) => this.hasProperty(ctx, { schema, propertyName })))
|
|
636
|
+
('anyOf' in schema && schema.anyOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))) ||
|
|
637
|
+
('allOf' in schema && schema.allOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))) ||
|
|
638
|
+
// Only an undiscriminated `oneOf` composes into the schema that references it, matching which `oneOf`
|
|
639
|
+
// branches `resolveAnyOfAndAllOf` merges. A discriminated one lists subtypes, whose properties are not
|
|
640
|
+
// the referencing schema's, so an inherited property never comes from there.
|
|
641
|
+
('oneOf' in schema && !schema.discriminator &&
|
|
642
|
+
schema.oneOf.some((schema) => this.hasProperty(ctx, { schema, propertyName, visited }))));
|
|
526
643
|
}
|
|
527
644
|
}
|
|
528
645
|
exports.DefaultKotlinModelGenerator = DefaultKotlinModelGenerator;
|
|
@@ -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":"okhttp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