OAI / OpenAPI-Specification

The OpenAPI Specification Repository
https://openapis.org
Apache License 2.0
29.03k stars 9.07k forks source link

Error: Parameter (x) failed schema validation #503

Closed yasirbam closed 8 years ago

yasirbam commented 9 years ago

Hi

I have created a specification using the Swagger Editor and deployed the generated server code for Nodejs on a server. I am getting the following error when trying the Post /emailjobs method. I am not sure what I am doing wrong, I am hopping someone can point me to the issue.

thanks

Error: Parameter (emailJob) failed schema validation<br> &nbsp; &nbsp;at throwErrorWithCode (/home/ubuntu/nodejs-server/node_modules/swagger-tools/lib/validators.js:97:13)<br> &nbsp; &nbsp;at Object.validateAgainstSchema (/home/ubuntu/nodejs-server/node_modules/swagger-tools/lib/validators.js:126:7)<br> &nbsp; &nbsp;at /home/ubuntu/nodejs-server/node_modules/swagger-tools/middleware/swagger-validator.js:119:22<br> &nbsp; &nbsp;at /home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:246:17<br> &nbsp; &nbsp;at /home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:122:13<br> &nbsp; &nbsp;at _each (/home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:46:13)<br> &nbsp; &nbsp;at async.each (/home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:121:9)<br> &nbsp; &nbsp;at _asyncMap (/home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:245:13)<br> &nbsp; &nbsp;at Object.map (/home/ubuntu/nodejs-server/node_modules/swagger-tools/node_modules/async/lib/async.js:216:23)<br> &nbsp; &nbsp;at validateValue (/home/ubuntu/nodejs-server/node_modules/swagger-tools/middleware/swagger-validator.js:112:11)

And here is the Swagger.json

