Schema validation
See original GitHub issueHello there! I’m trying to get fastify-multipart form and fastify/ajv schema validation to work together in a restfull api. But I still get an error :
{
"statusCode": 400,
"error": "Bad Request",
"message": "body should be object",
"validation": [
{
"keyword": "type",
"dataPath": "",
"schemaPath": "#/type",
"params": {
"type": "object"
},
"message": "should be object"
}
],
"code": "BadRequest"
}
I’ve extented AJV with a fileType
ajv.addKeyword("isFileType", {
compile: (schema, parent, it) => {
// Change the schema type, as this is post validation it doesn't appear to error.
(parent as any).type = "file";
delete (parent as any).isFileType;
return () => true;
},
});
Here is my schema
{
"consumes": ["multipart/form-data"],
"body": {
"type": "object",
"properties": {
"urbanFile": {
"isFileType": true,
"type": "object"
},
"authorizationType": {
"type": "string",
"enum": [
"buildingPermit",
"planningPermit",
"demolitionPermit"
]
},
}
and here is my handler function
const mutliPart = request.multipart(
function fileHandler(field, file, filename, encoding, mimetype) {
console.log("file is in " + field + " and is named " + filename);
},
function done(error) {
if (error) {
throw error;
}
}
);
mutliPart.on('field', function (key, value) {
console.log('form-data', key, value)
})
reply.status(201).send("Victory");
Is this a bug ? or am I doing something wrong? any help on this would be much much appreciated.
Cheers, Olivier
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Schema Markup Validator
Schema.org. menu. Documentation · Schemas · About. public. NEW TEST. languages ... help_outline. play_arrow. VALIDATE.
Read more >Schema Validation — MongoDB Manual
Schema validation lets you create validation rules for your fields, such as allowed data types and value ranges. MongoDB uses a flexible schema...
Read more >Schema Markup Testing Tool | Google Search Central
Schema Markup Validator. Validate all Schema.org-based structured data that's embedded in web pages, without Google feature specific warnings. Go to the Schema ......
Read more >A Vocabulary for Structural Validation of JSON - JSON Schema
JSON Schema validation asserts constraints on the structure of instance data. An instance location that satisfies all asserted constraints is then annotated ...
Read more >JSON Schema Validator - Newtonsoft
View source code. An online, interactive JSON Schema validator. Supports JSON Schema Draft 3, Draft 4, Draft 6, Draft 7 and Draft 2019-09....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@chenchuraviteja what is your validation schema ?
validation schema
schema: { tags: [{ name: ‘Category’ }], description: ‘Post category data’, consumes: [ “multipart/form-data” ], body: { type: ‘object’, properties: { name: { type: ‘string’ }, thumg_url: { isFileType: true, type: ‘object’ }, img_url: { isFileType: true, type: ‘object’ }, status: { type: ‘number’, enum: [0, 1], default: 1 } }, required: [‘name’, ‘thumg_url’, ‘img_url’] }, response: { 201: { type: ‘object’, properties: categoryProperties } } }