ruby-grape / ruby-grape/grape-swagger
Dependent parameter shows up as required
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.1k
- Forks
- 479
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Grape has the concept of dependent parameters, which is not supported in OpenAPI specs currently (although there is an issue for it). I have found that given something simple like:
params do
optional :a, type: String
given :a do
requires :b, type: String
end
end
will cause the generated OpenAPI spec to have the :b parameter listed as a required parameter for the request.
This functionality is not supported in OpenAPI specs so there isn't a "correct" answer, but I believe that the attribute dependent on another attribute should default to the other attribute's status. If attribute :a was required and there was a dependent attribute then obviously it would also be required and would show up as such. But if :a is optional, and :b is only required when :a is present, then it seems that :b is also optional since a request with neither :a nor :b is still valid.
@LeFnord, is this something you guys would be receptive to as a change? I know it isn't following OpenAPI specs since this lies outside of it, but it seems correct to me. If you are open to it, I can make a PR to change the functionality.
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
Reproduce the issue with the Grape params block using optional :a and dependent required :b, then inspect how the generated OpenAPI spec determines parameter requiredness. Add coverage for optional and required parent parameters; done when :b is not marked required for optional :a but is marked required when :a is required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, ruby
- Domain
- api, documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100