ruby-grape / ruby-grape/grape

Provide a generic interface for requires: complex type.

Open
#827 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

http://pastebin.com/QQV0NJ5K

  # Entity
  module API
  module Entities
    class Article < Grape::Entity
      expose :title, documentation: { type: 'string', desc: 'Title' }
      expose :body, documentation: { type: 'string', desc: 'Body' }
    end
  end
end

  # API
  desc "Create an article"
  params do
    requires :article, type: API::Entities::Article, documentation: { example: "aklsdfj" }
  end
  post '/articles' do
    puts params
    article = Article.create(params(:title, :body))
    represent(article, env)
  end

Currently:

# curl -X POST -H "Content-Type:application/json" 0:9292/v1/articles -d '{"title":"hello","body":"world"}'  
# {"error":"article is missing"}
# curl -X POST -H "Content-Type:application/json" 0:9292/v1/articles -d '{"article":{"title":"hello","body":"world"}}'
# {"error":"article is invalid"}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two request cases shown for the requires :article declaration and compare their missing and invalid responses. Trace the requires entry point and the post '/articles' example; done means a complex entity type can be accepted and validated through the generic interface without the current errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.