Skip to content

Commit

Permalink
refactor(): simplify filter condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jul 8, 2021
1 parent dec5c0c commit e7e2451
Showing 1 changed file with 58 additions and 58 deletions.
116 changes: 58 additions & 58 deletions lib/swagger-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,66 +126,66 @@ export class SwaggerExplorer {
const ctrlExtraModels = exploreGlobalApiExtraModelsMetadata(metatype);
this.registerExtraModels(ctrlExtraModels);

const denormalizedPaths = this.metadataScanner.scanFromPrototype<
any,
DenormalizedDoc
>(instance, prototype, (name) => {
const targetCallback = prototype[name];
const excludeEndpoint = exploreApiExcludeEndpointMetadata(
instance,
prototype,
targetCallback
);
if (excludeEndpoint && excludeEndpoint.disable) {
return;
}
const ctrlExtraModels = exploreApiExtraModelsMetadata(
instance,
prototype,
targetCallback
);
this.registerExtraModels(ctrlExtraModels);
const denormalizedPaths = this.metadataScanner
.scanFromPrototype<any, DenormalizedDoc>(instance, prototype, (name) => {
const targetCallback = prototype[name];
const excludeEndpoint = exploreApiExcludeEndpointMetadata(
instance,
prototype,
targetCallback
);
if (excludeEndpoint && excludeEndpoint.disable) {
return;
}
const ctrlExtraModels = exploreApiExtraModelsMetadata(
instance,
prototype,
targetCallback
);
this.registerExtraModels(ctrlExtraModels);

const methodMetadata = mapValues(documentResolvers, (explorers: any[]) =>
explorers.reduce((metadata, fn) => {
const exploredMetadata = fn.call(
self,
instance,
prototype,
targetCallback,
metatype,
globalPrefix,
modulePath,
applicationConfig
);
if (!exploredMetadata) {
return metadata;
}
if (!isArray(exploredMetadata)) {
return { ...metadata, ...exploredMetadata };
}
return isArray(metadata)
? [...metadata, ...exploredMetadata]
: exploredMetadata;
}, {})
);
const mergedMethodMetadata = this.mergeMetadata(
globalMetadata,
omitBy(methodMetadata, isEmpty)
);
const methodMetadata = mapValues(
documentResolvers,
(explorers: any[]) =>
explorers.reduce((metadata, fn) => {
const exploredMetadata = fn.call(
self,
instance,
prototype,
targetCallback,
metatype,
globalPrefix,
modulePath,
applicationConfig
);
if (!exploredMetadata) {
return metadata;
}
if (!isArray(exploredMetadata)) {
return { ...metadata, ...exploredMetadata };
}
return isArray(metadata)
? [...metadata, ...exploredMetadata]
: exploredMetadata;
}, {})
);
const mergedMethodMetadata = this.mergeMetadata(
globalMetadata,
omitBy(methodMetadata, isEmpty)
);

return this.migrateOperationSchema(
{
responses: {},
...omit(globalMetadata, 'chunks'),
...mergedMethodMetadata
},
prototype,
targetCallback
);
})
.filter((path) => path.root?.path);

return this.migrateOperationSchema(
{
responses: {},
...omit(globalMetadata, 'chunks'),
...mergedMethodMetadata
},
prototype,
targetCallback
);
}).filter((path) => {
return path.root !== undefined && path.root.path !== undefined;
});
return denormalizedPaths;
}

Expand Down

0 comments on commit e7e2451

Please sign in to comment.