ruby-grape / ruby-grape/grape-swagger
Cannot call helper methods
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
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
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