Skip to content

Commit

Permalink
feat: upgrade to ajv v8 (#132)
Browse files Browse the repository at this point in the history
* feat: upgrade to ajv v8

* fix: tests and linting

* feat: remove deprecated method

* chore: linting
  • Loading branch information
supertong authored Aug 30, 2023
1 parent af9de89 commit b90c88c
Show file tree
Hide file tree
Showing 21 changed files with 644 additions and 2,563 deletions.
9 changes: 9 additions & 0 deletions .changeset/shiny-swans-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'oas3-chow-chow': major
---

Upgrade ajv to version 8.

The main BREAKING CHANGE is that the support for JSON-Schema draft-04 is removed from version 8.
Some properties of Ajv.Options has also changed its shape.
More details: https://ajv.js.org/v6-to-v8-migration.html
8 changes: 4 additions & 4 deletions __test__/__snapshots__/pet-store.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Pet Store RequestBody It returns defined body content type 1`] = `
Array [
[
"application/json",
]
`;

exports[`Pet Store RequestBody It returns empty array for defined body content type if method is undefined 1`] = `Array []`;
exports[`Pet Store RequestBody It returns empty array for defined body content type if method is undefined 1`] = `[]`;

exports[`Pet Store RequestBody It returns empty array for defined body content type if path is undefined 1`] = `Array []`;
exports[`Pet Store RequestBody It returns empty array for defined body content type if path is undefined 1`] = `[]`;

exports[`Pet Store RequestBody It returns empty array for defined body content type if requestBody is not defined 1`] = `Array []`;
exports[`Pet Store RequestBody It returns empty array for defined body content type if requestBody is not defined 1`] = `[]`;
36 changes: 18 additions & 18 deletions __test__/chow-error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ describe('ChowError', () => {
it('should be able to initialize a ChowError', () => {
const chowError = new ChowError('An error', { in: 'test' });
expect(chowError.toJSON()).toMatchInlineSnapshot(`
Object {
"code": 400,
"location": Object {
"in": "test",
},
"message": "An error",
"suggestions": Array [],
}
`);
{
"code": 400,
"location": {
"in": "test",
},
"message": "An error",
"suggestions": [],
}
`);
});

it('should be able to output JSON format of the error', () => {
const chowError = new ChowError('An error', { in: 'test' });
expect(chowError.toJSON()).toMatchInlineSnapshot(`
Object {
"code": 400,
"location": Object {
"in": "test",
},
"message": "An error",
"suggestions": Array [],
}
`);
{
"code": 400,
"location": {
"in": "test",
},
"message": "An error",
"suggestions": [],
}
`);
});
});
1 change: 1 addition & 0 deletions __test__/fixtures/option-unknown-fmt.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
Expand All @@ -94,6 +95,7 @@
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
Expand Down
2 changes: 2 additions & 0 deletions __test__/fixtures/parameter-in-path-level.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
Expand All @@ -83,6 +84,7 @@
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
Expand Down
2 changes: 2 additions & 0 deletions __test__/fixtures/path.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
Expand All @@ -126,6 +127,7 @@
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
Expand Down
2 changes: 2 additions & 0 deletions __test__/fixtures/pet-store.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
Expand Down Expand Up @@ -476,6 +477,7 @@
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
Expand Down
2 changes: 2 additions & 0 deletions __test__/fixtures/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": [
"id",
"name"
Expand All @@ -96,6 +97,7 @@
}
},
"Error": {
"type": "object",
"required": [
"code",
"message"
Expand Down
2 changes: 2 additions & 0 deletions __test__/fixtures/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {
Expand Down Expand Up @@ -165,6 +166,7 @@
}
},
"Error": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": {
Expand Down
8 changes: 6 additions & 2 deletions __test__/option.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Option Body', () => {
expect(() => {
new ChowChow(fixture);
}).toThrow(
'unknown format "pet-name" is used in schema at path "#/properties/name"'
'unknown format "pet-name" ignored in schema at path "#/properties/name"'
);
});

Expand All @@ -16,7 +16,11 @@ describe('Option Body', () => {

expect(() => {
new ChowChow(fixture, {
responseBodyAjvOptions: { unknownFormats: 'ignore' },
responseBodyAjvOptions: {
formats: {
'pet-name': true,
},
},
});
}).not.toThrow();
});
Expand Down
36 changes: 15 additions & 21 deletions __test__/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ describe('Path', () => {
});

it('should validate the path parameters and coerce to the correct type', () => {
const pathMeta = {
method: 'get',
};
expect(chowchow.validateRequest('/pets/123', pathMeta)).toEqual(
const pathMeta = {};
expect(
chowchow.validateRequestByPath('/pets/123', 'get', pathMeta)
).toEqual(
expect.objectContaining({
path: {
petId: 123,
Expand All @@ -27,9 +27,7 @@ describe('Path', () => {

it('should throw error if path parameter fails schema check', () => {
expect(() => {
chowchow.validateRequest('/pets/abc', {
method: 'get',
});
chowchow.validateRequestByPath('/pets/abc', 'get', {});
}).toThrowError(ChowError);
});
});
Expand All @@ -42,10 +40,10 @@ describe('Path', () => {
});

it('should validate the path parameters and coerce to the correct type', () => {
const pathMeta = {
method: 'get',
};
expect(chowchow.validateRequest('/pets/123', pathMeta)).toEqual(
const pathMeta = {};
expect(
chowchow.validateRequestByPath('/pets/123', 'get', pathMeta)
).toEqual(
expect.objectContaining({
path: {
petId: 123,
Expand All @@ -56,9 +54,7 @@ describe('Path', () => {

it('should throw error if path parameter fails schema check', () => {
expect(() => {
chowchow.validateRequest('/pets/abc', {
method: 'get',
});
chowchow.validateRequestByPath('/pets/abc', 'get', {});
}).toThrowError(ChowError);
});
});
Expand All @@ -71,10 +67,10 @@ describe('Path', () => {
});

it('should validate the path parameters and coerce to the correct type', () => {
const pathMeta = {
method: 'get',
};
expect(chowchow.validateRequest('/pets/123', pathMeta)).toEqual(
const pathMeta = {};
expect(
chowchow.validateRequestByPath('/pets/123', 'get', pathMeta)
).toEqual(
expect.objectContaining({
path: {
petId: 123,
Expand All @@ -85,9 +81,7 @@ describe('Path', () => {

it('should throw error if path parameter fails schema check', () => {
expect(() => {
chowchow.validateRequest('/pets/abc', {
method: 'get',
});
chowchow.validateRequestByPath('/pets/abc', 'get', {});
}).toThrowError(ChowError);
});
});
Expand Down
Loading

0 comments on commit b90c88c

Please sign in to comment.