ruby-grape / ruby-grape/grape-swagger

require and optional with block

Open
#612 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.1k
Forks
479
Avg merge
2d 14h
Merged PRs (30d)
6

Description

First a part of my definition code,

      params do
        requires :id, type: Integer
        optional :text, type: String, regexp: /\A[a-z]+\z/
        group :group_params, type: Hash do
          requires :require_param
          optional :optional_param
        end
        requires :requires_params, type: Hash do
          optional :optional_param1
          optional :optional_param2
        end
        optional :optional_params, type: Hash do
          requires :require_param
          optional :optional_param
        end
      end

From my perspective,

  • group_params[require_param] is required,
  • group_params[optional_param], require_params[optional_param1], require_params[optional_param2], optional_params[require_param] and optional_params[optional_param] is not required.
  • If I pass optional_params[optional_param], then optional_params[require_param] is required.


Part of the instance variable @options of API

   :forward_match => nil,
           :suffix => "(.:format)",
           :params => {
                                      "id" => {
            :required => true,
                :type => "Integer"
        },
                                    "text" => {
            :required => false,
                :type => "String"
        },
                            "group_params" => {
            :required => true,
                :type => "Hash"
        },
             "group_params[require_param]" => {
            :required => true
        },
            "group_params[optional_param]" => {
            :required => false
        },
                         "requires_params" => {
            :required => true,
                :type => "Hash"
        },
        "requires_params[optional_param1]" => {
            :required => false
        },
        "requires_params[optional_param2]" => {
            :required => false
        },
                         "optional_params" => {
            :required => false,
                :type => "Hash"
        },
          "optional_params[require_param]" => {
            :required => true
        },
         "optional_params[optional_param]" => {
            :required => false
        }
    }


But what I got from the swagger documentation was as below:

parameters": [

    {
        "in": "query",
        "name": "id",
        "type": "integer",
        "format": "int32",
        "required": true
    },
    {
        "in": "query",
        "name": "text",
        "type": "string",
        "required": false
    },
    {
        "in": "query",
        "name": "group_params[require_param]",
        "type": "string",
        "required": true
    },
    {
        "in": "query",
        "name": "group_params[optional_param]",
        "type": "string",
        "required": false
    },
    {
        "in": "query",
        "name": "requires_params[optional_param1]",
        "type": "string",
        "required": false
    },
    {
        "in": "query",
        "name": "requires_params[optional_param2]",
        "type": "string",
        "required": false
    },
    {
        "in": "query",
        "name": "optional_params[require_param]",
        "type": "string",
        "required": true
    },
    {
        "in": "query",
        "name": "optional_params[optional_param]",
        "type": "string",
        "required": false
    }

],

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

The report does not name a source file or test. Start from handling of nested Grape group, requires, and optional blocks, then trace the Swagger parameter generation that produces the shown list. Verify the generated documentation against the stated required and conditional requirements; done means the output matches those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, ruby
Domain
api, documentation
Issue type
Bug
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.