-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inherit from Grape::API::Instance breaks Boolean type #1892
Comments
Feel free to PR a fix to this effect. I would also try to track where this got removed. There's probably a good reason since |
Note: if you are just creating an API you should not be inheriting from In the i.e. on this example you should be doing:
|
Thank you @myxoh for pointing that out. As I can see, the inheritance from However, on my app where I integrate FYI, my app's APIs structure would look similar to this. Rails.application.routes.draw do
mount API::Base, at: "/"
end # app/controllers/api/base.rb
class API::Base < Grape::API
mount API::V1::Base
end # app/controllers/api/v1/base.rb
class API::V1::Base < Grape::API
version 'v1', using: :path
format :json
mount API::V1::Ping
end # app/controllers/api/v1/ping.rb
class API::V1::Ping < Grape::API
resource :system do
params do
optional :hit, type: Boolean
end
get :ping do
"pong"
end
end
end Edited: Add failing spec # spec/requests/api/v1/ping.rb
require 'rails_helper'
require 'rack/test'
describe API::V1 do
include Rack::Test::Methods
def app
API::V1::Ping
end
it 'returns pong' do
get '/v1/system/ping'
expect(last_response.status).to be(200)
end
end |
Interesting as this is a similar setup to the one I've got. Could you please attach the failing spec too? I'll look into this! Thanks ! |
Oops! I should have attached it in the first place. I edited the above comment and added the failing spec. Thanks! |
This is interesting, and sounds like a bug. def app
API::V1::Ping
end With def app
Rails.application
end The spec will go green again. |
The problem stems from the fact that an undocumented breaking change from the upgrade is that |
I think we could use an integration test in Grape. I upgraded ruby-grape/grape-on-rails#8 and it "just worked". This is because I don't have |
OK, I've actually managed to replicate the issue on a spec in the rack integration, and also find a solution ( I believe) |
I think this issue can now be closed, could you confirm @sondnm whether you can now get your spec to work by inheriting from |
It is working great now! Thanks a lot @myxoh. Since the Boolean type for |
Recently I followed the UPGRADING.md guide to upgrade Grape from 1.0.3 to 1.2.4 and an error occurs due to the use of
type: Boolean
inparams
block.This happens only when inheriting from
Grape::API::Instance
. I wrote a small rack app to test and the behaviour is the same.Error:
I could easily change the
Boolean
toVirtus::Attribute::Boolean
to fix this issue on my app but since you already supported this Boolean type feature, I think it should be supported in the next releases too.Thank you.
The text was updated successfully, but these errors were encountered: