ruby-grape / ruby-grape/grape-swagger

Cannot call helper methods

Open
#652 0 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

I am trying to call helper methods defined in my API for the failure and success response. But am getting the not defined error. If I use the method defined inside the resource, it works perfectly. Is there no way to use the helper methods?

The below code throws the error

resource :users do
    desc "User Authentication API",
        summary: "This is the API used to authenticate the user"
        failure: [ invalid_login_credentials_error ],
        success: sign_in_successful_msg
    post :sign_in do
    ....
end

helpers do
    ....
    def invalid_login_credentials_error
        { code: 422, message: "Invalid email or password" }
    end
    ....
end

But the below one works perfectly

resource :users do

    def invalid_login_credentials_error
        { code: 422, message: "Invalid email or password" }
    end

    desc "User Authentication API",
        summary: "This is the API used to authenticate the user"
        failure: [ invalid_login_credentials_error ],
        success: sign_in_successful_msg
    post :sign_in do
    ....
end

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 helper lookup with the two snippets in the issue and trace how the failure and success values in desc are resolved. Identify the relevant API documentation entry point and add or update coverage for helpers defined in the API; done means the helper-based declarations behave consistently with methods defined inside the resource.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.