Skip to content

Commit

Permalink
revert ajv8 (temporarily)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed May 30, 2022
1 parent 1706538 commit 4d0d598
Show file tree
Hide file tree
Showing 48 changed files with 365 additions and 758 deletions.
16 changes: 8 additions & 8 deletions examples/2-standard-multiple-api-specs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ curl 'localhost:3000/v2/pets?pet_type=kitty' |jq
]

## invoke GET /v2/pets using `type` as specified in v1, but not v2
curl 'localhost:3000/v2/pets?type=cat' |jq
curl 'localhost:3000/v2/pets?type=cat' |jq
{
"message": "Unknown query parameter 'type'",
"errors": [
{
"path": "/query/type",
"path": ".query.type",
"message": "Unknown query parameter 'type'"
}
]
}

## invoke GET /v1/pets using type='kitty'. kitty is not a valid v1 value.
## invoke GET /v1/pets using type='kitty'. kitty is not a valid v1 value.
## also limit is required in GET /v1/pets
curl 'localhost:3000/v1/pets?type=kitty' |jq
{
"message": "request/query/type must be equal to one of the allowed values: dog, cat, request.query must have required property 'limit'",
"message": "request.query.type should be equal to one of the allowed values: dog, cat, request.query should have required property 'limit'",
"errors": [
{
"path": "/query.type",
"message": "must be equal to one of the allowed values: dog, cat",
"path": ".query.type",
"message": "should be equal to one of the allowed values: dog, cat",
"errorCode": "enum.openapi.validation"
},
{
"path": "/query.limit",
"message": "must have required property 'limit'",
"path": ".query.limit",
"message": "should have required property 'limit'",
"errorCode": "required.openapi.validation"
}
]
Expand Down
4 changes: 2 additions & 2 deletions examples/9-nestjs/src/modules/ping/ping.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('PingController', () => {
path: '/',
errors: [
{
path: '/body/ping',
message: "must have required property 'ping'",
path: '.body.ping',
message: "should have required property 'ping'",
errorCode: 'required.openapi.validation',
},
],
Expand Down
59 changes: 10 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-openapi-validator",
"version": "4.14.0-beta.2",
"version": "4.13.7",
"description": "Automatically validate API requests and responses with OpenAPI 3 and Express.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -33,9 +33,7 @@
"license": "MIT",
"dependencies": {
"@types/multer": "^1.4.7",
"ajv": "^8.6.2",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^2.1.1",
"ajv": "^6.12.6",
"content-type": "^1.0.4",
"json-schema-ref-parser": "^9.0.9",
"lodash.clonedeep": "^4.5.0",
Expand Down
18 changes: 6 additions & 12 deletions src/framework/ajv/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@ const base64regExp = /^[A-Za-z0-9+/]*(=|==)?$/;

export const formats = {
int32: {
validate: (i: number) =>
Number.isInteger(i) && i <= maxInt32 && i >= minInt32,
validate: i => Number.isInteger(i) && i <= maxInt32 && i >= minInt32,
type: 'number',
},
int64: {
validate: (i: number) =>
Number.isInteger(i) && i <= maxInt64 && i >= minInt64,
validate: i => Number.isInteger(i) && i <= maxInt64 && i >= minInt64,
type: 'number',
},
float: {
validate: (i: number) =>
typeof i === 'number' &&
(i === 0 ||
(i <= maxFloat && i >= minPosFloat) ||
(i >= minFloat && i <= maxNegFloat)),
validate: i => typeof i === 'number' && (i === 0 || (i <= maxFloat && i >= minPosFloat) || (i >= minFloat && i <= maxNegFloat)),
type: 'number',
},
double: {
validate: (i: number) => typeof i === 'number',
validate: i => typeof i === 'number',
type: 'number',
},
byte: (b: string) => b.length % 4 === 0 && base64regExp.test(b),
byte: b => b.length % 4 === 0 && base64regExp.test(b),
binary: alwaysTrue,
password: alwaysTrue,
} as const;
};
Loading

0 comments on commit 4d0d598

Please sign in to comment.