From 8dfd8719846153e41b9d9ba942019420eff03233 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Sun, 24 Nov 2019 20:52:03 -0500 Subject: [PATCH] merge from master --- .all-contributorsrc | 10 ++++ README.md | 4 +- test/empty.servers.spec.ts | 35 ++++++++++++ test/resources/empty.servers.yaml | 94 +++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 test/empty.servers.spec.ts create mode 100644 test/resources/empty.servers.yaml diff --git a/.all-contributorsrc b/.all-contributorsrc index d2150295..18b5aede 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -111,6 +111,16 @@ "code", "test" ] + }, + { + "login": "HugoMario", + "name": "HugoMario", + "avatar_url": "https://avatars1.githubusercontent.com/u/3266608?v=4", + "profile": "https://github.com/HugoMario", + "contributions": [ + "code", + "test" + ] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index 50636762..15960be6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # express-openapi-validator -[![](https://travis-ci.org/cdimascio/express-openapi-validator.svg?branch=master)](#) [![](https://img.shields.io/npm/v/express-openapi-validator.svg)](https://www.npmjs.com/package/express-openapi-validator) ![](https://img.shields.io/npm/dm/express-openapi-validator.svg) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/express-openapi-validator/badge.svg?branch=master)](https://coveralls.io/github/cdimascio/express-openapi-validator?branch=master) [![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors) [![Greenkeeper badge](https://badges.greenkeeper.io/cdimascio/express-openapi-validator.svg)](https://greenkeeper.io/) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) [![](https://img.shields.io/badge/license-MIT-blue.svg)](#license) +[![](https://travis-ci.org/cdimascio/express-openapi-validator.svg?branch=master)](#) [![](https://img.shields.io/npm/v/express-openapi-validator.svg)](https://www.npmjs.com/package/express-openapi-validator) ![](https://img.shields.io/npm/dm/express-openapi-validator.svg) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/express-openapi-validator/badge.svg?branch=master)](https://coveralls.io/github/cdimascio/express-openapi-validator?branch=master) [![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors) [![Greenkeeper badge](https://badges.greenkeeper.io/cdimascio/express-openapi-validator.svg)](https://greenkeeper.io/) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) [![](https://img.shields.io/badge/license-MIT-blue.svg)](#license) **An OpenApi validator for ExpressJS** that automatically validates **API** _**requests**_ and _**responses**_ using an **OpenAPI 3** specification. @@ -58,6 +58,7 @@ _**Note:** Ensure express is configured with all relevant body parsers. body par See [Advanced Usage](#Advanced-Usage) options to: - inline api specs as JSON. +- configure request/response validation options - tweak the file upload configuration. - customize authentication with `securityHandlers`. - use OpenAPI 3.0.x 3rd party and custom formats. @@ -586,6 +587,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Spencer Brown
Spencer Brown

💻 ⚠️ José Neves
José Neves

💻 mk811
mk811

💻 ⚠️ + HugoMario
HugoMario

💻 ⚠️ diff --git a/test/empty.servers.spec.ts b/test/empty.servers.spec.ts new file mode 100644 index 00000000..6554ebc2 --- /dev/null +++ b/test/empty.servers.spec.ts @@ -0,0 +1,35 @@ +import * as path from 'path'; +import * as express from 'express'; +import { expect } from 'chai'; +import * as request from 'supertest'; +import { createApp } from './common/app'; + +describe('express-openapi-validator', () => { + let app = null; + + before(async () => { + // Set up the express app + const apiSpec = path.join('test', 'resources', 'empty.servers.yaml'); + app = await createApp({ apiSpec }, 3007, app => + app.use( + ``, + express + .Router() + .get(`/pets`, (req, res) => res.json(req.body)), + ), + ); + }); + + after(() => { + app.server.close(); + }); + + it('should throw 400', async () => + request(app) + .get(`/pets`) + .expect(400) + .then(r => { + expect(r.body.errors).to.be.an('array'); + expect(r.body.errors).to.have.length(2); + })); +}); diff --git a/test/resources/empty.servers.yaml b/test/resources/empty.servers.yaml new file mode 100644 index 00000000..621c6430 --- /dev/null +++ b/test/resources/empty.servers.yaml @@ -0,0 +1,94 @@ +openapi: '3.0.0' +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API + termsOfService: http://swagger.io/terms/ + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +servers: [] +paths: + /pets: + get: + description: | + Returns all pets + operationId: findPets + parameters: + - name: type + in: query + description: maximum number of results to return + required: true + schema: + type: string + enum: + - dog + - cat + - name: tags + in: query + description: tags to filter by + required: false + style: form + schema: + type: array + items: + type: string + - name: limit + in: query + description: maximum number of results to return + required: true + schema: + type: integer + format: int32 + minimum: 1 + maximum: 20 + responses: + '200': + description: pet response + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + +components: + schemas: + NewPet: + required: + - name + properties: + name: + type: string + tag: + type: string + type: + $ref: '#/components/schemas/PetType' + + Pet: + allOf: + - $ref: '#/components/schemas/NewPet' + - required: + - id + properties: + id: + type: integer + format: int64 + + PetType: + type: string + enum: + - dog + - cat + + Error: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string +