rswag: RSwag + Oauth/Doorkeeper authorization not working
Hello, having issues using rswag with autorization, currently using doorkeeper+devise with password flow.
My swagger_helper.rb
require 'rails_helper'
RSpec.configure do |config|
# Specify a root folder where Swagger JSON files are generated
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need
# to ensure that it's configured to serve Swagger from the same folder
config.swagger_root = Rails.root.join('swagger').to_s
# Define one or more Swagger documents and provide global metadata for each one
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
# be generated at the provided relative path under swagger_root
# By default, the operations defined in spec files are added to the first
# document below. You can override this behavior by adding a swagger_doc tag to the
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
config.swagger_docs = {
'v1/swagger.yaml' => {
swagger: '2.0',
info: {
title: 'API V1',
version: 'v1'
},
paths: {},
securityDefinitions: {
oauth: {
type: :oauth2,
flows: 'password',
tokenUrl: 'https://localhost:3000/api/oauth/token',
scopes: [ 'read', 'write' ]
}
}
}
}
# Specify the format of the output Swagger file when running 'rswag:specs:swaggerize'.
# The swagger_docs configuration option has the filename including format in
# the key, this may want to be changed to avoid putting yaml in json files.
# Defaults to json. Accepts ':json' and ':yaml'.
config.swagger_format = :yaml
end
And a dummy spec.
require 'swagger_helper'
describe 'Status API' do
path '/api/status' do
get 'Get Status' do
security [ oauth: [ "read" ] ]
tags 'Status'
consumes 'application/json'
parameter name: :blog, in: :body, schema: {
type: :object,
properties: {
title: { type: :string },
content: { type: :string }
},
required: [ 'title', 'content' ]
}
response '201', 'blog created' do
let(:blog) { { title: 'foo', content: 'bar' } }
run_test!
end
response '422', 'invalid request' do
let(:blog) { { title: 'foo' } }
run_test!
end
end
end
end
Basically when clicking on authorize button on swagge ui i’m stucked with no option to enter user/password and the Authorize button not working.
Looking at the browser console i see a javascript error
One thing i need to mention is that i had to change on the autogenerated swagger_helper.rb the line
openapi: '3.0.1'
with
swagger: '2.0',
Got that one from this #257 . Without that change i was not getting the main Authorize button on the UI.
Anybody use this combination before? Thanks
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (3 by maintainers)
I’m experiencing trouble with this, too, not really sure how to use the
tokenUrlkey in swagger_helper. I’m using Devise, Doorkeeper, OAuth2, password flow:and
spec result:
Any rspec examples that includes oauth flow?
I’m not allowed to share the code that I currently have working (BigCorp would crush my bones)
Instead, let me see if I can whip up an example that I can open source for devise + rswag as I see this issue popped open yesterday too: https://github.com/rswag/rswag/issues/259