mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-14 18:22:31 +03:00
fix: filter out non-existing security schemas + warn
This commit is contained in:
parent
dead16199f
commit
ee822f6ebe
|
@ -2,26 +2,36 @@ import { OpenAPISecurityRequirement } from '../../types';
|
||||||
import { SECURITY_SCHEMES_SECTION } from '../../utils/openapi';
|
import { SECURITY_SCHEMES_SECTION } from '../../utils/openapi';
|
||||||
import { OpenAPIParser } from '../OpenAPIParser';
|
import { OpenAPIParser } from '../OpenAPIParser';
|
||||||
|
|
||||||
|
interface SecurityScheme {
|
||||||
|
id: string;
|
||||||
|
sectionId: string;
|
||||||
|
type: string;
|
||||||
|
scopes: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class SecurityRequirementModel {
|
export class SecurityRequirementModel {
|
||||||
schemes: Array<{
|
schemes: SecurityScheme[];
|
||||||
id: string;
|
|
||||||
sectionId: string;
|
|
||||||
type: string;
|
|
||||||
scopes: string[];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
constructor(requirement: OpenAPISecurityRequirement, parser: OpenAPIParser) {
|
constructor(requirement: OpenAPISecurityRequirement, parser: OpenAPIParser) {
|
||||||
const schemes = (parser.spec.components && parser.spec.components.securitySchemes) || {};
|
const schemes = (parser.spec.components && parser.spec.components.securitySchemes) || {};
|
||||||
|
|
||||||
this.schemes = Object.keys(requirement || {}).map(id => {
|
this.schemes = Object.keys(requirement || {})
|
||||||
const scheme = parser.deref(schemes[id]);
|
.map(id => {
|
||||||
const scopes = requirement[id] || [];
|
const scheme = parser.deref(schemes[id]);
|
||||||
return {
|
const scopes = requirement[id] || [];
|
||||||
id,
|
|
||||||
sectionId: SECURITY_SCHEMES_SECTION + id,
|
if (!scheme) {
|
||||||
type: scheme.type,
|
console.warn(`Non existing security scheme referenced: ${id}. Skipping`);
|
||||||
scopes,
|
return null;
|
||||||
};
|
}
|
||||||
});
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
sectionId: SECURITY_SCHEMES_SECTION + id,
|
||||||
|
type: scheme.type,
|
||||||
|
scopes,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(scheme => scheme !== undefined) as SecurityScheme[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user