How to validate Path variable in Play Framework

255 views Asked by At

I'm developing a scala Application with play framework. i validate the request body using play json schema validator and the validation works perfect, i'm validating the the path variable using filter but my problem is i have to get every pattern and trying to match the url which i received then i have to split them into array then i need to execute my validation, it's pretty hard to do it and it needs a lot of code in order to validate the path variables, i have around 80 API each api has different path variable, it's unlogical to create 80 filter or 80 action builder, im wondering if there is something like play json schema validator, or can i merge it to take another attribute. orderId should be passed by path variable here is my schema

{
  "properties": {
    "vouchersCount": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "orderId": {
      "type": "integer",
      "minimum": 50,
      "maximum": 90,
      "in": "path"
    },
    "comments": {
      "type": "string"
    }
  },
  "required": [
    "vouchersCount",
    "comments",
    "orderId"
  ]
}

Thanks for any suggestions

1

There are 1 answers

1
Rich Dougherty On BEST ANSWER

I don't think there's something already out there to do this for you. You'll probably need to write your own logic. You don't need to write 80 filters or 80 action builders, you could write one that loads your schema and then uses that to produce 80 different types of behaviour. Unfortunately you'll probably need to write it yourself because this doesn't already exist. If you want to have a go writing it then you can ask more questions.