Skip to content

Doc Update Request: Nested re-usable params #2313

Open
@rwilliams3088

Description

@rwilliams3088

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions