Skip to content

Commit

Permalink
Patch on serdes test and allow to use generated AJV out of Express us…
Browse files Browse the repository at this point in the history
…age (cdimascio#684)

* Try catch serdes serialize and deserialize in order to avoid Internal Server Error and return BadRequest errors cdimascio#601

* Fix incorrect serDes example cdimascio#569

* fix the unit test and change message to a more human friendly description of the error cdimascio#601

* Allow to get the generated request AJV object in order to use it out of an OpenAPI and express usage (websocket...)
cdimascio#683

* Add documentation for OpenApiValidator.ajv function initialization usage
cdimascio#683

* ResponseValidator's Ajv can be useful too.
So we return an object that contains both request ajv and response ajv :
```javascript
ajvs = {
  req : 'Ajv object'
  res : 'Ajv object'
}
```
cdimascio#683

* fix the unit test and change message to a more human friendly description of the error cdimascio#601

* Allow to get the generated request AJV object in order to use it out of an OpenAPI and express usage (websocket...)
cdimascio#683

* Add documentation for OpenApiValidator.ajv function initialization usage
cdimascio#683

* ResponseValidator's Ajv can be useful too.
So we return an object that contains both request ajv and response ajv :
```javascript
ajvs = {
  req : 'Ajv object'
  res : 'Ajv object'
}
```
cdimascio#683

* Revert commits in order to push only bug fixes
cdimascio#601

* Revert "ResponseValidator's Ajv can be useful too."

This reverts commit 677cacf.

* Revert "Add documentation for OpenApiValidator.ajv function initialization usage"

This reverts commit a727f2d.

* Revert "Allow to get the generated request AJV object in order to use it out of an OpenAPI and express usage (websocket...)"

This reverts commit ad3e785.

* Revert "ResponseValidator's Ajv can be useful too. So we return an object that contains both request ajv and response ajv : ```javascript ajvs = {   req : 'Ajv object'   res : 'Ajv object' } ``` cdimascio#683"

This reverts commit 8fc7226

* Revert "Add documentation for OpenApiValidator.ajv function initialization usage"

This reverts commit ecb8424.

* Revert "Allow to get the generated request AJV object in order to use it out of an OpenAPI and express usage (websocket...)"

This reverts commit 52429c5.

Co-authored-by: Carmine DiMascio <cdimasci@amazon.com>
  • Loading branch information
pilerou and cdimascio authored Dec 26, 2021
1 parent 56f778b commit 3744cdd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/framework/ajv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ function createAjv(
obj[propName] = sch.deserialize(data);
}
catch(e) {
(<ajv.ValidateFunction>validate).errors = [
{
keyword: 'serdes',
schemaPath: data,
dataPath: path,
message: `format is invalid`,
params: { 'x-eov-serdes': propName },
},
];
return false;
}
}
Expand Down Expand Up @@ -108,6 +117,15 @@ function createAjv(
obj[propName] = sch.serialize(data);
}
catch(e) {
(<ajv.ValidateFunction>validate).errors = [
{
keyword: 'serdes',
schemaPath: data,
dataPath: path,
message: `format is invalid`,
params: { 'x-eov-serdes': propName },
},
];
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/serdes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ describe('serdes serialize response components only', () => {
.expect(500)
.then((r) => {
console.log(r);
expect(r.body.message).to.equal('d.toISOString is not a function');
expect(r.body.message).to.equal('.response.creationDate format is invalid');
}));

/*
FIXME Manage format validation after serialize ? I can serialize using a working serialize method but that respond a bad format
it('should throw error 500 on an object that serialize to a bad string format', async () =>
request(app)
.get(`${app.basePath}/users/5fdefd13a6640bb5fb5fa925`)
.query({baddateresponse : 'functionBadFormat'})
Expand All @@ -322,7 +322,7 @@ describe('serdes serialize response components only', () => {
console.log(r.body);
expect(r.body.message).to.equal('Something saying that date is not date-time format');
}));
*/

});
Expand Down

0 comments on commit 3744cdd

Please sign in to comment.