Closed zdne closed 9 years ago
Is there a concept of header validation planned? Common headers have a very specific syntax (like link headers) and most custom headers could be validated with basic type checking or regexes.
@ecordell
Nothing besides what is in Dredd / Gavel. This is mainly a design goal - to get rid of as most of pre code blocks as possible while unifying syntax (=making it easier to learn) for parameters, body attributes and headers...
@zdne
Do you have thoughts about how header validation should be handled?
It seems like header validation should be supported: If a POST should return a Location header, and the API responds with a valid Location header but which is not the exact location that's documented in the blueprint, Dredd will say that the docs/api are out of sync when they're actually perfectly fine.
Standard headers (like Link) have some default formatting rules they must comply with, so it would be easy to bake in validation for that in Gavel(?). Custom headers or custom validation of standard headers could be validated pretty simply with a regex. Seem reasonable?
The only question then would be if there should be a syntax in the blueprint for saying either 1) the header must contain this value exactly or 2) the header must validate against this pattern (sort of how the Body can match text exactly or a schema).
Edit with possible design: header should match exactly
+ Headers
+ Location (string, `/some/uri`) ... URI of the created user account
header should validate against a regex
+ Headers
+ Location (string, `/some/uri`, `regex_string`) ... URI of the created user account
@ecordell
I feel like writing regexes into blueprint is far from what is readable for most of the users. However some out-of-the-box headers validation would be great.
Note there is already the preliminary support for "header schema" in Gavel. Which leads me to following idea (just brainstorming here):
The parametric headers definition should in fact generate a header schema if not provided. So really the question here is whether add the dedicated syntax for the regexes...
RFC proposal of syntax addressing this issue: https://github.com/apiaryio/api-blueprint-rfcs/pull/3.
Please track and comment on the RFC.
Thank you!
Documentation of HTTP headers using syntax similar to URI parameters.
e.g.