z0mt3c/hapi-swaggered-ui

Quoting issues when using Joi validation on delete route

Closed this issue · 3 comments

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?

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

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

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