@goast/kotlin 0.0.4 → 0.0.6
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.
|
@@ -51,6 +51,11 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
51
51
|
}
|
|
52
52
|
generateFileContent(ctx, builder) {
|
|
53
53
|
let schema = ctx.schema;
|
|
54
|
+
if (schema.kind === 'oneOf') {
|
|
55
|
+
schema = ctx.config.oneOfBehavior === 'treat-as-any-of'
|
|
56
|
+
? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
|
|
57
|
+
ctx.schema = schema;
|
|
58
|
+
}
|
|
54
59
|
if (schema.kind === 'object' || schema.kind === 'combined') {
|
|
55
60
|
const mergedSchema = (0, core_1.resolveAnyOfAndAllOf)(schema, true);
|
|
56
61
|
if (mergedSchema) {
|
|
@@ -130,7 +135,7 @@ class DefaultKotlinModelGenerator extends file_generator_1.KotlinFileGenerator {
|
|
|
130
135
|
.applyIf(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?').append(' = null')));
|
|
131
136
|
}
|
|
132
137
|
generateObjectDataClass(ctx, builder, schema) {
|
|
133
|
-
const inheritedSchemas = schema.inheritedSchemas.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated);
|
|
138
|
+
const inheritedSchemas = schema.inheritedSchemas.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated).filter((item, index, self) => self.indexOf(item) === index);
|
|
134
139
|
builder
|
|
135
140
|
.apply((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
136
141
|
.append('data class ')
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultKotlinModelsGeneratorConfig = void 0;
|
|
4
4
|
const config_1 = require("../../config");
|
|
5
|
-
exports.defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model' });
|
|
5
|
+
exports.defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, config_1.defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of' });
|
|
@@ -48,6 +48,11 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
48
48
|
}
|
|
49
49
|
generateFileContent(ctx, builder) {
|
|
50
50
|
let schema = ctx.schema;
|
|
51
|
+
if (schema.kind === 'oneOf') {
|
|
52
|
+
schema = ctx.config.oneOfBehavior === 'treat-as-any-of'
|
|
53
|
+
? Object.assign(Object.assign({}, schema), { kind: 'combined', anyOf: schema.oneOf, allOf: [], oneOf: undefined }) : Object.assign(Object.assign({}, schema), { kind: 'combined', allOf: schema.oneOf, anyOf: [], oneOf: undefined });
|
|
54
|
+
ctx.schema = schema;
|
|
55
|
+
}
|
|
51
56
|
if (schema.kind === 'object' || schema.kind === 'combined') {
|
|
52
57
|
const mergedSchema = resolveAnyOfAndAllOf(schema, true);
|
|
53
58
|
if (mergedSchema) {
|
|
@@ -127,7 +132,7 @@ export class DefaultKotlinModelGenerator extends KotlinFileGenerator {
|
|
|
127
132
|
.applyIf(!schema.required.has(property.name), (builder) => builder.appendIf(!property.schema.nullable, '?').append(' = null')));
|
|
128
133
|
}
|
|
129
134
|
generateObjectDataClass(ctx, builder, schema) {
|
|
130
|
-
const inheritedSchemas = schema.inheritedSchemas.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated);
|
|
135
|
+
const inheritedSchemas = schema.inheritedSchemas.filter((x) => this.shouldGenerateTypeDeclaration(ctx, x) && !x.isNameGenerated).filter((item, index, self) => self.indexOf(item) === index);
|
|
131
136
|
builder
|
|
132
137
|
.apply((builder) => this.generateDocumentation(ctx, builder, schema))
|
|
133
138
|
.append('data class ')
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { defaultKotlinGeneratorConfig } from '../../config';
|
|
2
|
-
export const defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model' });
|
|
2
|
+
export const defaultKotlinModelsGeneratorConfig = Object.assign(Object.assign({}, defaultKotlinGeneratorConfig), { packageName: 'com.openapi.generated', packageSuffix: '.model', oneOfBehavior: 'treat-as-any-of' });
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { KotlinGeneratorConfig } from '../../config';
|
|
|
4
4
|
export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
|
|
5
5
|
packageName: string;
|
|
6
6
|
packageSuffix: string;
|
|
7
|
+
oneOfBehavior: 'treat-as-any-of' | 'treat-as-all-of';
|
|
7
8
|
};
|
|
8
9
|
export declare const defaultKotlinModelsGeneratorConfig: DefaultGenerationProviderConfig<KotlinModelsGeneratorConfig>;
|
|
9
10
|
export type KotlinModelsGeneratorInput = {};
|