z0mt3c / hapi-swaggered-ui

An easy swagger-ui drop-in plugin for hapi (to be used with hapi-swaggered).
39 stars 31 forks source link

Quoting issues when using Joi validation on delete route #16

Closed delaneyj closed 9 years ago

delaneyj commented 9 years ago

I have a validation scheme

{
  playerIds: Joi.array().items(Joi.string().guid()).required()
}

and say i send a bad message of {"playerIds": ["string"]}

That works great for POST/PUT payload/body validation and GET reply. However when using DELETE method via the hapi-swaggered parameter window. I get this.

{
  "success": false,
  "error": {
    "type": "ValidationError",
    "description": "child \"playerIds\" fails because [\"playerIds\" is required]. \"{
  "playerIds": \" is not allowed",
    "details": [
      {
        "message": "\"playerIds\" is required",
        "path": "playerIds",
        "type": "any.required",
        "context": {
          "key": "playerIds"
        }
      },
      {
        "message": "\"{
  "playerIds": \" is not allowed",
        "path": "{\n  \"playerIds\": ",
        "type": "object.allowUnknown",
        "context": {
          "key": "{\n  \"playerIds\": "
        }
      }
    ]
  }
}

Note that if I use POSTman or curl with the same json it gives the proper validation error of

{
  "success": false,
  "error": {
    "type": "ValidationError",
    "description": "child \"playerIds\" fails because [\"playerIds\" at position 0 fails because [\"0\" must be a valid GUID]]",
    "details": [
      {
        "message": "\"0\" must be a valid GUID",
        "path": "playerIds.0",
        "type": "string.guid",
        "context": {
          "value": "string",
          "key": 0
        }
      }
    ]
  }
}

It appears DELETE's param window is somehow escaping things improperly. Any thoughts?

z0mt3c commented 9 years ago

funny, need to have a look... most obviously it's an issue in swagger-ui

z0mt3c commented 9 years ago

I guess it's related to: swagger-api/swagger-ui#1435

delaneyj commented 9 years ago

There appears to be a fix in the works. Thanks for looking out and hopefully its gets fixed soon.