Methods
resolved an api specification to local source files and exported method handlers
Parameters:
| Name |
Type |
Description |
options |
Object
|
Properties
| Name |
Type |
Description |
basePath |
string
|
base filename to look for controllers to match with the api spec |
|
- Source:
Throws:
Error in case that a controller or method could not be resolved
Returns:
express callback handler
-
Type
-
ExpressHandler
router(options) → {Object}
initializes an express router object with routes as defined by the passed open api 3.0.x specification
Parameters:
| Name |
Type |
Description |
options |
RouterConfiguration
|
configuration for the middleware. only `specification` is required if the defaults suit your needs |
- Source:
Throws:
-
TypeError if an invalid configuration option has been passed to this function
-
forwards additional thrown exceptions to the caller, depending on the resolver used and the configured error handler
Returns:
an express router middleware
-
Type
-
Object
Type Definitions
ExpressHandler(req, res, next)
Parameters:
| Name |
Type |
Description |
req |
Object
|
the http request object |
res |
Object
|
the http response object |
next |
Next
|
a continuation function |
- Source:
Next()
- Source:
Resolver(path, method, options) → {ExpressHandler}
Parameters:
| Name |
Type |
Description |
path |
string
|
api path as defined in the oas specification |
method |
string
|
method as defined by the oas specification e.g. get, put, post, delete, head, ... |
options |
Object
|
additional configuration for the method under the given path |
- Source:
Returns:
-
Type
-
ExpressHandler
RouterConfiguration
Type:
Properties:
| Name |
Type |
Attributes |
Description |
specification |
Object
|
|
the open api specification that will be used for mapping to the controllers |
router |
Object
|
<optional>
|
an express router object where the routes from the specification will be attached to. you can use this e.g. to configure a base path to your api. by default a new `express.Router()` object is used. |
resolver |
Resolver
|
<optional>
|
function which resolves a uri path and method to an express function handler. See the documentation for the resolver for more detail about the default behavior. |
onError |
RouterErrorCallback
|
<optional>
|
callback that will be called for errors that may occur during handler lookup. defaults to a function returning `false` - which will re-throw any exception and abort the router configuration. |
onBeforeRouteAdded |
RouterOnBeforeRouteAddedCallback
|
<optional>
|
callback that will be called for every route path that is to be added to the router. defaults to an `noop`. |
onBeforeRouteMethodAdded |
RouterOnBeforeMethodAddedCallback
|
<optional>
|
callback that will be called for every route method that is to be added to the current router path. defaults to an `noop`. |
- Source:
RouterErrorCallback(exception, path, method, options)
Parameters:
| Name |
Type |
Description |
exception |
Error
|
exception thrown by the resolver |
path |
string
|
path as defined by the open api specification |
method |
string
|
a method as defined by the open api specification for that path |
options |
Object
|
additional configuration options for that path and method from the open api specification |
- Source:
RouterOnBeforeMethodAddedCallback(handler, path, method, options)
Parameters:
| Name |
Type |
Description |
handler |
ExpressHandler
|
handler for the specific path and method |
path |
string
|
path as defined by the open api specification |
method |
string
|
a method as defined by the open api specification for that path |
options |
Object
|
additional configuration options for that path and method from the open api specification |
- Source:
RouterOnBeforeRouteAddedCallback(path, options)
Parameters:
| Name |
Type |
Description |
path |
string
|
path as defined by the open api specification |
options |
Object
|
additional configuration options for that path and containing all methods and their configurations |
- Source: