Skip to content

Commit

Permalink
Address additional PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
deongroenewald committed Aug 4, 2023
1 parent 4731336 commit 7cbe0ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/interfaces/swagger-document-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type OperationIdFactory = (
controllerKey: string,
methodKey: string,
pathVersionKey?: string
version?: string
) => string;

export interface SwaggerDocumentOptions {
Expand Down
49 changes: 30 additions & 19 deletions lib/swagger-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,28 +275,17 @@ export class SwaggerExplorer {
VERSION_METADATA,
method
);
const versioningOptions = applicationConfig.getVersioning();
const controllerVersion = this.getVersionMetadata(
metatype,
applicationConfig.getVersioning()
versioningOptions
);

const versionOrVersions = methodVersion ?? controllerVersion;
let versions: string[] = [];
if (!!versionOrVersions) {
if (Array.isArray(versionOrVersions)) {
versions = versionOrVersions.filter(
(v) => v !== VERSION_NEUTRAL
) as string[];
} else if (versionOrVersions !== VERSION_NEUTRAL) {
versions = [versionOrVersions];
}

const versionConfig = applicationConfig.getVersioning();
if (versionConfig?.type == VersioningType.URI) {
const prefix = this.routePathFactory.getVersionPrefix(versionConfig);
versions = versions.map((v) => `${prefix}${v}`);
}
}
const versions = this.getRoutePathVersions(
versionOrVersions,
versioningOptions
);

const allRoutePaths = this.routePathFactory.create(
{
Expand Down Expand Up @@ -346,15 +335,37 @@ export class SwaggerExplorer {
private getOperationId(
instance: object,
method: Function,
pathVersion?: string
version?: string
): string {
return this.operationIdFactory(
instance.constructor?.name || '',
method.name,
pathVersion
version
);
}

private getRoutePathVersions(
versionValue?: VersionValue,
versioningOptions?: VersioningOptions
) {
let versions: string[] = [];

if (!versionValue || versioningOptions?.type !== VersioningType.URI) {
return versions;
}

if (Array.isArray(versionValue)) {
versions = versionValue.filter((v) => v !== VERSION_NEUTRAL) as string[];
} else if (versionValue !== VERSION_NEUTRAL) {
versions = [versionValue];
}

const prefix = this.routePathFactory.getVersionPrefix(versioningOptions);
versions = versions.map((v) => `${prefix}${v}`);

return versions;
}

private reflectControllerPath(metatype: Type<unknown>): string {
return Reflect.getMetadata(PATH_METADATA, metatype);
}
Expand Down

0 comments on commit 7cbe0ef

Please sign in to comment.