krakenjs / swaggerize-routes

Swagger document driven route builder.
Other
58 stars 57 forks source link

Incorrect property path on validation errors #63

Open pmeinhardt opened 8 years ago

pmeinhardt commented 8 years ago

Hi, I am currently using swaggerize-express/-routes in a client project and find it to be really useful.

However, I have noticed that the property path is set incorrectly for nested objects on input validation. I.e. I have a swagger.json which contains sth. like the following (following the JSON API spec):

{
  "consumes": [ "application/json" ],
  "produces": [ "application/json" ],
  // …
  "parameters": [{
    "name": "body",
    "in": "body",
    "required": true,
    "schema": {
      "type": "object",
      "required": [ "data" ],
      "properties": {
         "data": {
            "type": "object",
            "required": [ "type", "attributes" ],
            "properties": {
                "type": { "type": "string" },
                "attributes": { "type": "object", … }
            }
         }
      }
    }
  }]
}

So any input JSON object is required to have data.type (string) and data.attributes (object).

When a validation for a nested property fails though, the "path" provided in the error details contains only the property name, not the full path – i.e. type instead of data.type or email instead of data.attributes.email.

This is the source line that looks like the chief culprit: https://github.com/krakenjs/swaggerize-routes/blob/910c3908b3986288c8b9f72870a9048bdeb535a0/lib/validator.js#L117

Is there a particular reason for replacing the original detail.path with the parameter.name?

Cheers and thanks a lot!