Make parameters required or optional later
Open
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
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
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