api_blueprint writer misses scope for scoped parameters
The formatter used is api_blueprint. The generated docs misses the scope for parameters. Other writers like html, json and markdown works good. But api_blueprint misses the scope key
This is my spec
resource "Invite",acceptance: true do
route '/v1/invite/send',name: "Invite" do
with_options :scope => :invitation, :required => true do
parameter :first_name, "first name"
parameter :last_name, "last name"
parameter :email, "email"
end
post 'send invite' do
context 'valid params' do
example_request 'failed' do
expect(status).to be(400)
end
end
end
end
end
Generated docs
FORMAT: A1
# Group Invite
## [/v1/invite/send]
+ Parameters
+ first_name (required) - first name
+ last_name (required) - last name
+ email (required)
### send invite [POST]
+ Request failed (application/x-www-form-urlencoded)
+ Headers
Host: example.org
Content-Type: application/x-www-form-urlencoded
Cookie:
+ Response 400 (application/json)
+ Headers
Content-Type: application/json
Content-Length: 153
Cache-Control: no-cache
X-Request-Id: 19651b4a-d2cc-41f1-addd-411d8bf6cff9
X-Runtime: 0.030192
Vary: Origin
+ Body
{
"error": {
"status": 400,
"message": [
"Email is missing",
"First name is missing",
"Last name is missing"
]
}
}
@sureshprasanna70 can you post the rest of your example code so I can run it to track down the issue?
@jakehow I'm sorry. This is the grape api
module Users
class InviteAPI < Grape::API
resources :invite do
params do
requires :invitation, type: Hash do
requires :email, type: String, allow_blank: false, desc: "Invitee Email"
requires :first_name, type: String, allow_blank: false, desc: "Invitee First Name"
requires :last_name, type: String, allow_blank: true, desc: "Invitee Last Name"
end
end
post "send" do
authenticate_user!
email = params[:invitation][:email]
first_name = params[:invitation][:first_name]
last_name = params[:invitation][:last_name]
@invite = Invitation.new(:first_name => first_name,:last_name => last_name,:email => email,:user_id => current_user.id)
if @invite.save
return true
else
invitation_failed_error
end
end
end
helpers do
def invitation_failed_error
throw_errors(422, "Invitation failed")
end
end
end
end
Hope this helps.
@sureshprasanna70 can you put the whole thing up as a repo or a gist? I don't use grape so don't know what the Gemfile should look like, etc. Looks like you have an Invitation model also.
I'm sorry and can't do that. The code is protected and can't be shared publicly. The invitation model contains the fields like first_name,last_name, email and user_id. The gemfile is
source 'https://rubygems.org'
ruby '2.4.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.8'
# Postgres for database
gem 'pg', '0.20.0'
# Grape is a REST-like API micro-framework for Ruby
gem 'grape', '0.19.2'
# Use Rabl templates in Grape
gem 'grape-rabl', '0.4.2'
# Use Devise for authendication and authorization
gem 'devise', '4.2.1'
# For communicating with the Twilio API
gem 'twilio-ruby', '~> 4.11.1'
# Cross domain access
gem 'rack-cors', '0.4.1', :require => 'rack/cors'
# Use Puma as the app server
gem 'puma', '3.8.2'
#Abort requests that are taking too long; an exception is raised.
gem 'rack-timeout', '0.4.2'
group :production, :test do
# SendGrid - To send transactional emails
gem 'sendgrid-ruby', '5.2.0'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Web interface for emails
gem 'mailcatcher'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', '2.0.1'
end
group :development, :test do
# For generating fake data
gem 'faker', '1.7.3'
# Add a comment summarizing the current schema
gem 'annotate', '2.7.2'
#For testing
gem 'rspec-rails', '~> 3.7'
gem 'rspec_api_documentation'
end