Skip to content

Commit b85e101

Browse files
cdimascioSF97carmineluisfidelissnyk-bot
authored
feat(openapi): support OpenAPI version 3.1 (extends PR #882) (#1027)
* feat(openapi): support version 3.1 * test(openapi_3.1): ensure that an API with webhooks and no routes is supported * feat(openapi_3.1): adds open api 3.1 type * chore(test-scripts): run mocha with --extension instead of glob to pick up subdirectories Mocha was not picking up the tests in subdirectories with the provided glob. Adding --extension with the tests extension and setting the root test folder in tests fixed it * test(openapi-3.1): adds test to ensure an API with only components is considered valid * test(openapi-3.1): remove unnecessary import * test(openapi-3.1): add support for summary in info object * test(openapi-3.1): add support for identifier in license * test(openapi_3.1): ensure API with type set to null works correctly * test(open_api3.1): ensure that methods with non-explicit semantics allow request body * test(open_api3.1): ensure 500 is returned when server variable has no default * feat(openapi_3.1): ensure API supports an endpoint without response * feat(openapi_3.1): add full type support for open api 3.1 * test(openapi_3.1): adds test for path item support in components * fix(openapi_3.1_schema): update schema to fix bug * feat(openapi_3.1): support reusable path items * style(linting): fix linting issues * style(openapi): improve readability of version validation * docs(schema-validator): clearly state why media-range attribute is not defined * version 6.0.0-alpha.1 with initial OAS-3.1 support (from PR #882) * v6.0.0-alpha.2 * feat(openapi): support version 3.1 * test(openapi_3.1): ensure that an API with webhooks and no routes is supported * feat(openapi_3.1): adds open api 3.1 type * chore(test-scripts): run mocha with --extension instead of glob to pick up subdirectories Mocha was not picking up the tests in subdirectories with the provided glob. Adding --extension with the tests extension and setting the root test folder in tests fixed it * test(openapi-3.1): adds test to ensure an API with only components is considered valid * test(openapi-3.1): remove unnecessary import * test(openapi-3.1): add support for summary in info object * test(openapi-3.1): add support for identifier in license * test(openapi_3.1): ensure API with type set to null works correctly * test(open_api3.1): ensure that methods with non-explicit semantics allow request body * test(open_api3.1): ensure 500 is returned when server variable has no default * feat(openapi_3.1): ensure API supports an endpoint without response * feat(openapi_3.1): add full type support for open api 3.1 * test(openapi_3.1): adds test for path item support in components * fix(openapi_3.1_schema): update schema to fix bug * feat(openapi_3.1): support reusable path items * style(linting): fix linting issues * style(openapi): improve readability of version validation * docs(schema-validator): clearly state why media-range attribute is not defined * version 6.0.0-alpha.1 with initial OAS-3.1 support (from PR #882) * v6.0.0-alpha.2 * alpha.3 * feat(openapi): support version 3.1 * feat(openapi_3.1): adds open api 3.1 type * fix(openapi_3.1_schema): update schema to fix bug * style(linting): fix linting issues * fix: instantiate Ajv2020 for OAS 3.1 (#1009) * chore: create factories for ajvInstance and schema * test: writing some tests * chore: removing ts from editorconfig * chore: add eslint * update alpha 3.1 version * fix: examples/4-eov-operations-babel/package.json & examples/4-eov-operations-babel/package-lock.json to reduce vulnerabilities (#1021) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-PATHTOREGEXP-8482416 Co-authored-by: snyk-bot <[email protected]> * fix: package.json & package-lock.json to reduce vulnerabilities (#1017) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-PATHTOREGEXP-8482416 Co-authored-by: snyk-bot <[email protected]> * chore(deps): bump path-to-regexp and express in /examples/1-standard (#1016) Bumps [path-to-regexp](https://github.com/pillarjs/path-to-regexp) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together. Updates `path-to-regexp` from 0.1.10 to 0.1.12 - [Release notes](https://github.com/pillarjs/path-to-regexp/releases) - [Changelog](https://github.com/pillarjs/path-to-regexp/blob/master/History.md) - [Commits](pillarjs/path-to-regexp@v0.1.10...v0.1.12) Updates `express` from 4.21.0 to 4.21.2 - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/4.21.2/History.md) - [Commits](expressjs/express@4.21.0...4.21.2) --- updated-dependencies: - dependency-name: path-to-regexp dependency-type: indirect - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: upgrade express-openapi-validator from 5.3.7 to 5.3.8 (#1011) Snyk has created this PR to upgrade express-openapi-validator from 5.3.7 to 5.3.8. See this package in npm: express-openapi-validator See this project in Snyk: https://app.snyk.io/org/cdimascio/project/53639b22-8ff0-4bd5-97c3-ae30b20a20f4?utm_source=github&utm_medium=referral&page=upgrade-pr Co-authored-by: snyk-bot <[email protected]> * fix: upgrade express-openapi-validator from 5.3.6 to 5.3.7 (#1008) Snyk has created this PR to upgrade express-openapi-validator from 5.3.6 to 5.3.7. See this package in npm: express-openapi-validator See this project in Snyk: https://app.snyk.io/org/cdimascio/project/0ac9a5bd-9a7f-4c0e-bf8b-51d0bd4c4448?utm_source=github&utm_medium=referral&page=upgrade-pr Co-authored-by: snyk-bot <[email protected]> * fix: upgrade @apidevtools/json-schema-ref-parser from 11.7.0 to 11.7.2 (#1006) Snyk has created this PR to upgrade @apidevtools/json-schema-ref-parser from 11.7.0 to 11.7.2. See this package in npm: @apidevtools/json-schema-ref-parser See this project in Snyk: https://app.snyk.io/org/cdimascio/project/f63fb44e-f154-45ba-b1f0-20d49ea578ce?utm_source=github&utm_medium=referral&page=upgrade-pr Co-authored-by: snyk-bot <[email protected]> * adds standard example for oas-3.1 * v6.0.0.alpha.6 * update oas3.1 example * v5.4.0 - adds initial oas3.1 support * updates readme for oas3.1 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Sergio Ferreira <[email protected]> Co-authored-by: carmine <[email protected]> Co-authored-by: Luis Philipe Fidelis <[email protected]> Co-authored-by: snyk-bot <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 5e23352 commit b85e101

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5673
-168
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@
2929
[NestJS](https://github.com/cdimascio/express-openapi-validator/tree/master/examples/9-nestjs)
3030
[Koa](https://github.com/cdimascio/express-openapi-validator/tree/lerna-fastify/packages/koa-openapi-validator) and [Fastify](https://github.com/cdimascio/express-openapi-validator/tree/lerna-fastify/packages/fastify-openapi-validator) now available! 🚀
3131

32-
[OAS 3.1 (experimental)](https://github.com/cdimascio/express-openapi-validator/pull/882)
32+
[OAS 3.1 (beta)](https://github.com/cdimascio/express-openapi-validator/pull/882) is available in v5.4.0!
3333

3434
## Install
3535

3636
```shell
3737
npm install express-openapi-validator
38-
39-
# experimental OAS 3.1 in alpha (contributions welcome - see branch `oas-3.1` and pr-882
40-
# please provide feedback on (issue-573)
41-
npm install [email protected]
4238
```
4339

4440
## Usage

examples/1-standard-oas-3.1/README.md

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# example
2+
3+
simple example using express-openapi-validator
4+
5+
## Install
6+
7+
```shell
8+
npm run deps && npm i
9+
```
10+
11+
## Run
12+
13+
From this `1-standard` directory, run:
14+
15+
```shell
16+
npm start
17+
```
18+
19+
## Try
20+
21+
```shell
22+
## call ping
23+
curl http://localhost:3000/v1/ping
24+
25+
## call pets
26+
## the call below should return 400 since it requires additional parameters
27+
curl http://localhost:3000/v1/pets
28+
```
29+
30+
## Text examples
31+
32+
### GET /pets
33+
34+
success
35+
```shell
36+
curl -s 'localhost:3000/v1/pets?limit=5' |jq
37+
[
38+
{
39+
"id": 1,
40+
"name": "sparky",
41+
"type": "dog",
42+
"tags": [
43+
"sweet"
44+
]
45+
},
46+
{
47+
"id": 2,
48+
"name": "buzz",
49+
"type": "cat",
50+
"tags": [
51+
"purrfect"
52+
]
53+
},
54+
{
55+
"id": 3,
56+
"name": "max",
57+
"type": "dog",
58+
"tags": []
59+
}
60+
]
61+
```
62+
63+
error
64+
```shell
65+
curl -s 'localhost:3000/v1/pets' |jq
66+
{
67+
"message": "request/query must have required property 'limit'",
68+
"errors": [
69+
{
70+
"path": "/query/limit",
71+
"message": "must have required property 'limit'",
72+
"errorCode": "required.openapi.validation"
73+
}
74+
],
75+
"code": 400
76+
}
77+
```
78+
79+
### POST /pets
80+
81+
success
82+
```shell
83+
curl -s -XPOST 'localhost:3000/v1/pets' -d '{"id": 1, "name": "jobe"}' -H 'Content-type: application/json'|jq
84+
{
85+
"id": 1,
86+
"name": "jobe"
87+
}
88+
```
89+
90+
error
91+
```shell
92+
curl -s -XPOST 'localhost:3000/v1/pets' -d '{"id": "sdfsf", "name": "jobe"}' -H 'Content-type: application/json'|jq
93+
{
94+
"message": "request/body/id must be integer",
95+
"errors": [
96+
{
97+
"path": "/body/id",
98+
"message": "must be integer",
99+
"errorCode": "type.openapi.validation"
100+
}
101+
],
102+
"code": 400
103+
}
104+
```
105+
106+
### GET /pets/:id
107+
108+
success
109+
```shell
110+
curl -s 'localhost:3000/v1/pets/1' |jq
111+
{
112+
"id": 1,
113+
"name": "sparky",
114+
"type": "dog",
115+
"tags": [
116+
"sweet"
117+
]
118+
}
119+
```
120+
121+
error: bad id type
122+
```shell
123+
curl -s 'localhost:3000/v1/pets/lkl' |jq
124+
{
125+
"message": "request/params/petId must be number",
126+
"errors": [
127+
{
128+
"path": "/params/petId",
129+
"message": "must be number",
130+
"errorCode": "type.openapi.validation"
131+
}
132+
],
133+
"code": 400
134+
}
135+
```
136+
137+
138+
### /v1/pets/1/photos
139+
140+
success
141+
```shell
142+
curl -XPOST 'localhost:3000/v1/pets/1/photos' -H 'Content-type: multipart/form-data' -F '[email protected]'|jq
143+
% Total % Received % Xferd Average Speed Time Time Time Current
144+
Dload Upload Total Spent Left Speed
145+
100 304 100 90 100 214 25996 61813 --:--:-- --:--:-- --:--:-- 98k
146+
{
147+
"files_metadata": [
148+
{
149+
"originalname": "test.txt",
150+
"encoding": "7bit",
151+
"mimetype": "text/plain"
152+
}
153+
]
154+
}
155+
```
156+
157+
error: no file
158+
```shell
159+
curl -s -XPOST 'localhost:3000/v1/pets/1/photos' -H 'Content-type: multipart/form-data' |jq
160+
{
161+
"message": "request/body must have required property 'file'",
162+
"errors": [
163+
{
164+
"path": "/body/file",
165+
"message": "must have required property 'file'",
166+
"errorCode": "required.openapi.validation"
167+
}
168+
],
169+
"code": 400
170+
}
171+
```
172+

examples/1-standard-oas-3.1/api.yaml

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
openapi: 3.1.0
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
url: https://opensource.org/licenses/MIT
8+
servers:
9+
- url: http://petstore.swagger.io/v1
10+
paths:
11+
/pets:
12+
get:
13+
summary: List all pets
14+
operationId: listPets
15+
tags:
16+
- pets
17+
parameters:
18+
- name: limit
19+
in: query
20+
description: How many items to return at one time (max 100)
21+
required: true
22+
schema:
23+
type: integer
24+
format: int32
25+
responses:
26+
'200':
27+
description: A paged array of pets
28+
headers:
29+
x-next:
30+
description: A link to the next page of responses
31+
schema:
32+
type: string
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/Pets'
37+
default:
38+
description: unexpected error
39+
content:
40+
application/json:
41+
schema:
42+
$ref: '#/components/schemas/Error'
43+
post:
44+
summary: Create a pet
45+
operationId: createPets
46+
tags:
47+
- pets
48+
requestBody:
49+
content:
50+
application/json:
51+
schema:
52+
$ref: '#/components/schemas/Pet'
53+
responses:
54+
'201':
55+
description: Null response
56+
content:
57+
application/json:
58+
schema:
59+
$ref: '#/components/schemas/Pet'
60+
default:
61+
description: unexpected error
62+
content:
63+
application/json:
64+
schema:
65+
$ref: '#/components/schemas/Error'
66+
/pets/{id}:
67+
get:
68+
summary: Info for a specific pet
69+
operationId: showPetById
70+
tags:
71+
- pets
72+
parameters:
73+
- name: id
74+
in: path
75+
required: true
76+
description: The id of the pet to retrieve
77+
schema:
78+
type: number
79+
responses:
80+
'200':
81+
description: Expected response to a valid request
82+
content:
83+
application/json:
84+
schema:
85+
$ref: '#/components/schemas/Pet'
86+
default:
87+
description: unexpected error
88+
content:
89+
application/json:
90+
schema:
91+
$ref: '#/components/schemas/Error'
92+
93+
/pets/{id}/photos:
94+
post:
95+
summary: upload a photo of the pet
96+
operationId: uploadPetPhoto
97+
parameters:
98+
- name: id
99+
in: path
100+
description: ID of pet to fetch
101+
required: true
102+
schema:
103+
type: integer
104+
format: int64
105+
requestBody:
106+
content:
107+
multipart/form-data:
108+
schema:
109+
type: object
110+
required:
111+
- file
112+
properties:
113+
file:
114+
description: The photo
115+
type: string
116+
format: binary
117+
required: true
118+
responses:
119+
'200':
120+
description: Null response
121+
content:
122+
application/json:
123+
schema:
124+
type: object
125+
properties:
126+
success:
127+
type: boolean
128+
components:
129+
schemas:
130+
Pet:
131+
type: object
132+
required:
133+
- id
134+
- name
135+
properties:
136+
id:
137+
type: integer
138+
format: int64
139+
name:
140+
type: string
141+
tag:
142+
type: string
143+
Pets:
144+
type: array
145+
items:
146+
$ref: '#/components/schemas/Pet'
147+
Error:
148+
type: object
149+
required:
150+
- code
151+
- message
152+
properties:
153+
code:
154+
type: integer
155+
format: int32
156+
message:
157+
type: string

0 commit comments

Comments
 (0)