Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc Update Request: Nested re-usable params #2313

Open
rwilliams3088 opened this issue Apr 6, 2023 · 1 comment
Open

Doc Update Request: Nested re-usable params #2313

rwilliams3088 opened this issue Apr 6, 2023 · 1 comment

Comments

@rwilliams3088
Copy link

I'm attempting was attempting to define a re-usable params type and make use of it for a request. The result is I get this: NameError (uninitialized constant Grape::Validations::Types::SymbolCoercer).

Here is my re-usable param structure:

   helpers do
      params :identifier_type do
        optional :id, type: String
        optional :name, type: String
        exactly_one_of :id, :name
      end
  end

Since there was no clear examples in the docs of how to go about it, I was trying things like this - which just gave me errors.

params do
  required :identifier, type: :identifier_type
end
post '' do
  ...
end

Eventually, I found a pattern that works:

params do
  required :identifier, type: Hash do
    use :identifier_type
  end
end
post '' do
  ...
end

Adding something like this to the documentation would be helpful for others, I think

@dblock
Copy link
Member

dblock commented Apr 6, 2023

Definitely a yes on documentation, please PR!

We could probably improve the error here. It is trying to coerce a symbol and you get a SymbolCoercer error.

While type: :identifier_type seems nice, maybe it's too nice and we should not allow to say type: <something that's not actually a type>. If you think it's a great idea, maybe try to PR it? Implementing a SymbolCoercer would do it, but I think it won't be that easy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants