ruby-grape / ruby-grape/grape

Make parameters required or optional later

Open
#829 9 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

Good day! I have a suggestion. The next code illustrates it:

class API < Grape::API
  helpers do
    params :car do
      param :name, type: String # param is a synonim for optional
      param :desc, type: String
    end
  end

  params do
    use :car
    requires :name
    optional :desc
  end
  post do
     # Create a car. Name is required.
  end

  params do
    use :car
    optional :name, :desc
  end
  put do
     # Update the car. Nothing is required.
  end
end

UPD: Another example:

params do
  param :name, type: String # param is a synonim for optional
  param :desc, type: String
end
namespace :cars do
  params do
    requires :name
  end
  post do
    # name required, not desc
  end

  put do
    # name, desc are optional
  end
end

What's your opinion? Thanks.

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

Review the existing parameter declaration behavior behind the examples, including how shared params are reused by POST and PUT endpoints. Clarify the intended precedence between param, requires, and optional, then add coverage for both examples; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.