diff --git a/src/parser/security.js b/src/parser/security.js index 9feceb9..b9eb7b8 100644 --- a/src/parser/security.js +++ b/src/parser/security.js @@ -57,7 +57,7 @@ export const parseSecurity = (operation, spec, securityHandlers) => { const blockHasMissingValues = Object.keys(block).some(name => readSchemeValue(name) == null); if (blockHasMissingValues) { - report.push({ schemes: {}, status: 'skipped' }); + report.push({ ok: false, schemes: {} }); continue; } diff --git a/src/parser/security.test.js b/src/parser/security.test.js index f0a896e..b4a37a9 100644 --- a/src/parser/security.test.js +++ b/src/parser/security.test.js @@ -364,12 +364,29 @@ describe('parseSecurity()', () => { const onRequest = parseSecurity(operation, spec, securityHandlers); - expect.assertions(2); + expect.assertions(3); await onRequest(request); expect(securityHandlers.ApiKey).not.toHaveBeenCalled(); expect(securityHandlers.OAuth2).toHaveBeenCalledTimes(1); + expect(request[DECORATOR_NAME].securityReport).toMatchInlineSnapshot(` + [ + { + "ok": false, + "schemes": {}, + }, + { + "ok": true, + "schemes": { + "OAuth2": { + "data": "OAuth2 data", + "ok": true, + }, + }, + }, + ] + `); }); it('should validate scopes', async () => { diff --git a/types/index.d.ts b/types/index.d.ts index 468a625..7c1aea5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7,8 +7,8 @@ declare module 'fastify' { interface FastifyRequest { [DECORATOR_NAME]: { operation: OpenAPI.OpenAPIV3_1.OperationObject, - security: RequestSecurity - securityReport: RequestSecurityReportEntry[] + security: SecurityData + securityReport: SecurityReport } } @@ -20,11 +20,13 @@ declare module 'fastify' { } } -export interface RequestSecurity { +export interface SecurityData { [key:string]: any } -export interface RequestSecurityReportEntry { +export type SecurityReport = SecurityReportBlock[] + +export interface SecurityReportBlock { ok: boolean schemes: { [key:string]: { @@ -35,13 +37,6 @@ export interface RequestSecurityReportEntry { } } -export interface RequestSecurityReportResult { - ok: boolean - schemes: { - [key:string]: RequestSecurityReportResult - } -} - export type SecurityHandler = (value: string, request: FastifyRequest) => SecurityHandlerReturn | undefined export interface SecurityHandlerReturn { data?: any, scopes?: string[] }