Skip to content

Commit 3677844

Browse files
committed
fix: build after refactoring
1 parent e052452 commit 3677844

File tree

10 files changed

+67
-40
lines changed

10 files changed

+67
-40
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class ComplexSchemaParser extends MonoSchemaParser {
2323
_.compact([
2424
this.config.Ts.ExpressionGroup(complexSchemaContent),
2525
this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT &&
26-
this.config.Ts.ExpressionGroup(this.schemaParser.getInlineParseContent(simpleSchema)),
26+
this.config.Ts.ExpressionGroup(
27+
this.schemaParser.getInlineParseContent(simpleSchema, null, this.schemaPath),
28+
),
2729
]),
2830
) || this.config.Ts.Keyword.Any,
2931
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
5656
const component = this.schemaComponentsMap.createComponent("schemas", mappingTypeName, {
5757
internal: true,
5858
});
59-
const schema = this.schemaParser.parseSchema(component);
59+
const schema = this.schemaParser.parseSchema(component, null, this.schemaPath);
6060
schema.genericArgs = [{ name: "Key" }, { name: "Type" }];
6161
schema.internal = true;
6262
schema.content = this.config.Ts.IntersectionType([
@@ -67,7 +67,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
6767
}
6868

6969
const createMappingContent = (mappingSchema, mappingKey) => {
70-
const content = this.schemaParser.getInlineParseContent(mappingSchema);
70+
const content = this.schemaParser.getInlineParseContent(mappingSchema, null, this.schemaPath);
7171

7272
if (ableToCreateMappingType) {
7373
return this.config.Ts.TypeWithGeneric(mappingTypeName, [this.config.Ts.StringValue(mappingKey), content]);
@@ -134,7 +134,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
134134
...schema,
135135
internal: true,
136136
});
137-
const content = this.schemaParser.getInlineParseContent(component);
137+
const content = this.schemaParser.getInlineParseContent(component, null, this.schemaPath);
138138

139139
return {
140140
typeName,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ class EnumSchemaParser extends MonoSchemaParser {
1515
const schemaComponent = this.schemaComponentsMap.createComponent("schemas", generatedTypeName, {
1616
...this.schema,
1717
});
18-
return this.schemaParser.parseSchema(schemaComponent, generatedTypeName);
18+
return this.schemaParser.parseSchema(schemaComponent, generatedTypeName, this.schemaPath);
1919
}
2020

2121
const refType = this.schemaUtils.getSchemaRefType(this.schema);
2222
const $ref = (refType && refType.$ref) || null;
2323

2424
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) {
25-
return this.parseSchema(
25+
return this.schemaParser.parseSchema(
2626
{
2727
oneOf: this.schema.enum.map((enumNames) => ({
2828
type: "array",
2929
items: enumNames.map((enumName) => ({ type: "string", enum: [enumName] })),
3030
})),
3131
},
3232
this.typeName,
33+
this.schemaPath,
3334
);
3435
}
3536

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ObjectSchemaParser extends MonoSchemaParser {
2929
const rawTypeData = _.get(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
3030
const nullable = !!(rawTypeData.nullable || property.nullable);
3131
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
32-
const fieldValue = this.schemaParser.getInlineParseContent(property);
32+
const fieldValue = this.schemaParser.getInlineParseContent(property, null, this.schemaPath);
3333
const readOnly = property.readOnly;
3434

3535
this.schemaPath.pop();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PrimitiveSchemaParser extends MonoSchemaParser {
99

1010
if (type === this.config.Ts.Keyword.Object && additionalProperties) {
1111
const fieldType = _.isObject(additionalProperties)
12-
? this.schemaParser.getInlineParseContent(additionalProperties)
12+
? this.schemaParser.getInlineParseContent(additionalProperties, null, this.schemaPath)
1313
: this.config.Ts.Keyword.Any;
1414
contentType = this.config.Ts.RecordType(this.config.Ts.Keyword.String, fieldType);
1515
}
@@ -22,7 +22,9 @@ class PrimitiveSchemaParser extends MonoSchemaParser {
2222
}
2323

2424
if (_.isArray(items) && type === SCHEMA_TYPES.ARRAY) {
25-
contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParser.getInlineParseContent(item)));
25+
contentType = this.config.Ts.Tuple(
26+
items.map((item) => this.schemaParser.getInlineParseContent(item, null, this.schemaPath)),
27+
);
2628
}
2729

2830
return {

src/schema-parser/complex-schema-parsers/all-of.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class AllOfSchemaParser extends MonoSchemaParser {
55
parse() {
66
const ignoreTypes = [...this.config.jsPrimitiveTypes, this.config.Ts.Keyword.Any];
77
const combined = _.map(this.schema.allOf, (childSchema) =>
8-
this.schemaParser.getInlineParseContent(this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema)),
8+
this.schemaParser.getInlineParseContent(
9+
this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema),
10+
null,
11+
this.schemaPath,
12+
),
913
);
1014
const filtered = this.schemaUtils.filterSchemaContents(combined, (content) => !ignoreTypes.includes(content));
1115

src/schema-parser/complex-schema-parsers/any-of.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class AnyOfSchemaParser extends MonoSchemaParser {
55
parse() {
66
const ignoreTypes = [...this.config.jsPrimitiveTypes, this.config.Ts.Keyword.Any];
77
const combined = _.map(this.schema.anyOf, (childSchema) =>
8-
this.schemaParser.getInlineParseContent(this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema)),
8+
this.schemaParser.getInlineParseContent(
9+
this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema),
10+
null,
11+
this.schemaPath,
12+
),
913
);
1014
const filtered = this.schemaUtils.filterSchemaContents(combined, (content) => !ignoreTypes.includes(content));
1115

src/schema-parser/complex-schema-parsers/one-of.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ class OneOfSchemaParser extends MonoSchemaParser {
55
parse() {
66
const ignoreTypes = [this.config.Ts.Keyword.Any];
77
const combined = _.map(this.schema.oneOf, (childSchema) =>
8-
this.schemaParser.getInlineParseContent(this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema)),
8+
this.schemaParser.getInlineParseContent(
9+
this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema),
10+
null,
11+
this.schemaPath,
12+
),
913
);
1014
const filtered = this.schemaUtils.filterSchemaContents(combined, (content) => !ignoreTypes.includes(content));
1115

src/schema-parser/schema-parser.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ class SchemaParser {
5353
complexSchemaParsers = {
5454
// T1 | T2
5555
[SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => {
56-
const schemaParser = new OneOfSchemaParser(this, schema);
56+
const schemaParser = new OneOfSchemaParser(this, schema, null);
5757
return schemaParser.parse();
5858
},
5959
// T1 & T2
6060
[SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => {
61-
const schemaParser = new AllOfSchemaParser(this, schema);
61+
const schemaParser = new AllOfSchemaParser(this, schema, null);
6262
return schemaParser.parse();
6363
},
6464
// T1 | T2 | (T1 & T2)
6565
[SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => {
66-
const schemaParser = new AnyOfSchemaParser(this, schema);
66+
const schemaParser = new AnyOfSchemaParser(this, schema, null);
6767
return schemaParser.parse();
6868
},
6969
[SCHEMA_TYPES.COMPLEX_NOT]: (schema) => {
70-
const schemaParser = new NotSchemaParser(this, schema);
70+
const schemaParser = new NotSchemaParser(this, schema, null);
7171
return schemaParser.parse();
7272
},
7373
};
@@ -126,7 +126,7 @@ class SchemaParser {
126126
}
127127
schemaType = this.schemaUtils.getInternalSchemaType(schema);
128128

129-
this.schemaPath.push(...(schemaPath || []));
129+
this.schemaPath = [...(schemaPath || [])];
130130
this.schemaPath.push(typeName);
131131

132132
_.merge(schema, this.config.hooks.onPreParseSchema(schema, typeName, schemaType));
@@ -140,15 +140,13 @@ class SchemaParser {
140140
};
141141

142142
getInlineParseContent = (rawTypeData, typeName, schemaPath) => {
143-
this.schemaPath.push(...(schemaPath || []));
144-
const parsedSchema = this.parseSchema(rawTypeData, typeName);
143+
const parsedSchema = this.parseSchema(rawTypeData, typeName, schemaPath);
145144
const formattedSchema = this.schemaFormatters.formatSchema(parsedSchema, "inline");
146145
return formattedSchema.content;
147146
};
148147

149148
getParseContent = (rawTypeData, typeName, schemaPath) => {
150-
this.schemaPath.push(...(schemaPath || []));
151-
const parsedSchema = this.parseSchema(rawTypeData, typeName);
149+
const parsedSchema = this.parseSchema(rawTypeData, typeName, schemaPath);
152150
const formattedSchema = this.schemaFormatters.formatSchema(parsedSchema, "base");
153151
return formattedSchema.content;
154152
};

src/schema-parser/schema-routes.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ class SchemaRoutes {
606606
if (successResponse.schema && !successResponse.schema.$ref) {
607607
const schema = this.getSchemaFromRequestType(successResponse.schema);
608608
successResponse.schema = this.schemaComponentMap.createComponent("schemas", typeName, { ...schema });
609-
successResponse.type = this.schemaParser.getInlineParseContent(successResponse.schema, [routeInfo.open]);
609+
successResponse.type = this.schemaParser.getInlineParseContent(successResponse.schema, null, [
610+
routeInfo.operationId,
611+
]);
610612

611613
if (idx > -1) {
612614
_.assign(responseBodyInfo.responses[idx], {
@@ -630,17 +632,21 @@ class SchemaRoutes {
630632

631633
if (!errorSchemas.length) return;
632634

633-
const schema = this.schemaParser.parseSchema({
634-
oneOf: errorSchemas,
635-
title: errorSchemas
636-
.map((schema) => schema.title)
637-
.filter(Boolean)
638-
.join(" "),
639-
description: errorSchemas
640-
.map((schema) => schema.description)
641-
.filter(Boolean)
642-
.join("\n"),
643-
});
635+
const schema = this.schemaParser.parseSchema(
636+
{
637+
oneOf: errorSchemas,
638+
title: errorSchemas
639+
.map((schema) => schema.title)
640+
.filter(Boolean)
641+
.join(" "),
642+
description: errorSchemas
643+
.map((schema) => schema.description)
644+
.filter(Boolean)
645+
.join("\n"),
646+
},
647+
null,
648+
[routeInfo.operationId],
649+
);
644650
const component = this.schemaComponentMap.createComponent("schemas", typeName, { ...schema });
645651
responseBodyInfo.error.schemas = [component];
646652
responseBodyInfo.error.type = this.typeNameFormatter.format(component.typeName);
@@ -723,7 +729,7 @@ class SchemaRoutes {
723729
const pathArgs = routeParams.path.map((pathArgSchema) => ({
724730
name: pathArgSchema.name,
725731
optional: !pathArgSchema.required,
726-
type: this.schemaParser.getInlineParseContent(pathArgSchema.schema),
732+
type: this.schemaParser.getInlineParseContent(pathArgSchema.schema, null, [operationId]),
727733
description: pathArgSchema.description,
728734
}));
729735
const pathArgsNames = pathArgs.map((arg) => arg.name);
@@ -770,17 +776,23 @@ class SchemaRoutes {
770776
this.extractResponseErrorIfItNeeded(routeInfo, responseBodyInfo, routeName);
771777
}
772778

773-
const queryType = routeParams.query.length ? this.schemaParser.getInlineParseContent(queryObjectSchema) : null;
774-
const pathType = routeParams.path.length ? this.schemaParser.getInlineParseContent(pathObjectSchema) : null;
775-
const headersType = routeParams.header.length ? this.schemaParser.getInlineParseContent(headersObjectSchema) : null;
779+
const queryType = routeParams.query.length
780+
? this.schemaParser.getInlineParseContent(queryObjectSchema, null, [operationId])
781+
: null;
782+
const pathType = routeParams.path.length
783+
? this.schemaParser.getInlineParseContent(pathObjectSchema, null, [operationId])
784+
: null;
785+
const headersType = routeParams.header.length
786+
? this.schemaParser.getInlineParseContent(headersObjectSchema, null, [operationId])
787+
: null;
776788

777789
const nameResolver = new SpecificArgNameResolver(this.logger, pathArgsNames);
778790

779791
const specificArgs = {
780792
query: queryType
781793
? {
782794
name: nameResolver.resolve(RESERVED_QUERY_ARG_NAMES),
783-
optional: this.schemaParser.parseSchema(queryObjectSchema).allFieldsAreOptional,
795+
optional: this.schemaParser.parseSchema(queryObjectSchema, null, [operationId]).allFieldsAreOptional,
784796
type: queryType,
785797
}
786798
: void 0,
@@ -794,14 +806,14 @@ class SchemaRoutes {
794806
pathParams: pathType
795807
? {
796808
name: nameResolver.resolve(RESERVED_PATH_ARG_NAMES),
797-
optional: this.schemaParser.parseSchema(pathObjectSchema).allFieldsAreOptional,
809+
optional: this.schemaParser.parseSchema(pathObjectSchema, null, [operationId]).allFieldsAreOptional,
798810
type: pathType,
799811
}
800812
: void 0,
801813
headers: headersType
802814
? {
803815
name: nameResolver.resolve(RESERVED_HEADER_ARG_NAMES),
804-
optional: this.schemaParser.parseSchema(headersObjectSchema).allFieldsAreOptional,
816+
optional: this.schemaParser.parseSchema(headersObjectSchema, null, [operationId]).allFieldsAreOptional,
805817
type: headersType,
806818
}
807819
: void 0,

0 commit comments

Comments
 (0)