Skip to content

Commit

Permalink
Merge pull request #54 from richdouglasevans/docs/root-validation
Browse files Browse the repository at this point in the history
Document how validation only applies underneath the server's base URL
  • Loading branch information
cdimascio committed Sep 22, 2019
2 parents ebc8020 + 141cb5f commit 20dd137
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -159,6 +159,27 @@ app.use((err, req, res, next) => {
});
```

## The Base URL

The validator will only validate requests — and (optionally) responses — that are under
the server's [base URL](https://spec.openapis.org/oas/v3.0.0.html#serverVariableObject).

This is useful for those times when the API and frontend are being served by the same
application. ([More detail about the base URL](https://swagger.io/docs/specification/api-host-and-base-path/).)

```yaml
servers:
- url: https://api.example.com/v1
```

The validation applies to all paths defined under this base URL. Routes in your app
that are _not_ under the base URL—such as pages—will not be validated.

| URL | Validated? |
| :----------------------------------- | :-------------------------- |
| `https://api.example.com/v1/users` | :white_check_mark: |
| `https://api.example.com/index.html` | no; not under the base URL |

## [Example Express API Server](https://github.com/cdimascio/express-openapi-validator-example) (clone it)

A fully working example lives [here](https://github.com/cdimascio/express-openapi-validator-example)
Expand Down

0 comments on commit 20dd137

Please sign in to comment.