Skip to content

Commit

Permalink
getSecurity() to return an array of logical containers.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Jan 21, 2025
1 parent e3aaf56 commit 4ccd7de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { contentTypes } from "./content-type";
import { DocumentationError } from "./errors";
import { defaultInputSources, makeCleanId } from "./common-helpers";
import { CommonConfig } from "./config-type";
import { mapLogicalContainer } from "./logical-container";
import { combineContainers, mapLogicalContainer } from "./logical-container";
import { Method } from "./method";
import {
OpenAPIContext,
Expand Down Expand Up @@ -226,7 +226,14 @@ export class Documentation extends OpenApiBuilder {

const securityRefs = depictSecurityRefs(
mapLogicalContainer(
depictSecurity(endpoint.getSecurity(), inputSources),
depictSecurity(
endpoint
.getSecurity()
.reduce((acc, entry) => combineContainers(acc, entry), {
and: [],
}),
inputSources,
),
(securitySchema) => {
const name = this.ensureUniqSecuritySchemaName(securitySchema);
const scopes = ["oauth2", "openIdConnect"].includes(
Expand Down
14 changes: 5 additions & 9 deletions src/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { IOSchema } from "./io-schema";
import { lastResortHandler } from "./last-resort";
import { ActualLogger } from "./logger-helpers";
import { LogicalContainer, combineContainers } from "./logical-container";
import { LogicalContainer } from "./logical-container";
import { AuxMethod, Method } from "./method";
import { AbstractMiddleware, ExpressMiddleware } from "./middleware";
import { ContentType } from "./content-type";
Expand Down Expand Up @@ -49,7 +49,7 @@ export abstract class AbstractEndpoint extends Nesting {
public abstract getResponses(
variant: ResponseVariant,
): ReadonlyArray<NormalizedResponse>;
public abstract getSecurity(): LogicalContainer<Security>;
public abstract getSecurity(): LogicalContainer<Security>[];
public abstract getScopes(): ReadonlyArray<string>;
public abstract getTags(): ReadonlyArray<string>;
public abstract getOperationId(method: Method): string | undefined;
Expand Down Expand Up @@ -145,13 +145,9 @@ export class Endpoint<
}

public override getSecurity() {
return this.#middlewares.reduce<LogicalContainer<Security>>(
(acc, middleware) => {
const security = middleware.getSecurity();
return security ? combineContainers(acc, security) : acc;
},
{ and: [] },
);
return this.#middlewares
.map((middleware) => middleware.getSecurity())
.filter((entry) => entry !== undefined);
}

public override getScopes() {
Expand Down

0 comments on commit 4ccd7de

Please sign in to comment.