ruby-grape / ruby-grape/grape-entity
Using entities as grape params cause invalid fields?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
Hi this is my code. When I'm using entities as grape params, whenever i do a post request, it returns me name invalid, email invalid, id invalid, etc. Everything is invalid, is there anything i did wrong here? I couldn't find a lot of documentation on this though
desc 'Create a customer.'
params {
requires :none, except: [:name, :email], using: Entities::Customer.documentation.except(:id)
}
post do
present Customer.create! params, with: Entities::Customer
end
class Customer< Grape::Entity
expose :id, documentation: { type: "string" } do |model| model.id.to_s end
expose :name, documentation: { type: "string" }
expose :contact_details do
expose :emailaddress, documentation: { type: "string" }
expose :address, documentation: { type: "string" }
expose :phone, documentation: { type: "string" }
end
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the params block and Entities::Customer.documentation shown in the issue, then reproduce the POST request that marks every field invalid. Trace how the entity documentation is used for parameter validation; done means identifying the cause and confirming a valid request accepts the intended customer fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100