Skip to content

Commit de5302d

Browse files
author
rcatoio
committed
feat: add a parameter to disable type matching by content for unnamed types
1 parent 17c1251 commit de5302d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class CodeGenConfig {
7979
extractResponseError = false;
8080
extractResponses = false;
8181
extractEnums = false;
82+
doNotMatchUnnamedTypesByContent = false;
8283
fileNames = {
8384
dataContracts: "data-contracts",
8485
routeTypes: "route-types",

src/schema-routes/schema-routes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export class SchemaRoutes {
348348
operationId,
349349
defaultType,
350350
typeName,
351+
doNotMatchUnnamedTypesByContent,
351352
}) => {
352353
// TODO: make more flexible pick schema without content type
353354
const schema = this.getSchemaFromRequestType(requestInfo);
@@ -364,7 +365,7 @@ export class SchemaRoutes {
364365
(parsedSchema) =>
365366
this.typeNameFormatter.format(parsedSchema.name) === content,
366367
);
367-
const foundSchemaByContent = parsedSchemas.find((parsedSchema) =>
368+
const foundSchemaByContent = doNotMatchUnnamedTypesByContent ? null : parsedSchemas.find((parsedSchema) =>
368369
lodash.isEqual(parsedSchema.content, content),
369370
);
370371

@@ -412,6 +413,7 @@ export class SchemaRoutes {
412413
parsedSchemas,
413414
operationId,
414415
defaultType,
416+
doNotMatchUnnamedTypesByContent,
415417
}) =>
416418
lodash.reduce(
417419
requestInfos,
@@ -432,6 +434,7 @@ export class SchemaRoutes {
432434
parsedSchemas,
433435
operationId,
434436
defaultType,
437+
doNotMatchUnnamedTypesByContent,
435438
}),
436439
),
437440
description:
@@ -460,6 +463,7 @@ export class SchemaRoutes {
460463
parsedSchemas,
461464
operationId,
462465
defaultType: this.config.defaultResponseType,
466+
doNotMatchUnnamedTypesByContent: this.config.doNotMatchUnnamedTypesByContent,
463467
});
464468

465469
const successResponse = responseInfos.find(
@@ -538,7 +542,7 @@ export class SchemaRoutes {
538542
);
539543
};
540544

541-
getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) => {
545+
getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName, doNotMatchUnnamedTypesByContent) => {
542546
const { requestBody, consumes, requestBodyName, operationId } = routeInfo;
543547
let schema = null;
544548
let content = null;
@@ -583,6 +587,7 @@ export class SchemaRoutes {
583587
parsedSchemas,
584588
operationId,
585589
typeName,
590+
doNotMatchUnnamedTypesByContent,
586591
}),
587592
);
588593

@@ -943,6 +948,7 @@ export class SchemaRoutes {
943948
routeParams,
944949
parsedSchemas,
945950
routeName,
951+
this.config.doNotMatchUnnamedTypesByContent,
946952
);
947953

948954
const requestParamsSchema = this.createRequestParamsSchema({

0 commit comments

Comments
 (0)