Skip to content

Commit

Permalink
Documentation update for changed match() behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
aautio committed Aug 31, 2020
1 parent f1ee68c commit ac071df
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,20 @@ Object][openapi-path-item-object]:
`RequestHandler` is an express middleware function with the signature
`(req: Request, res: Response, next: NextFunction): any;`.

#### `match(): RequestHandler`
#### `match(options: MatchOptions = { allowNoMatch: false }): RequestHandler`

Returns an express middleware function which calls `validate()` based on the
request method and path. Using this function removes the need to specify
`validate()` middleware for each express endpoint individually.

Note that behaviour is different to `validate()` for routes where no schema is
specified: `validate()` will throw an exception if no matching route
specification is found in the OpenAPI schema. `match()` will not throw an
exception in this case; the request is simply not validated. Be careful to
ensure you OpenAPI schema contains validators for each endpoint if using
`match()`.
`match()` will throw an error if matching route specification is not found. This
ensures all requests are validated. The thrown error is a
[`ValidationError`](#class-validationerror-extends-error) without a `.data`
array.

Use `match({ allowNoMatch: true})` if you want to skip validation for routes
that are not mentioned in the OpenAPI schema. It allows the request to be
handled without any validation.

The following examples achieve the same result:

Expand Down

0 comments on commit ac071df

Please sign in to comment.