Skip to content

Commit e052452

Browse files
committed
refactor: part array type own parser (2)
1 parent 5466dba commit e052452

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/configuration.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ class CodeGenConfig {
294294
"relative-json-pointer": () => this.Ts.Keyword.String,
295295
regex: () => this.Ts.Keyword.String,
296296
},
297-
array: ({ items, ...schemaPart }, parser) => {
298-
const content = parser.getInlineParseContent(items);
299-
return parser.schemaUtils.safeAddNullToType(schemaPart, this.Ts.ArrayType(content));
300-
},
301297
};
302298

303299
templateInfos = [

src/schema-parser/base-schema-parsers/complex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ComplexSchemaParser extends MonoSchemaParser {
2222
this.config.Ts.IntersectionType(
2323
_.compact([
2424
this.config.Ts.ExpressionGroup(complexSchemaContent),
25-
this.schemaParser.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT &&
25+
this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT &&
2626
this.config.Ts.ExpressionGroup(this.schemaParser.getInlineParseContent(simpleSchema)),
2727
]),
2828
) || this.config.Ts.Keyword.Any,

src/schema-parser/schema-parser.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ class SchemaParser {
9999
},
100100
};
101101

102-
getInternalSchemaType = (schema) => {
103-
if (!_.isEmpty(schema.enum) || !_.isEmpty(this.schemaUtils.getEnumNames(schema))) return SCHEMA_TYPES.ENUM;
104-
if (schema.discriminator) return SCHEMA_TYPES.DISCRIMINATOR;
105-
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES.COMPLEX;
106-
if (!_.isEmpty(schema.properties)) return SCHEMA_TYPES.OBJECT;
107-
108-
return SCHEMA_TYPES.PRIMITIVE;
109-
};
110-
111102
/**
112103
*
113104
* @param schema {any}
@@ -133,7 +124,7 @@ class SchemaParser {
133124
if (schema.items && !Array.isArray(schema.items) && !schema.type) {
134125
schema.type = SCHEMA_TYPES.ARRAY;
135126
}
136-
schemaType = this.getInternalSchemaType(schema);
127+
schemaType = this.schemaUtils.getInternalSchemaType(schema);
137128

138129
this.schemaPath.push(...(schemaPath || []));
139130
this.schemaPath.push(typeName);

src/schema-parser/schema-utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ class SchemaUtils {
174174
return SCHEMA_TYPES.COMPLEX_UNKNOWN;
175175
};
176176

177+
getInternalSchemaType = (schema) => {
178+
if (!_.isEmpty(schema.enum) || !_.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES.ENUM;
179+
if (schema.discriminator) return SCHEMA_TYPES.DISCRIMINATOR;
180+
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES.COMPLEX;
181+
if (!_.isEmpty(schema.properties)) return SCHEMA_TYPES.OBJECT;
182+
if (schema.type === SCHEMA_TYPES.ARRAY) return SCHEMA_TYPES.ARRAY;
183+
184+
return SCHEMA_TYPES.PRIMITIVE;
185+
};
186+
177187
getSchemaType = (schema) => {
178188
if (!schema) return this.config.Ts.Keyword.Any;
179189

0 commit comments

Comments
 (0)