Skip to content

feat(openapi): support OpenAPI version 3.1 (extends PR #882) #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 68 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
4f2ceaa
feat(openapi): support version 3.1
SF97 Dec 31, 2023
1894d84
test(openapi_3.1): ensure that an API with webhooks and no routes is …
SF97 Feb 5, 2024
bb53f78
feat(openapi_3.1): adds open api 3.1 type
SF97 Feb 5, 2024
0c4f24c
chore(test-scripts): run mocha with --extension instead of glob to pi…
SF97 Feb 5, 2024
289bd03
test(openapi-3.1): adds test to ensure an API with only components is…
SF97 Feb 29, 2024
0e6ae31
test(openapi-3.1): remove unnecessary import
SF97 Feb 29, 2024
3161312
test(openapi-3.1): add support for summary in info object
SF97 Feb 29, 2024
7698f02
test(openapi-3.1): add support for identifier in license
SF97 Feb 29, 2024
15d9049
test(openapi_3.1): ensure API with type set to null works correctly
SF97 Mar 31, 2024
0587415
test(open_api3.1): ensure that methods with non-explicit semantics al…
SF97 Mar 31, 2024
415de44
test(open_api3.1): ensure 500 is returned when server variable has no…
SF97 Mar 31, 2024
7bcf518
feat(openapi_3.1): ensure API supports an endpoint without response
SF97 Mar 31, 2024
782a70a
Merge remote-tracking branch 'upstream/master' into feat/openapi-3.1-…
SF97 Apr 28, 2024
4584261
feat(openapi_3.1): add full type support for open api 3.1
SF97 Apr 28, 2024
9c58166
test(openapi_3.1): adds test for path item support in components
SF97 Apr 28, 2024
5897589
fix(openapi_3.1_schema): update schema to fix bug
SF97 May 13, 2024
9654417
feat(openapi_3.1): support reusable path items
SF97 May 16, 2024
ddc0ebc
style(linting): fix linting issues
SF97 May 20, 2024
2cae4b5
style(openapi): improve readability of version validation
SF97 May 20, 2024
81b45ee
docs(schema-validator): clearly state why media-range attribute is no…
SF97 May 20, 2024
ffd7468
Merge branch 'master' into feat/openapi-3.1-support
SF97 Jun 11, 2024
b1740a1
Merge branch 'pr-882' into oas3.1
Aug 24, 2024
ebb9b25
version 6.0.0-alpha.1 with initial OAS-3.1 support (from PR https://g…
Aug 24, 2024
334e2de
v6.0.0-alpha.2
Aug 31, 2024
8f43042
feat(openapi): support version 3.1
SF97 Dec 31, 2023
ad10f8b
test(openapi_3.1): ensure that an API with webhooks and no routes is …
SF97 Feb 5, 2024
c305243
feat(openapi_3.1): adds open api 3.1 type
SF97 Feb 5, 2024
e49db6a
chore(test-scripts): run mocha with --extension instead of glob to pi…
SF97 Feb 5, 2024
a66845b
test(openapi-3.1): adds test to ensure an API with only components is…
SF97 Feb 29, 2024
f346d9d
test(openapi-3.1): remove unnecessary import
SF97 Feb 29, 2024
a273299
test(openapi-3.1): add support for summary in info object
SF97 Feb 29, 2024
97a84f6
test(openapi-3.1): add support for identifier in license
SF97 Feb 29, 2024
7262edd
test(openapi_3.1): ensure API with type set to null works correctly
SF97 Mar 31, 2024
b757ff3
test(open_api3.1): ensure that methods with non-explicit semantics al…
SF97 Mar 31, 2024
8ad7a4f
test(open_api3.1): ensure 500 is returned when server variable has no…
SF97 Mar 31, 2024
44939ee
feat(openapi_3.1): ensure API supports an endpoint without response
SF97 Mar 31, 2024
47fb245
feat(openapi_3.1): add full type support for open api 3.1
SF97 Apr 28, 2024
6d14d8c
test(openapi_3.1): adds test for path item support in components
SF97 Apr 28, 2024
b250c7f
fix(openapi_3.1_schema): update schema to fix bug
SF97 May 13, 2024
0daf9f3
feat(openapi_3.1): support reusable path items
SF97 May 16, 2024
448d239
style(linting): fix linting issues
SF97 May 20, 2024
b4cbb1a
style(openapi): improve readability of version validation
SF97 May 20, 2024
1c15cee
docs(schema-validator): clearly state why media-range attribute is no…
SF97 May 20, 2024
f842723
version 6.0.0-alpha.1 with initial OAS-3.1 support (from PR https://g…
Aug 24, 2024
f5b31dc
v6.0.0-alpha.2
Aug 31, 2024
ee85d8d
alpha.3
Sep 1, 2024
3701c94
Merge remote-tracking branch 'origin/oas3.1' into oas3.1
Sep 1, 2024
03efbf3
feat(openapi): support version 3.1
SF97 Dec 31, 2023
6333ae0
feat(openapi_3.1): adds open api 3.1 type
SF97 Feb 5, 2024
f23ce0c
fix(openapi_3.1_schema): update schema to fix bug
SF97 May 13, 2024
e3daa22
style(linting): fix linting issues
SF97 May 20, 2024
380520d
Merge branch 'master' into oas3.1
Sep 22, 2024
c5a991f
Merge branch 'master' into oas3.1
Oct 26, 2024
ef8e7ba
fix: instantiate Ajv2020 for OAS 3.1 (#1009)
luisfidelis Nov 10, 2024
bd5a373
Merge branch 'master' into oas3.1
Nov 11, 2024
e0e6a43
update alpha 3.1 version
Nov 11, 2024
178da06
fix: examples/4-eov-operations-babel/package.json & examples/4-eov-op…
cdimascio Dec 19, 2024
b80f11e
fix: package.json & package-lock.json to reduce vulnerabilities (#1017)
cdimascio Dec 19, 2024
1f1da16
chore(deps): bump path-to-regexp and express in /examples/1-standard …
dependabot[bot] Dec 19, 2024
5152b7e
fix: upgrade express-openapi-validator from 5.3.7 to 5.3.8 (#1011)
cdimascio Dec 19, 2024
eaf83ec
fix: upgrade express-openapi-validator from 5.3.6 to 5.3.7 (#1008)
cdimascio Dec 19, 2024
bc7ed2a
fix: upgrade @apidevtools/json-schema-ref-parser from 11.7.0 to 11.7.…
cdimascio Dec 19, 2024
71567f3
Merge branch 'master' into oas3.1
Dec 19, 2024
35424c9
adds standard example for oas-3.1
Dec 22, 2024
3050e7f
v6.0.0.alpha.6
Dec 23, 2024
9b4e160
update oas3.1 example
Dec 24, 2024
f7167ff
v5.4.0 - adds initial oas3.1 support
Dec 24, 2024
f33f2c6
updates readme for oas3.1
Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
[NestJS](https://github.com/cdimascio/express-openapi-validator/tree/master/examples/9-nestjs)
[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! 🚀

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

## Install

```shell
npm install express-openapi-validator

# experimental OAS 3.1 in alpha (contributions welcome - see branch `oas-3.1` and pr-882
# please provide feedback on (issue-573)
npm install [email protected]
```

## Usage
Expand Down
172 changes: 172 additions & 0 deletions examples/1-standard-oas-3.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# example

simple example using express-openapi-validator

## Install

```shell
npm run deps && npm i
```

## Run

From this `1-standard` directory, run:

```shell
npm start
```

## Try

```shell
## call ping
curl http://localhost:3000/v1/ping

## call pets
## the call below should return 400 since it requires additional parameters
curl http://localhost:3000/v1/pets
```

## Text examples

### GET /pets

success
```shell
curl -s 'localhost:3000/v1/pets?limit=5' |jq
[
{
"id": 1,
"name": "sparky",
"type": "dog",
"tags": [
"sweet"
]
},
{
"id": 2,
"name": "buzz",
"type": "cat",
"tags": [
"purrfect"
]
},
{
"id": 3,
"name": "max",
"type": "dog",
"tags": []
}
]
```

error
```shell
curl -s 'localhost:3000/v1/pets' |jq
{
"message": "request/query must have required property 'limit'",
"errors": [
{
"path": "/query/limit",
"message": "must have required property 'limit'",
"errorCode": "required.openapi.validation"
}
],
"code": 400
}
```

### POST /pets

success
```shell
curl -s -XPOST 'localhost:3000/v1/pets' -d '{"id": 1, "name": "jobe"}' -H 'Content-type: application/json'|jq
{
"id": 1,
"name": "jobe"
}
```

error
```shell
curl -s -XPOST 'localhost:3000/v1/pets' -d '{"id": "sdfsf", "name": "jobe"}' -H 'Content-type: application/json'|jq
{
"message": "request/body/id must be integer",
"errors": [
{
"path": "/body/id",
"message": "must be integer",
"errorCode": "type.openapi.validation"
}
],
"code": 400
}
```

### GET /pets/:id

success
```shell
curl -s 'localhost:3000/v1/pets/1' |jq
{
"id": 1,
"name": "sparky",
"type": "dog",
"tags": [
"sweet"
]
}
```

error: bad id type
```shell
curl -s 'localhost:3000/v1/pets/lkl' |jq
{
"message": "request/params/petId must be number",
"errors": [
{
"path": "/params/petId",
"message": "must be number",
"errorCode": "type.openapi.validation"
}
],
"code": 400
}
```


### /v1/pets/1/photos

success
```shell
curl -XPOST 'localhost:3000/v1/pets/1/photos' -H 'Content-type: multipart/form-data' -F '[email protected]'|jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 304 100 90 100 214 25996 61813 --:--:-- --:--:-- --:--:-- 98k
{
"files_metadata": [
{
"originalname": "test.txt",
"encoding": "7bit",
"mimetype": "text/plain"
}
]
}
```

error: no file
```shell
curl -s -XPOST 'localhost:3000/v1/pets/1/photos' -H 'Content-type: multipart/form-data' |jq
{
"message": "request/body must have required property 'file'",
"errors": [
{
"path": "/body/file",
"message": "must have required property 'file'",
"errorCode": "required.openapi.validation"
}
],
"code": 400
}
```

157 changes: 157 additions & 0 deletions examples/1-standard-oas-3.1/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
openapi: 3.1.0
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: true
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: createPets
tags:
- pets
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'201':
description: Null response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{id}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: id
in: path
required: true
description: The id of the pet to retrieve
schema:
type: number
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/pets/{id}/photos:
post:
summary: upload a photo of the pet
operationId: uploadPetPhoto
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
schema:
type: integer
format: int64
requestBody:
content:
multipart/form-data:
schema:
type: object
required:
- file
properties:
file:
description: The photo
type: string
format: binary
required: true
responses:
'200':
description: Null response
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Loading
Loading