Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 21, 2019
1 parent 3f495f2 commit 68b31a5
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions README.md
Expand Up @@ -106,3 +106,82 @@ module.exports = app;
## [Example API Server (Full Project Source)](https://github.com/cdimascio/express-middleware-openapi-example)

A full working example lives [here](https://github.com/cdimascio/express-middleware-openapi-example)

## Example validation responses

#### Validate a query parameter with a value constraint

```shell
curl http://localhost:3000/v1/pets/as |jq
{
"errors": [
{
"path": "id",
"errorCode": "type.openapi.validation",
"message": "should be integer",
"location": "path"
}
]
}
```

#### Validate a query parameter with a range constraint

```shell
curl http://localhost:3000/v1/pets?limit=1 |jq
{
"errors": [
{
"path": "limit",
"errorCode": "minimum.openapi.validation",
"message": "should be >= 5",
"location": "query"
},
{
"path": "test",
"errorCode": "required.openapi.validation",
"message": "should have required property 'test'",
"location": "query"
}
]
}
```

#### Validate the query parameter's value type

```shell
curl --request POST \
--url http://localhost:3000/v1/pets \
--header 'content-type: application/xml' \
--data '{
"name": "test"
}' |jq
{
"errors": [
{
"message": "Unsupported Content-Type application/xml"
}
]
}
```

#### Validate a POST body to ensure required parameters are present

```shell
位 my-test curl --request POST \
--url http://localhost:3000/v1/pets \
--header 'content-type: application/json' \
--data '{
}'|jq
"errors": [
{
"path": "name",
"errorCode": "required.openapi.validation",
"message": "should have required property 'name'",
"location": "body"
}
]
}
```

#### ...and much more. Try it out!

0 comments on commit 68b31a5

Please sign in to comment.