express-openapi-validator
Advanced tools
Comparing version
@@ -28,5 +28,15 @@ "use strict"; | ||
return function validate(data, path, obj, propName) { | ||
if (typeof data === 'object') | ||
return true; | ||
if (!!sch.deserialize) { | ||
if (typeof data !== 'string') { | ||
validate.errors = [ | ||
{ | ||
keyword: 'serdes', | ||
schemaPath: data, | ||
dataPath: path, | ||
message: `must be a string`, | ||
params: { 'x-eov-serdes': propName }, | ||
}, | ||
]; | ||
return false; | ||
} | ||
obj[propName] = sch.deserialize(data); | ||
@@ -39,2 +49,3 @@ } | ||
}, | ||
// errors: 'full', | ||
}); | ||
@@ -41,0 +52,0 @@ } |
@@ -55,2 +55,3 @@ import * as ajv from 'ajv'; | ||
format: string; | ||
jsonType?: string; | ||
serialize?: (o: unknown) => string; | ||
@@ -63,2 +64,3 @@ deserialize?: (s: string) => unknown; | ||
format: string; | ||
jsonType: string; | ||
serialize?: (o: unknown) => string; | ||
@@ -68,2 +70,3 @@ deserialize?: (s: string) => unknown; | ||
format: string; | ||
jsonType?: string; | ||
serialize: (o: unknown) => string; | ||
@@ -70,0 +73,0 @@ deserialize: (s: string) => unknown; |
@@ -7,2 +7,3 @@ "use strict"; | ||
this.format = param.format; | ||
this.jsonType = param.jsonType || 'object'; | ||
this.serialize = param.serialize; | ||
@@ -12,2 +13,3 @@ this.deserialize = param.deserialize; | ||
format: param.format, | ||
jsonType: param.jsonType || 'object', | ||
deserialize: param.deserialize | ||
@@ -17,2 +19,3 @@ }; | ||
format: param.format, | ||
jsonType: param.jsonType || 'object', | ||
serialize: param.serialize | ||
@@ -19,0 +22,0 @@ }; |
@@ -224,3 +224,6 @@ "use strict"; | ||
const newSchema = JSON.parse(JSON.stringify(schemaObj)); | ||
newSchema.properties = Object.assign(Object.assign({}, ((_m = o.properties) !== null && _m !== void 0 ? _m : {})), ((_o = newSchema.properties) !== null && _o !== void 0 ? _o : {})); | ||
const newProperties = Object.assign(Object.assign({}, ((_m = o.properties) !== null && _m !== void 0 ? _m : {})), ((_o = newSchema.properties) !== null && _o !== void 0 ? _o : {})); | ||
if (Object.keys(newProperties).length > 0) { | ||
newSchema.properties = newProperties; | ||
} | ||
newSchema.required = o.required; | ||
@@ -249,3 +252,3 @@ if (newSchema.required.length === 0) { | ||
this.serDesMap[schema.format]) { | ||
schema.type = ['object', 'string']; | ||
schema.type = [this.serDesMap[schema.format].jsonType || 'object', 'string']; | ||
schema['x-eov-serdes'] = this.serDesMap[schema.format]; | ||
@@ -252,0 +255,0 @@ } |
{ | ||
"name": "express-openapi-validator", | ||
"version": "4.13.0", | ||
"version": "4.13.1", | ||
"description": "Automatically validate API requests and responses with OpenAPI 3 and Express.", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.js", | ||
"media-typer": "^1.1.0", | ||
"multer": "^1.4.2", | ||
"multer": "^1.4.3", | ||
"ono": "^7.1.3", | ||
@@ -47,0 +47,0 @@ "path-to-regexp": "^6.2.0" |
@@ -770,2 +770,3 @@ # 🦋 express-openapi-validator | ||
- `serialize` (optional) - before sending a response, transform an object to string. Serialization occurs _after_ response schema validation | ||
- `jsonType` (optional, default 'object') - set to override for deserialized types that are not 'object', eg 'array' | ||
@@ -1311,2 +1312,5 @@ e.g. | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/alonsohki"><img src="https://avatars.githubusercontent.com/u/165835?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alberto Alonso</b></sub></a><br /><a href="https://github.com/cdimascio/express-openapi-validator/commits?author=alonsohki" title="Code">💻</a></td> | ||
</tr> | ||
</table> | ||
@@ -1313,0 +1317,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
393606
0.5%5792
0.35%1338
0.3%Updated