mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
fix: make error optional parameter for SwaggerToolsSecurityHandler callback
This commit is contained in:
parent
510f81374c
commit
0b594f46b9
13
types/swagger-node-runner/index.d.ts
vendored
13
types/swagger-node-runner/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for swagger-node-runner 0.5
|
||||
// Type definitions for swagger-node-runner 0.6
|
||||
// Project: https://www.npmjs.com/package/swagger-node-runner
|
||||
// Definitions by: Michael Mrowetz <https://github.com/micmro>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@ -36,6 +36,7 @@ import { Spec } from "swagger-schema-official";
|
||||
import { EventEmitter } from "events";
|
||||
import * as Hapi from "hapi";
|
||||
import * as Restify from "restify";
|
||||
import { OutgoingHttpHeaders } from "http";
|
||||
|
||||
/**
|
||||
* Config object for SwaggerNodeRunner
|
||||
@ -117,12 +118,18 @@ export type SwaggerToolsMiddleware = (req: any, res: any, next: any) => any;
|
||||
|
||||
/**
|
||||
* @param callback - Error is returned if request is unauthorized.
|
||||
* The Error may include "message", "state", and "code" fields to be conveyed to the client in the response body and a
|
||||
* The Error may include "message", and "code" fields to be conveyed to the client in the response body and a
|
||||
* "headers" field containing an object representing headers to be set on the response to the client.
|
||||
* In addition, if the Error has a statusCode field, the response statusCode will be set to match -
|
||||
* otherwise, the statusCode will be set to 403.
|
||||
*/
|
||||
export type SwaggerToolsSecurityHandler = (request: any, securityDefinition: any, scopes: any, callback: (err: Error) => void) => void;
|
||||
export interface SwaggerToolsSecurityHandlerCallbackError {
|
||||
code?: string;
|
||||
headers?: OutgoingHttpHeaders;
|
||||
message?: string;
|
||||
statusCode?: number;
|
||||
}
|
||||
export type SwaggerToolsSecurityHandler = (request: any, securityDefinition: any, scopes: any, callback: (err?: Error | SwaggerToolsSecurityHandlerCallbackError, result?: any) => void) => void;
|
||||
|
||||
/**
|
||||
* The keys match SecurityDefinition names and the associated values are functions that accept the following parameters:
|
||||
|
||||
@ -84,7 +84,7 @@ SwaggerNodeRunner.create(config, (err, runner) => {
|
||||
app.listen(port);
|
||||
});
|
||||
|
||||
const swaggerSecurityHandlerCb = (err: Error) => {
|
||||
const swaggerSecurityHandlerCb = (err?: Error) => {
|
||||
// do nothing
|
||||
};
|
||||
|
||||
@ -98,7 +98,34 @@ const configComplex: SwaggerNodeRunner.Config = {
|
||||
swaggerSecurityHandlers: {
|
||||
// did not manage to research the typings of first 3 arguments
|
||||
someHandlerName: ({}, {}, {}, swaggerSecurityHandlerCb) => {
|
||||
// do nothing
|
||||
swaggerSecurityHandlerCb(new Error('foo'));
|
||||
}
|
||||
},
|
||||
validateResponse: true
|
||||
};
|
||||
|
||||
const handlerWithoutError: SwaggerNodeRunner.Config = {
|
||||
appRoot: __dirname,
|
||||
swaggerSecurityHandlers: {
|
||||
// did not manage to research the typings of first 3 arguments
|
||||
someHandlerName: ({}, {}, {}, swaggerSecurityHandlerCb) => {
|
||||
swaggerSecurityHandlerCb();
|
||||
}
|
||||
},
|
||||
validateResponse: true
|
||||
};
|
||||
|
||||
const handlerWithHeaders: SwaggerNodeRunner.Config = {
|
||||
appRoot: __dirname,
|
||||
swaggerSecurityHandlers: {
|
||||
// did not manage to research the typings of first 3 arguments
|
||||
someHandlerName: ({}, {}, {}, swaggerSecurityHandlerCb) => {
|
||||
swaggerSecurityHandlerCb({
|
||||
headers: {
|
||||
foo: 'bar',
|
||||
baz: 2,
|
||||
some: ['a', 'b'],
|
||||
}});
|
||||
}
|
||||
},
|
||||
validateResponse: true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user