@goast/typescript 0.2.4 → 0.2.5
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.
|
@@ -41,7 +41,7 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
41
41
|
content.values.push(this.getEnum(ctx));
|
|
42
42
|
}
|
|
43
43
|
else if (ctx.schema.discriminator && Object.keys(ctx.schema.discriminator.mapping).length > 0) {
|
|
44
|
-
content.values.push(ast_1.ts.typeAlias(this.getDiscriminatorTypeName(ctx, ctx.schema), ast_1.ts.unionType(Object.keys(ctx.schema.discriminator.mapping).map((x) => ast_1.ts.string(x)))), ast_1.ts.typeAlias(this.getBaseTypeName(ctx, ctx.schema), (_a = this.getType(ctx, ctx.schema, true)) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), { export: true }), this.getTypeAlias(ctx, ctx.schema));
|
|
44
|
+
content.values.push(ast_1.ts.typeAlias(this.getDiscriminatorTypeName(ctx, ctx.schema), ast_1.ts.unionType(Object.keys(ctx.schema.discriminator.mapping).map((x) => ast_1.ts.string(x)))), ast_1.ts.typeAlias(this.getBaseTypeName(ctx, ctx.schema), (_a = this.getType(ctx, ctx.schema, { skipSchemas: true })) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), { export: true }), this.getTypeAlias(ctx, ctx.schema));
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
content.values.push(this.getTypeAlias(ctx, ctx.schema));
|
|
@@ -65,7 +65,7 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
65
65
|
getTypeAlias(ctx, schema) {
|
|
66
66
|
var _a;
|
|
67
67
|
const isDiscriminated = schema.discriminator && Object.keys(schema.discriminator.mapping).length > 0;
|
|
68
|
-
const result = ast_1.ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (isDiscriminated ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, true))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
|
|
68
|
+
const result = ast_1.ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (isDiscriminated ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, { skipSchemas: true }))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
|
|
69
69
|
export: true,
|
|
70
70
|
doc: ast_1.ts.doc({ description: schema.description }),
|
|
71
71
|
});
|
|
@@ -94,14 +94,14 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
getType(ctx, schema,
|
|
97
|
+
getType(ctx, schema, options) {
|
|
98
98
|
if (!schema)
|
|
99
99
|
return this.getAnyType(ctx);
|
|
100
100
|
schema = (0, core_1.getSchemaReference)(schema, ['description']);
|
|
101
|
-
if (ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
|
|
101
|
+
if ((options === null || options === void 0 ? void 0 : options.useBaseType) && ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
|
|
102
102
|
return ast_1.ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema));
|
|
103
103
|
}
|
|
104
|
-
if (!skipSchemas && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
104
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
105
105
|
if (schema.id === ctx.schema.id) {
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
@@ -178,9 +178,10 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
178
178
|
if (schema.allOf.length === 0 && schema.anyOf.length === 0) {
|
|
179
179
|
return this.getAnyType(ctx);
|
|
180
180
|
}
|
|
181
|
+
const useBaseType = schema.id === ctx.schema.id;
|
|
181
182
|
return ast_1.ts.intersectionType([
|
|
182
|
-
...schema.allOf.map((x) => this.getType(ctx, x)),
|
|
183
|
-
...schema.anyOf.map((x) => ast_1.ts.reference('Partial', null, { generics: [this.getType(ctx, x)] })),
|
|
183
|
+
...schema.allOf.map((x) => this.getType(ctx, x, { useBaseType })),
|
|
184
|
+
...schema.anyOf.map((x) => ast_1.ts.reference('Partial', null, { generics: [this.getType(ctx, x, { useBaseType })] })),
|
|
184
185
|
]);
|
|
185
186
|
}
|
|
186
187
|
getOneOfType(ctx, schema) {
|
|
@@ -38,7 +38,7 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
38
38
|
content.values.push(this.getEnum(ctx));
|
|
39
39
|
}
|
|
40
40
|
else if (ctx.schema.discriminator && Object.keys(ctx.schema.discriminator.mapping).length > 0) {
|
|
41
|
-
content.values.push(ts.typeAlias(this.getDiscriminatorTypeName(ctx, ctx.schema), ts.unionType(Object.keys(ctx.schema.discriminator.mapping).map((x) => ts.string(x)))), ts.typeAlias(this.getBaseTypeName(ctx, ctx.schema), (_a = this.getType(ctx, ctx.schema, true)) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), { export: true }), this.getTypeAlias(ctx, ctx.schema));
|
|
41
|
+
content.values.push(ts.typeAlias(this.getDiscriminatorTypeName(ctx, ctx.schema), ts.unionType(Object.keys(ctx.schema.discriminator.mapping).map((x) => ts.string(x)))), ts.typeAlias(this.getBaseTypeName(ctx, ctx.schema), (_a = this.getType(ctx, ctx.schema, { skipSchemas: true })) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), { export: true }), this.getTypeAlias(ctx, ctx.schema));
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
content.values.push(this.getTypeAlias(ctx, ctx.schema));
|
|
@@ -62,7 +62,7 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
62
62
|
getTypeAlias(ctx, schema) {
|
|
63
63
|
var _a;
|
|
64
64
|
const isDiscriminated = schema.discriminator && Object.keys(schema.discriminator.mapping).length > 0;
|
|
65
|
-
const result = ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (isDiscriminated ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, true))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
|
|
65
|
+
const result = ts.typeAlias(this.getDeclarationTypeName(ctx, schema), (_a = (isDiscriminated ? this.getDiscriminatorType(ctx, schema) : this.getType(ctx, schema, { skipSchemas: true }))) !== null && _a !== void 0 ? _a : this.getAnyType(ctx), {
|
|
66
66
|
export: true,
|
|
67
67
|
doc: ts.doc({ description: schema.description }),
|
|
68
68
|
});
|
|
@@ -91,14 +91,14 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
getType(ctx, schema,
|
|
94
|
+
getType(ctx, schema, options) {
|
|
95
95
|
if (!schema)
|
|
96
96
|
return this.getAnyType(ctx);
|
|
97
97
|
schema = getSchemaReference(schema, ['description']);
|
|
98
|
-
if (ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
|
|
98
|
+
if ((options === null || options === void 0 ? void 0 : options.useBaseType) && ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
|
|
99
99
|
return ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema));
|
|
100
100
|
}
|
|
101
|
-
if (!skipSchemas && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
101
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
102
102
|
if (schema.id === ctx.schema.id) {
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
@@ -175,9 +175,10 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
175
175
|
if (schema.allOf.length === 0 && schema.anyOf.length === 0) {
|
|
176
176
|
return this.getAnyType(ctx);
|
|
177
177
|
}
|
|
178
|
+
const useBaseType = schema.id === ctx.schema.id;
|
|
178
179
|
return ts.intersectionType([
|
|
179
|
-
...schema.allOf.map((x) => this.getType(ctx, x)),
|
|
180
|
-
...schema.anyOf.map((x) => ts.reference('Partial', null, { generics: [this.getType(ctx, x)] })),
|
|
180
|
+
...schema.allOf.map((x) => this.getType(ctx, x, { useBaseType })),
|
|
181
|
+
...schema.anyOf.map((x) => ts.reference('Partial', null, { generics: [this.getType(ctx, x, { useBaseType })] })),
|
|
181
182
|
]);
|
|
182
183
|
}
|
|
183
184
|
getOneOfType(ctx, schema) {
|
package/package.json
CHANGED
|
@@ -17,7 +17,10 @@ export declare class DefaultTypeScriptModelGenerator extends TypeScriptFileGener
|
|
|
17
17
|
protected getTypeAlias(ctx: Context, schema: ApiSchema): ts.TypeAlias<Builder>;
|
|
18
18
|
protected getIndexer(ctx: Context, schema: ObjectLikeApiSchema): ts.Indexer<Builder, never> | null;
|
|
19
19
|
protected getProperties(ctx: Context, schema: ObjectLikeApiSchema): (import("../../ast/nodes/property").TsAccessorProperty<Builder, ""> | import("../../ast/nodes/property").TsSimpleProperty<Builder, "">)[];
|
|
20
|
-
protected getType(ctx: Context, schema: Nullable<ApiSchema>,
|
|
20
|
+
protected getType(ctx: Context, schema: Nullable<ApiSchema>, options?: {
|
|
21
|
+
skipSchemas?: boolean;
|
|
22
|
+
useBaseType?: boolean;
|
|
23
|
+
}): ts.Type<Builder> | null;
|
|
21
24
|
protected getArrayType(ctx: Context, schema: ArrayLikeApiSchema): ts.Type<Builder>;
|
|
22
25
|
protected getObjectType(ctx: Context, schema: ObjectLikeApiSchema): ts.Type<Builder>;
|
|
23
26
|
protected getDiscriminatorType(ctx: Context, schema: ApiSchema): ts.Type<Builder>;
|