Open thedrow opened 8 years ago
for grape-swagger we had a similar discussion … one approach was, to define the header parameters for the request in the same manner as the other one, e.g.:
params do
requires :X-Rate-Limit-Limit, type: Integer, documentation: {desc: '…', param_type: 'header' }
end
this way, it could be used the params validations, what did you think? on the other side, the request params are consistent
at the moment, the header
key from the desc
block would be used, with the downside, you mentioned
IMO we want headers do
just like params do
reusing the exact implementation of params
.
@dblock Exactly what I was going to say
maybe we also need
body Entity
to simplify json schema from client.
with
params do
requires :user
end
client must post json like this
{
"user":
{
"id":"123"
}
}
I just want
{
"id":"123"
}
@pynixwang Your example should be
params do
requires :id
end
Body is read into params
as long as content-type is JSON or form or such.
@dblock swagger-doc show as formData, I want a Model Scheme. and I want just accept json not form...
Swagger is a whole other issue, but you cannot have it both ways - call something a user
and expect the DSL to ignore it. You can however move the declarations out of the params
part, and then use
that.
make a body DSL like
body :user
and do not merge hash into params, just put into prams so we can reference like params[user]
or new reference body[:user]
or just body
or something like object
and collection
for array.
@pynixwang Feel free to enable this with a pull request.
@dblock I 'm trying.
+1 I know this is old, but still feel it's relevant. We're half way there in that we can define headers to be re required or not inside the desc block See here. but it would also be nice to be able to validate them with the all_or_none_of, at_least_one_of
etc methods already present for params
Agreed...would love to see header validation DSL matching params validation DSL.
Currently there is no way to validate headers with Grape using the DSL. It'd be useful to be able to specify that a header must be present or must be equal to something without coding it manually. Providing a header validation DSL can help you say things like: