Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Mar 22, 2019
2 parents 2159eec + dd065d2 commit d7c77e5
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# express-middleware-openapi

![](https://travis-ci.org/cdimascio/express-middleware-openapi.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/express-middleware-openapi/badge.svg?branch=master)](https://coveralls.io/github/cdimascio/express-middleware-openapi?branch=master) ![](https://img.shields.io/badge/license-MIT-blue.svg)
![](https://travis-ci.org/cdimascio/express-middleware-openapi.svg?branch=master) ![](https://img.shields.io/npm/v/express-middleware-openapi.svg) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/express-middleware-openapi/badge.svg?branch=master)](https://coveralls.io/github/cdimascio/express-middleware-openapi?branch=master) ![](https://img.shields.io/badge/license-MIT-blue.svg)

ExpressJs middleware that automatically validates API requests using an OpenAPI 3.0 specification,

Try out the [sample project](https://github.com/cdimascio/express-middleware-openapi-example)

## Install

Try this pre-release alpha version:

```shell
npm i express-middleware-openapi
```
Expand All @@ -24,21 +20,21 @@ new OpenApiMiddleware({
}).install(app);
```

(see complete [example](#example))

### Advanced

```javascript
new OpenApiMiddleware({

// required: path to an openapi 3 spec
apiSpecPath: './openapi.yaml',
// default is true
// validates the openapi spec, throws if invalid

// default true: validates the openapi spec, throws if invalid
validateApiDoc: true,
// default is true
// attempts to coerce a value's type to that defined in the openapi spec

// default: trueattempts to coerce a value's type to that defined in the openapi spec
enableObjectCoercion: true,
// default is undefined
// provide a custom error transform to customize how errors are shaped

// optional: provide a custom error transform to customize how errors are shaped
errorTransform: validationResult => ({
// the http status code to return
statusCode: validationResult.status,
Expand All @@ -51,6 +47,8 @@ new OpenApiMiddleware({
}).install(app);
```

(see complete [example](#example))

## Example API Server

Try the complete example below:
Expand Down Expand Up @@ -103,7 +101,7 @@ 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)
A fully working example lives [here](https://github.com/cdimascio/express-middleware-openapi-example)

## Example validation responses

Expand Down

0 comments on commit d7c77e5

Please sign in to comment.