Validation in RAML 1.0


#1

Hello , I would like to know wether it is possible to add in .raml 1.0 validations for :slight_smile:

a. To validate that an attribute request is for instance not
null, or that it must comply with a regular expression, or if it allows custom
validations.

b. To validate that a header is not null, or that it must
comply with a regular expression, or if it allows custom validations.

c. To validate URL parameters.

Is there any example ???
Regards
Gorka


#2

I think that is almost very much implementation details and should stay like that. It’s hard to document these things. Do you really want to put them into your API design / documentation?


#3

Yah…what Christian said. To validate that in incoming request is not null (e.g. the body is not empty in a POST), that would definitely be implementation specific. Same with the header. To validate URL parameters, I believe you can define a resource type, such as URI with regex, and then specify that as the type of the parameter. However, the actual value for that parameter would not be available until the request was being made to an implementation.

What you can do with 1.0 is build your own parser that then generates the back end, like a JAXRS or Spring MVC or whatever, and add in some code in your generator that can produce code that then validates as you desire. This is one of the nice things with 1.0 and the annotations it now makes available. You can build a tool that generates something and define how the RAML should be written to take advantage of your parser capabilities.