Skip to content

Commit bf09b6c

Browse files
authored
replace deref lib (#140)
* replace deref lib * changeset * remove v14 support
1 parent b90c88c commit bf09b6c

File tree

14 files changed

+575
-386
lines changed

14 files changed

+575
-386
lines changed

.changeset/five-bananas-bake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'oas3-chow-chow': major
3+
---
4+
5+
The API has been updated to be an async function.
6+
Remove support for node v14.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
node-version: [14.x, 16.x, 18.x]
13+
node-version: [16.x, 18.x]
1414

1515
steps:
1616
- uses: actions/checkout@v2

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as fs from "fs";
2828
import * as yaml from "js-yaml";
2929

3030
var doc = yaml.safeLoad(fs.readFileSync("./openapi.yml", "utf8"));
31-
const chow = new ChowChow(doc);
31+
const chow = ChowChow.create(doc);
3232

3333
// For URL: /:pathParam/info?arrParam=x&arrParam=y&other=z
3434
chow.validateRequestByPath(
@@ -56,7 +56,7 @@ chow.validateResponseByPath("/books/info", "POST", {
5656

5757
You could optionally provide configs to the constructor
5858
```typescript
59-
const chow = new ChowChow(doc, {
59+
const chow = ChowChow.create(doc, {
6060
headerAjvOptions: {},
6161
cookieAjvOptions: {},
6262
pathAjvOptions: { coerceTypes: true },

__test__/deref-error.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import ChowChow from '../src';
33
const fixture = require('./fixtures/deref-error.json');
44

55
describe('Deref Error', () => {
6-
it('should throw a proper error', () => {
7-
expect(() => new ChowChow(fixture)).toThrow(
8-
'Missing $ref: #/components/schemas/blahBlahBlah'
6+
it('should throw a proper error', async () => {
7+
await expect(ChowChow.create(fixture)).rejects.toMatchInlineSnapshot(
8+
`[MissingPointerError: Token "blahBlahBlah" does not exist.]`
99
);
1010
});
1111
});

__test__/option.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import ChowChow from '../src';
22

33
describe('Option Body', () => {
4-
it('throw with unknown format', () => {
4+
it('throw with unknown format', async () => {
55
const fixture = require('./fixtures/option-unknown-fmt.json');
66

7-
expect(() => {
8-
new ChowChow(fixture);
9-
}).toThrow(
10-
'unknown format "pet-name" ignored in schema at path "#/properties/name"'
7+
await expect(ChowChow.create(fixture)).rejects.toMatchInlineSnapshot(
8+
`[Error: unknown format "pet-name" ignored in schema at path "#/properties/name"]`
119
);
1210
});
1311

14-
it('success with unknown format if unknown format is allowed', () => {
12+
it('success with unknown format if unknown format is allowed', async () => {
1513
const fixture = require('./fixtures/option-unknown-fmt.json');
1614

17-
expect(() => {
18-
new ChowChow(fixture, {
15+
await expect(
16+
ChowChow.create(fixture, {
1917
responseBodyAjvOptions: {
2018
formats: {
2119
'pet-name': true,
2220
},
2321
},
24-
});
25-
}).not.toThrow();
22+
})
23+
).resolves.toBeTruthy();
2624
});
2725
});

__test__/path.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ describe('Path', () => {
88
describe('Parameter in Operation level', () => {
99
let chowchow: ChowChow;
1010

11-
beforeAll(() => {
12-
chowchow = new ChowChow(pathFixture);
11+
beforeAll(async () => {
12+
chowchow = await ChowChow.create(pathFixture);
1313
});
1414

1515
it('should validate the path parameters and coerce to the correct type', () => {
@@ -35,8 +35,8 @@ describe('Path', () => {
3535
describe('Parameter in Path level', () => {
3636
let chowchow: ChowChow;
3737

38-
beforeAll(() => {
39-
chowchow = new ChowChow(parameterInPathLevelFixture);
38+
beforeAll(async () => {
39+
chowchow = await ChowChow.create(parameterInPathLevelFixture);
4040
});
4141

4242
it('should validate the path parameters and coerce to the correct type', () => {
@@ -62,8 +62,8 @@ describe('Path', () => {
6262
describe('Parameter in Operation level should override Path level', () => {
6363
let chowchow: ChowChow;
6464

65-
beforeAll(() => {
66-
chowchow = new ChowChow(parameterInBothOperationAndPathFixture);
65+
beforeAll(async () => {
66+
chowchow = await ChowChow.create(parameterInBothOperationAndPathFixture);
6767
});
6868

6969
it('should validate the path parameters and coerce to the correct type', () => {

__test__/pet-store.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const fixture = require('./fixtures/pet-store.json');
55
describe('Pet Store', () => {
66
let chowchow: ChowChow;
77

8-
beforeAll(() => {
9-
chowchow = new ChowChow(fixture as any);
8+
beforeAll(async () => {
9+
chowchow = await ChowChow.create(fixture as any);
1010
});
1111

1212
test('It should throw an error if a path is undefined', () => {
@@ -105,11 +105,11 @@ describe('Pet Store', () => {
105105
});
106106
});
107107
describe('Configure ChowOptions for allErrors', () => {
108-
test('It should fail validation and receive multiple errors if payload is invalid and ChowOptions configured with allErrors:true', () => {
108+
test('It should fail validation and receive multiple errors if payload is invalid and ChowOptions configured with allErrors:true', async () => {
109109
let chowOptions: Partial<ChowOptions> = {
110110
requestBodyAjvOptions: { allErrors: true },
111111
};
112-
chowchow = new ChowChow(fixture as any, chowOptions);
112+
chowchow = await ChowChow.create(fixture as any, chowOptions);
113113

114114
try {
115115
chowchow.validateRequestByPath('/pets', 'post', {
@@ -131,11 +131,11 @@ describe('Pet Store', () => {
131131
}
132132
});
133133

134-
test('It should fail validation and receive a single error if payload is invalid and ChowOptions configured for allErrors:false', () => {
134+
test('It should fail validation and receive a single error if payload is invalid and ChowOptions configured for allErrors:false', async () => {
135135
let chowOptions: Partial<ChowOptions> = {
136136
requestBodyAjvOptions: { allErrors: false },
137137
};
138-
chowchow = new ChowChow(fixture as any, chowOptions);
138+
chowchow = await ChowChow.create(fixture as any, chowOptions);
139139

140140
try {
141141
chowchow.validateRequestByPath('/pets', 'post', {
@@ -157,8 +157,8 @@ describe('Pet Store', () => {
157157
}
158158
});
159159

160-
test('It should fail validation and receive a single error if payload is invalid and ChowOptions not configured', () => {
161-
chowchow = new ChowChow(fixture as any);
160+
test('It should fail validation and receive a single error if payload is invalid and ChowOptions not configured', async () => {
161+
chowchow = await ChowChow.create(fixture as any);
162162

163163
try {
164164
chowchow.validateRequestByPath('/pets', 'post', {

__test__/query.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const fixture = require('./fixtures/query.json');
44
describe('Query', () => {
55
let chowchow: ChowChow;
66

7-
beforeAll(() => {
8-
chowchow = new ChowChow(fixture);
7+
beforeAll(async () => {
8+
chowchow = await ChowChow.create(fixture);
99
});
1010

1111
it('should coerce query parameter to an array', () => {

__test__/response.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const fixture = require('./fixtures/response.json');
77
describe('Response', () => {
88
let chowchow: ChowChow;
99

10-
beforeAll(() => {
11-
chowchow = new ChowChow(fixture);
10+
beforeAll(async () => {
11+
chowchow = await ChowChow.create(fixture);
1212
});
1313

1414
it('should validate the response with status code', () => {

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
"singleQuote": true
2828
},
2929
"dependencies": {
30+
"@apidevtools/json-schema-ref-parser": "^11.1.0",
3031
"ajv": "^8.12.0",
3132
"ajv-formats": "^2.1.1",
3233
"better-ajv-errors": "1.2.0",
33-
"json-schema-deref-sync": "^0.14.0",
34+
"oas-validator": "^5.0.8",
3435
"openapi3-ts": "^1.3.0",
3536
"xregexp": "^4.2.4"
3637
},
@@ -40,10 +41,10 @@
4041
"@types/node": "18.17.11",
4142
"@types/xregexp": "3.0.30",
4243
"babel-core": "6.26.3",
43-
"babel-jest": "29.6.4",
44-
"jest": "29.6.4",
44+
"babel-jest": "^29.7.0",
45+
"jest": "^29.7.0",
4546
"prettier": "2.2.1",
46-
"ts-jest": "29.1.1",
47-
"typescript": "4.9.5"
47+
"ts-jest": "^29.1.1",
48+
"typescript": "5.2.2"
4849
}
4950
}

0 commit comments

Comments
 (0)