zuzannast / swagger_ui_engine Goto Github PK
View Code? Open in Web Editor NEWInclude swagger-ui as rails engine and document your API with simple JSON or YAML files.
Home Page: https://zuzannast.github.io/swagger_ui_engine/
License: MIT License
Include swagger-ui as rails engine and document your API with simple JSON or YAML files.
Home Page: https://zuzannast.github.io/swagger_ui_engine/
License: MIT License
Like title, Sprocket 4 has deprecated the starts_with regex function. Please advice, thank you.
def valid_asset_uri?(str)
str.start_with?("file://".freeze) && parse_asset_uri(str) ? true : false
rescue URI::InvalidURIError
false
end
I would like to be able to setup more SwaggerUI parameters (e.g. docExpansion
) and use them instead of the defaults.
I get this error when I start my server. My applicaiton is api-only application so it doesn't include any assets files and its middlewares.
/home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `assets' for #<Rails::Application::Configuration:0x00000004095f20> (NoMethodError)
Did you mean? asset_host
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/swagger_ui_engine-1.0.2/lib/swagger_ui_engine/engine.rb:6:in `block in <class:Engine>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:396:in `instance_exec'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:396:in `block in make_lambda'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:169:in `block (2 levels) in halting'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:547:in `block (2 levels) in default_terminator'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:546:in `catch'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:546:in `block in default_terminator'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:170:in `block in halting'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:454:in `block in call'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:454:in `each'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:454:in `call'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:750:in `_run_prepare_callbacks'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/callbacks.rb:90:in `run_callbacks'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/reloader.rb:87:in `prepare!'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `run'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `call'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
from /home/dhurba/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/application.rb:352:in `initialize!'
from /home/dhurba/apps/ror/taskbazaar/config/environment.rb:5:in `<top (required)>'
from /home/dhurba/apps/ror/taskbazaar/config.ru:3:in `require_relative'
from /home/dhurba/apps/ror/taskbazaar/config.ru:3:in `block in <main>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
from /home/dhurba/apps/ror/taskbazaar/config.ru:in `new'
from /home/dhurba/apps/ror/taskbazaar/config.ru:in `<main>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/server.rb:59:in `app'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/server.rb:124:in `log_to_stdout'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/server.rb:77:in `start'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from /home/dhurba/apps/ror/taskbazaar/bin/rails:9:in `require'
from /home/dhurba/apps/ror/taskbazaar/bin/rails:9:in `<top (required)>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /home/dhurba/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/dhurba/apps/ror/taskbazaar/bin/spring:15:in `require'
from /home/dhurba/apps/ror/taskbazaar/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Hello @zuzannast!
I'm using your gem to an internal project and I'm having the following issue: When I "try out" a post to an endpoint is not taking into account the information I added to the field.
Please find below more data to reproduce the issue:
/employers/login:
post:
operationId: "loginEmployerAccount"
parameters:
- in: "body"
name: user
description: "logs in an employer user "
schema:
type: "object"
properties:
email:
type: "string"
password:
type: "string"
device_id:
type: "string"
responses:
200:
description: "successful operation"
headers:
APIKeyHeader:
type: string
It would be cool to support locking down access to the swagger doc using basic auth. This functionality is supported in other swagger ui gems as well as projects like resque web.
Here is an example implementation from another swagger gem.
Then we can configure the credentials inside an initializer as well.
# from https://github.com/batdevis/swagger_engine#basic-http-auth
SwaggerEngine.configure do |config|
config.admin_username = ENV['ADMIN_USERNAME']
config.admin_password = ENV['ADMIN_PASSWORD']
end
Thanks for putting this together!
Please help to figure out how to change path to documentation so that I won't need to place it under 'public/swagger_docs/v1/swagger.json'?
I'm used to use https://github.com/brennovich/ruby-swagger and with Rails update 'swagger_engine' is not working anymore (of course).
I could write task for copying .json file everytime it's generated, but that's not nice.
Hello. I saw that Basic Auth was added to the gem! Awesome!
I was playing around and was running into some issues getting the basic auth functionality to work in dev. Maybe we can add the basic auth to the example rails app as a proof of functionality.
When I go into the Rails console, I can see:
irb(main):003:0> SwaggerUiEngine.configuration
=> #<SwaggerUiEngine::Configuration:0x005569cd6ea668 @admin_username="admin", @admin_password="admin", @swagger_url={:v1=>"/api/v1/swagger.yaml"}, @doc_expansion="list", @model_rendering="schema", @request_headers=true, @json_editor=true>
I can see that the admin_username
and admin_password
are set, but no prompt in the bowser. Anything I am missing?
Thanks again!!
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: text/html' -d 'email=fd&password=fdd' 'http://localhost:3000/auth/login'
overrite the Accept header to: 'Accept': 'application/vnd.myapp.v1+json'
I use Rails 6.0.3.4 and it cannot resolved
swagger_ui_engine (~> 1.1, >= 1.1.3) was resolved to 1.1.3, which depends on
rails (< 6, >= 4.2)
Please update.
In the SwaggerUiEngine module class is defined as the following:
class SwaggerDocsController < ApplicationController
So It is inheriting from ApplicationController of my project Instead of from module.
I tried to change it like
class SwaggerDocsController < SwaggerUiEngine::ApplicationController
then it is working fine.
I want to change the UI and make look the same as the one on the swagger editor, it's much cleaner. Any help?
I've tried to implement this in api-only application and got following errors. It looks like ActionView::Layout is not configured properly in apionly application
Started GET "/api_docs/" for 127.0.0.1 at 2017-08-06 17:46:54 +0545
ActionController::RoutingError (undefined method `layout' for SwaggerUiEngine::SwaggerDocsController:Class):
swagger_ui_engine (1.1.0) app/controllers/swagger_ui_engine/swagger_docs_controller.rb:7:in `<class:SwaggerDocsController>'
swagger_ui_engine (1.1.0) app/controllers/swagger_ui_engine/swagger_docs_controller.rb:2:in `<module:SwaggerUiEngine>'
swagger_ui_engine (1.1.0) app/controllers/swagger_ui_engine/swagger_docs_controller.rb:1:in `<top (required)>'
activesupport (5.0.5) lib/active_support/dependencies.rb:477:in `load'
activesupport (5.0.5) lib/active_support/dependencies.rb:477:in `block in load_file'
activesupport (5.0.5) lib/active_support/dependencies.rb:662:in `new_constants_in'
activesupport (5.0.5) lib/active_support/dependencies.rb:476:in `load_file'
activesupport (5.0.5) lib/active_support/dependencies.rb:375:in `block in require_or_load'
activesupport (5.0.5) lib/active_support/dependencies.rb:37:in `block in load_interlock'
activesupport (5.0.5) lib/active_support/dependencies/interlock.rb:12:in `block in loading'
activesupport (5.0.5) lib/active_support/concurrency/share_lock.rb:150:in `exclusive'
activesupport (5.0.5) lib/active_support/dependencies/interlock.rb:11:in `loading'
activesupport (5.0.5) lib/active_support/dependencies.rb:37:in `load_interlock'
activesupport (5.0.5) lib/active_support/dependencies.rb:358:in `require_or_load'
activesupport (5.0.5) lib/active_support/dependencies.rb:511:in `load_missing_constant'
activesupport (5.0.5) lib/active_support/dependencies.rb:203:in `const_missing'
activesupport (5.0.5) lib/active_support/inflector/methods.rb:270:in `const_get'
activesupport (5.0.5) lib/active_support/inflector/methods.rb:270:in `block in constantize'
activesupport (5.0.5) lib/active_support/inflector/methods.rb:266:in `each'
activesupport (5.0.5) lib/active_support/inflector/methods.rb:266:in `inject'
activesupport (5.0.5) lib/active_support/inflector/methods.rb:266:in `constantize'
activesupport (5.0.5) lib/active_support/dependencies.rb:583:in `get'
activesupport (5.0.5) lib/active_support/dependencies.rb:614:in `constantize'
actionpack (5.0.5) lib/action_dispatch/http/request.rb:81:in `controller_class'
actionpack (5.0.5) lib/action_dispatch/routing/route_set.rb:44:in `controller'
actionpack (5.0.5) lib/action_dispatch/routing/route_set.rb:30:in `serve'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.5) lib/action_dispatch/routing/route_set.rb:727:in `call'
railties (5.0.5) lib/rails/engine.rb:522:in `call'
railties (5.0.5) lib/rails/railtie.rb:193:in `public_send'
railties (5.0.5) lib/rails/railtie.rb:193:in `method_missing'
actionpack (5.0.5) lib/action_dispatch/routing/mapper.rb:17:in `block in <class:Constraints>'
actionpack (5.0.5) lib/action_dispatch/routing/mapper.rb:46:in `serve'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.5) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.5) lib/action_dispatch/routing/route_set.rb:727:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.3) lib/rack/etag.rb:25:in `call'
rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.3) lib/rack/head.rb:12:in `call'
activerecord (5.0.5) lib/active_record/migration.rb:553:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.5) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.5) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.5) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.5) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.5) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.5) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.5) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.5) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.5) lib/rails/rack/logger.rb:24:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.3) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.5) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.0.1) lib/rack/cors.rb:93:in `call'
railties (5.0.5) lib/rails/engine.rb:522:in `call'
puma (3.9.1) lib/puma/configuration.rb:224:in `call'
puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
puma (3.9.1) lib/puma/server.rb:435:in `process_client'
puma (3.9.1) lib/puma/server.rb:299:in `block in run'
puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Why are tags not working?
Curious to know if anybody has methods to change swagger host according to the environment or requesting domain
When I open swagger, I get an error that I can't see the image.
Started GET "/api_docs/null?url=http://192.168.33.10:3000/api/swagger.yaml" for 192.168.33.1 at 2020-06-12 07:43:54 +0000
ActionController::RoutingError (No route matches [GET] "/api_docs/null"):
actionpack (5.2.4.3) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.4.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.4.3) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.4.3) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.4.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.4.3) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.4.3) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.4.3) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.4.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.4.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.2) lib/rack/method_override.rb:24:in `call'
rack (2.2.2) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.4.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.4.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.4.3) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.2.2) lib/rack/sendfile.rb:110:in `call'
railties (5.2.4.3) lib/rails/engine.rb:524:in `call'
puma (3.12.6) lib/puma/configuration.rb:227:in `call'
puma (3.12.6) lib/puma/server.rb:706:in `handle_request'
puma (3.12.6) lib/puma/server.rb:476:in `process_client'
puma (3.12.6) lib/puma/server.rb:334:in `block in run'
puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'
rails 5.1.5
api-mode
installed gem as per instructions, this error is displayed on visiting /api_docs
module SwaggerUiEngine
class SwaggerDocsController < ApplicationController
include SwaggerUiEngine::ConfigParser
include SwaggerUiEngine::OauthConfigParser
add_template_helper SwaggerUiEngine::TranslationHelper
layout 'swagger_ui_engine/layouts/swagger', except: %w(oauth2)
before_action :set_configs, :set_oauth_configs
def oauth2```
Hello there!
I just wanted to know if you have in the roadmap to include support for v3.
Thanks!
I believe this is a simple fix of replacing add_template_helper
with helper
in the controller to make this work with rails 6.1
There is an error in finding throbber.gif
file which results in 404 errors.
First of all thank you @zuzannast for this excellent plugin, very needed and easy to setup.
There is a small issue when validator_enabled
is set false, it looks like it's still trying to do a validation but with an url set to null?<path_to_yaml_file>
Additionally a config option to customize the URL of validationUrl
would be nice, as well as having the latest version (3.6) of SwaggerUI.
I'll try to send a PR the following week.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.