{
    "swagger": "2.0",
    "info": {
        "version": "0.0.1",
        "title": "test swagger API",
        "description": "A test mock API .",
        "contact": {
            "name": "CCS API team",
            "email": "foo@example.com",
            "url": "http://test.com"
        }
    },
    "basePath": "/api/v0",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/test": {
            "post": {
                "description": "Test post",
                "operationId": "addTest",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "pet",
                        "in": "body",
                        "description": "Pet to add",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/newPet"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "pet response",
                        "schema": {
                            "$ref": "#/definitions/pet"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs": {
            "post": {
                "description": "Creates a new email distribution job. Takes an email distribution job object containing the body of the email, a list of recipients and a list of attachments",
                "operationId": "addEmailJob",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "emailJob",
                        "in": "body",
                        "description": "Email job content.",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/emailJob"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email response",
                        "schema": {
                            "$ref": "#/definitions/emailJobResponse"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "get": {
                "description": "Returns a list of email distribution jobs from the system that the user has access to. NOT SURE IF WE SHOULD PROVIDE THIS. THIS MAY BE ADDED AS A REPORT",
                "operationId": "findEmailJob",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "from",
                        "in": "query",
                        "description": "from date in utc using iso 8061 format",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "description": "to date in utc using iso 8061 format",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "maximum number of results to return",
                        "required": false,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/emailJob"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs/{jobid}": {
            "get": {
                "description": "Returns an email distribution job based on a single Job Id",
                "operationId": "findEmailJobById",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "jobid",
                        "in": "path",
                        "description": "Job ID of email distribution to fetch",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email response object",
                        "schema": {
                            "$ref": "#/definitions/emailJob"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs/status/": {
            "get": {
                "description": "Returns the status for a list of email jobs",
                "operationId": "findEmailJobStatus",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "from",
                        "in": "query",
                        "description": "from date in utc using iso 8061 format",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "description": "to date in utc using iso 8061 format",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "maximum number of results to return",
                        "required": false,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email job status response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/emailJobStatus"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs/status/{jobid}": {
            "get": {
                "description": "Returns the status of an email distribution job based on a single Job Id",
                "operationId": "findEmailJobStatusById",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "jobid",
                        "in": "path",
                        "description": "Email Job Id to fetch",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email job status response",
                        "schema": {
                            "$ref": "#/definitions/emailJobStatus"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs/status/{jobid}/recipient/{email}": {
            "get": {
                "description": "Returns the status for a single recipient of a single email job",
                "operationId": "findRecipientStatusById",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "jobid",
                        "in": "path",
                        "description": "Email Job Id to fetch",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "email",
                        "in": "path",
                        "description": "email to fetch",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email job status response",
                        "schema": {
                            "$ref": "#/definitions/emailRecipientStatus"
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        },
        "/emailjobs/status/{jobid}/recipient/": {
            "get": {
                "description": "Returns the status for all the recipients in a email job",
                "operationId": "findRecipientStatus",
                "produces": [
                    "application/json",
                    "application/xml",
                    "text/html"
                ],
                "parameters": [
                    {
                        "name": "jobid",
                        "in": "path",
                        "description": "jobId",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "description": "from date in utc using iso 8061 format",
                        "required": true,
                        "type": "string",
                        "format": "date-time"
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "description": "to date in utc using iso 8061 format",
                        "required": true,
                        "type": "string",
                        "format": "date-time"
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "maximum number of results to return",
                        "required": false,
                        "type": "integer",
                        "format": "int32"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "email recipient status response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/emailRecipientStatus"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "emailJob": {
            "type": "object",
            "required": [
                "ApplicationId",
                "DistributionType",
                "From",
                "Subject"
            ],
            "properties": {
                "ApplicationId": {
                    "type": "string",
                    "description": "GNW or IR"
                },
                "Reference": {
                    "type": "string",
                    "description": "A reference such as clientID"
                },
                "DistributionType": {
                    "type": "string",
                    "description": "1=email, 2=fax, 3=sms",
                    "default": "1"
                },
                "Dkim-Signature": {
                    "type": "string",
                    "description": "Dkim-Signature"
                },
                "NumberOfRetries": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Number of retries -- default =3 , max=5",
                    "default": 1
                },
                "RetryIntervalInSecond": {
                    "type": "string",
                    "description": "Number of seconds the system will wait before attempting a retry. default 60 seconds.",
                    "default": "60"
                },
                "CostCentre": {
                    "type": "string",
                    "description": "cost centre for billing purposes"
                },
                "From": {
                    "type": "string",
                    "description": "senders from email address"
                },
                "LanguageCode": {
                    "type": "string",
                    "description": "language ISO code",
                    "default": "eng-gb"
                },
                "CharSet": {
                    "type": "string",
                    "description": "character set, default to utf-8",
                    "default": "utf-8"
                },
                "Priority": {
                    "type": "integer",
                    "format": "int32",
                    "description": "priority 0 low, 10 very hight",
                    "default": 1
                },
                "ReplyTo": {
                    "type": "string",
                    "description": "replyto email"
                },
                "ScheduleTimeUTC": {
                    "type": "string",
                    "description": "Date and time to send out in UTC. in yyyy-mm-ddThh:mm:ss format. if not specified, it will be send out immediatly"
                },
                "Subject": {
                    "type": "string",
                    "description": "title of the communication"
                },
                "TemplateName": {
                    "type": "string",
                    "description": "Name of a template to use",
                    "default": "Template A"
                },
                "Attachments": {
                    "type": "array",
                    "description": "List of attachments",
                    "items": {
                        "$ref": "#/definitions/attachment"
                    }
                },
                "Recipients": {
                    "type": "array",
                    "description": "List of recipients to send the distribution to",
                    "items": {
                        "$ref": "#/definitions/recipient"
                    }
                }
            }
        },
        "linkStatus": {
            "type": "object",
            "properties": {
                "url": {
                    "type": "string"
                },
                "clicks": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Number of times url was clicked"
                }
            }
        },
        "emailJobStatus": {
            "type": "object",
            "properties": {
                "JobId": {
                    "type": "string",
                    "description": "Job ID"
                },
                "JobSizeInByte": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Number of emails send per second for this job"
                },
                "SubmittedDate": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Submittion date UTC"
                },
                "TotalRecipients": {
                    "type": "integer",
                    "format": "int32"
                },
                "TotalSent": {
                    "type": "integer",
                    "format": "int32"
                },
                "TotalRead": {
                    "type": "integer",
                    "format": "int32"
                },
                "TotalBouncd": {
                    "type": "integer",
                    "format": "int32"
                },
                "TotalUnsubscribed": {
                    "type": "integer",
                    "format": "int32"
                },
                "DuplicateCount": {
                    "type": "integer",
                    "format": "int32"
                },
                "StartedProcessingOn": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Job started processing on date UTC"
                },
                "CompletedProcessingON": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Jon completed processing on UTC"
                },
                "LastStatus": {
                    "type": "string",
                    "description": "Job status"
                },
                "AverageThroughput": {
                    "type": "integer",
                    "format": "int32"
                },
                "LinkStatus": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/linkStatus"
                    }
                }
            }
        },
        "emailRecipientStatus": {
            "type": "object",
            "properties": {
                "jobId": {
                    "type": "string",
                    "description": "Email Job Id"
                },
                "Email": {
                    "type": "string",
                    "description": "Email address"
                },
                "SubmittedDate": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Job submitted on date UTC"
                },
                "StartedProcessingOn": {
                    "type": "string",
                    "description": "started processing email on date UTC"
                },
                "CompletedProcessingOn": {
                    "type": "string",
                    "format": "date-time",
                    "description": "date/time processing completed in UTC"
                },
                "LastStatus": {
                    "type": "string",
                    "description": "Status of email distribution"
                },
                "IsRead": {
                    "type": "boolean"
                },
                "DateRead": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Datetime UTC the email was read"
                },
                "IsUnSubscribed": {
                    "type": "boolean",
                    "description": "Boolean indicating if user has unsubscribed"
                },
                "DateUnsubscribed": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Datetime UTC when user unsubscribed"
                },
                "IsDuplicate": {
                    "type": "boolean",
                    "description": "Boolean indicating if the email was duplicate within this job"
                },
                "NumberOfAttempts": {
                    "type": "integer",
                    "format": "int32",
                    "description": "Number of times an attempt was made to send the email"
                },
                "UserAgent": {
                    "type": "string",
                    "description": "user agent"
                },
                "LinkStatus": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/linkStatus"
                    }
                }
            }
        },
        "recipient": {
            "type": "object",
            "properties": {
                "email": {
                    "type": "string"
                },
                "title": {
                    "type": "string"
                },
                "firstname": {
                    "type": "string"
                },
                "lastname": {
                    "type": "string"
                },
                "mailmerge_params": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/mailmerge_params"
                    }
                }
            }
        },
        "attachment": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "contentType": {
                    "type": "string",
                    "description": "content type"
                },
                "filename": {
                    "type": "string"
                },
                "content": {
                    "type": "string",
                    "format": "binary"
                }
            }
        },
        "mailmerge_params": {
            "type": "object",
            "properties": {
                "key": {
                    "type": "string",
                    "description": "The name of the field that will be mailmerged. This field must exist as a placeholder in the content"
                },
                "value": {
                    "type": "string",
                    "description": "The value that will be replaced"
                }
            }
        },
        "emailJobResponse": {
            "type": "object",
            "properties": {
                "jobId": {
                    "type": "string",
                    "description": "Job Id for the newly created job."
                }
            }
        },
        "errorModel": {
            "type": "object",
            "required": [
                "code",
                "message"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "format": "int32",
                    "description": "HTTP code"
                },
                "message": {
                    "type": "string",
                    "description": "Error message"
                }
            }
        },
        "pet": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        },
        "newPet": {
            "type": "object",
            "required": [
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        }
    }
}
webron commented 9 years ago

Is this using swagger-tools directly or swagger-node?

yasirbam commented 9 years ago

i used the online tool http://editor.swagger.io/#/ to build the json, then used Generate server from the menu to generate the nodejs server side code. thanks for the quick reply

webron commented 9 years ago

It's most likely that you're trying to run that API call with a request body that doesn't conform with the definition you've given it.

yasirbam commented 9 years ago

thanks, the issue was with this line, "format": "binary"

webron commented 8 years ago

Can we close this out?