Skip to content

Commit 428056a

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

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
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: 9 additions & 4 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,12 +365,11 @@ 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

371372
const foundSchema = foundedSchemaByName || foundSchemaByContent;
372-
373373
return foundSchema
374374
? this.typeNameFormatter.format(foundSchema.name)
375375
: content;
@@ -412,6 +412,7 @@ export class SchemaRoutes {
412412
parsedSchemas,
413413
operationId,
414414
defaultType,
415+
doNotMatchUnnamedTypesByContent,
415416
}) =>
416417
lodash.reduce(
417418
requestInfos,
@@ -432,6 +433,7 @@ export class SchemaRoutes {
432433
parsedSchemas,
433434
operationId,
434435
defaultType,
436+
doNotMatchUnnamedTypesByContent,
435437
}),
436438
),
437439
description:
@@ -460,6 +462,7 @@ export class SchemaRoutes {
460462
parsedSchemas,
461463
operationId,
462464
defaultType: this.config.defaultResponseType,
465+
doNotMatchUnnamedTypesByContent: this.config.doNotMatchUnnamedTypesByContent,
463466
});
464467

465468
const successResponse = responseInfos.find(
@@ -538,7 +541,7 @@ export class SchemaRoutes {
538541
);
539542
};
540543

541-
getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) => {
544+
getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName, doNotMatchUnnamedTypesByContent) => {
542545
const { requestBody, consumes, requestBodyName, operationId } = routeInfo;
543546
let schema = null;
544547
let content = null;
@@ -583,6 +586,7 @@ export class SchemaRoutes {
583586
parsedSchemas,
584587
operationId,
585588
typeName,
589+
doNotMatchUnnamedTypesByContent,
586590
}),
587591
);
588592

@@ -943,6 +947,7 @@ export class SchemaRoutes {
943947
routeParams,
944948
parsedSchemas,
945949
routeName,
950+
this.config.doNotMatchUnnamedTypesByContent,
946951
);
947952

948953
const requestParamsSchema = this.createRequestParamsSchema({
@@ -1098,7 +1103,7 @@ export class SchemaRoutes {
10981103

10991104
for (const [rawRouteName, routeInfoByMethodsMap] of pathsEntries) {
11001105
const routeInfosMap = this.createRequestsMap(routeInfoByMethodsMap);
1101-
1106+
11021107
for (const [method, routeInfo] of Object.entries(routeInfosMap)) {
11031108
const parsedRouteInfo = this.parseRouteInfo(
11041109
rawRouteName,

0 commit comments

Comments
 (0)