nedforce-grape-swagger-ui 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/CHANGELOG.md +39 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +78 -0
  7. data/Rakefile +1 -0
  8. data/app/controllers/swagger_controller.rb +8 -0
  9. data/app/views/layouts/swagger.html.erb +96 -0
  10. data/app/views/swagger/index.html +0 -0
  11. data/grape-swagger-ui.gemspec +22 -0
  12. data/lib/generators/swagger/layout/USAGE +8 -0
  13. data/lib/generators/swagger/layout/layout_generator.rb +15 -0
  14. data/lib/generators/swagger/layout/templates/swagger.html.haml +96 -0
  15. data/lib/grape-swagger-ui.rb +19 -0
  16. data/lib/grape-swagger-ui/routes.rb +15 -0
  17. data/lib/grape-swagger-ui/version.rb +7 -0
  18. data/vendor/assets/fonts/DroidSans-Bold.ttf +0 -0
  19. data/vendor/assets/fonts/DroidSans.ttf +0 -0
  20. data/vendor/assets/images/collapse.gif +0 -0
  21. data/vendor/assets/images/expand.gif +0 -0
  22. data/vendor/assets/images/explorer_icons.png +0 -0
  23. data/vendor/assets/images/favicon-16x16.png +0 -0
  24. data/vendor/assets/images/favicon-32x32.png +0 -0
  25. data/vendor/assets/images/favicon.ico +0 -0
  26. data/vendor/assets/images/logo_small.png +0 -0
  27. data/vendor/assets/images/pet_store_api.png +0 -0
  28. data/vendor/assets/images/throbber.gif +0 -0
  29. data/vendor/assets/images/wordnik_api.png +0 -0
  30. data/vendor/assets/javascripts/lang/en.js +56 -0
  31. data/vendor/assets/javascripts/lang/es.js +53 -0
  32. data/vendor/assets/javascripts/lang/fr.js +54 -0
  33. data/vendor/assets/javascripts/lang/geo.js +56 -0
  34. data/vendor/assets/javascripts/lang/it.js +52 -0
  35. data/vendor/assets/javascripts/lang/ja.js +53 -0
  36. data/vendor/assets/javascripts/lang/pl.js +53 -0
  37. data/vendor/assets/javascripts/lang/pt.js +53 -0
  38. data/vendor/assets/javascripts/lang/ru.js +56 -0
  39. data/vendor/assets/javascripts/lang/tr.js +53 -0
  40. data/vendor/assets/javascripts/lang/translator.js +39 -0
  41. data/vendor/assets/javascripts/lang/zh-cn.js +53 -0
  42. data/vendor/assets/javascripts/lib/backbone-min.js +15 -0
  43. data/vendor/assets/javascripts/lib/handlebars-2.0.0.js +28 -0
  44. data/vendor/assets/javascripts/lib/highlight.9.1.0.pack.js +2 -0
  45. data/vendor/assets/javascripts/lib/highlight.9.1.0.pack_extended.js +34 -0
  46. data/vendor/assets/javascripts/lib/jquery-1.8.0.min.js +2 -0
  47. data/vendor/assets/javascripts/lib/jquery.ba-bbq.min.js +18 -0
  48. data/vendor/assets/javascripts/lib/jquery.slideto.min.js +1 -0
  49. data/vendor/assets/javascripts/lib/jquery.wiggle.min.js +8 -0
  50. data/vendor/assets/javascripts/lib/js-yaml.min.js +3 -0
  51. data/vendor/assets/javascripts/lib/jsoneditor.min.js +11 -0
  52. data/vendor/assets/javascripts/lib/lodash.min.js +102 -0
  53. data/vendor/assets/javascripts/lib/marked.js +1272 -0
  54. data/vendor/assets/javascripts/lib/object-assign-pollyfill.js +23 -0
  55. data/vendor/assets/javascripts/lib/swagger-oauth.js +339 -0
  56. data/vendor/assets/javascripts/swagger-ui.js +22278 -0
  57. data/vendor/assets/javascripts/swagger-ui.min.js +9 -0
  58. data/vendor/assets/javascripts/swagger_ui.js +28 -0
  59. data/vendor/assets/stylesheets/print.css +1362 -0
  60. data/vendor/assets/stylesheets/reset.css +125 -0
  61. data/vendor/assets/stylesheets/reset_2.css +125 -0
  62. data/vendor/assets/stylesheets/screen.css +1489 -0
  63. data/vendor/assets/stylesheets/style.css +250 -0
  64. data/vendor/assets/stylesheets/swagger_ui.css +18 -0
  65. data/vendor/assets/stylesheets/swagger_ui_print.css +15 -0
  66. data/vendor/assets/stylesheets/swagger_ui_screen.css +16 -0
  67. data/vendor/assets/stylesheets/typography.css +14 -0
  68. metadata +124 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b19d502ccef2c5deda67804f2e6db8fed86c354e
4
+ data.tar.gz: 3fe45a64973900ad23d4e696fd76c34c9aee69c8
5
+ SHA512:
6
+ metadata.gz: 0e74d2d35a746e15cb0d938dd72b52af49d56e85a399dbc9a77c30acadfae3ea28ff37c0d938f8bda5452df46d7549a9e4701a4ba29662ad80c2a3a96a6a6ff3
7
+ data.tar.gz: 81fb3aefd1645be214f4cffbb954c302f5818450685f986fcdecbbf47c831b7f62ddd2339c750e00a9cc61c5138a95929d4ed913966be72bf298d6d27454aba2
@@ -0,0 +1,22 @@
1
+ .project
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.iml
20
+ atlassian-ide-plugin.xml
21
+ .idea/
22
+ .DS_Store
@@ -0,0 +1,39 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/kendrikat/grape-swagger-ui/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/kendrikat/grape-swagger-ui/compare/v0.0.3...HEAD)
6
+
7
+ **Closed issues:**
8
+
9
+ - Swagger UI needs to be updated [\#9](https://github.com/kendrikat/grape-swagger-ui/issues/9)
10
+
11
+ ## [v0.0.3](https://github.com/kendrikat/grape-swagger-ui/tree/v0.0.3) (2016-08-09)
12
+ [Full Changelog](https://github.com/kendrikat/grape-swagger-ui/compare/v0.0.2...v0.0.3)
13
+
14
+ **Closed issues:**
15
+
16
+ - Routing not working [\#6](https://github.com/kendrikat/grape-swagger-ui/issues/6)
17
+ - haml issue in rails 4 [\#4](https://github.com/kendrikat/grape-swagger-ui/issues/4)
18
+
19
+ **Merged pull requests:**
20
+
21
+ - Support swagger spec 2.0 [\#8](https://github.com/kendrikat/grape-swagger-ui/pull/8) ([dangnm](https://github.com/dangnm))
22
+
23
+ ## [v0.0.2](https://github.com/kendrikat/grape-swagger-ui/tree/v0.0.2) (2015-01-14)
24
+ [Full Changelog](https://github.com/kendrikat/grape-swagger-ui/compare/v0.0.1...v0.0.2)
25
+
26
+ **Closed issues:**
27
+
28
+ - License missing from gemspec [\#2](https://github.com/kendrikat/grape-swagger-ui/issues/2)
29
+
30
+ **Merged pull requests:**
31
+
32
+ - update for swagger-ui 2.0.24 [\#5](https://github.com/kendrikat/grape-swagger-ui/pull/5) ([alexagranov](https://github.com/alexagranov))
33
+ - assets path mistake in swagger-ui.js [\#3](https://github.com/kendrikat/grape-swagger-ui/pull/3) ([dfang](https://github.com/dfang))
34
+ - Optional form fields are not being send with request [\#1](https://github.com/kendrikat/grape-swagger-ui/pull/1) ([camol](https://github.com/camol))
35
+
36
+ ## [v0.0.1](https://github.com/kendrikat/grape-swagger-ui/tree/v0.0.1) (2013-02-25)
37
+
38
+
39
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-swagger-ui.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Klaas Endrikat
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Grape::Swagger::Ui
2
+ ===============
3
+
4
+ [![Code Climate](https://codeclimate.com/github/kendrikat/grape-swagger-ui.png)](https://codeclimate.com/github/kendrikat/grape-swagger-ui)
5
+
6
+ TODO/WIP: Write a gem description
7
+
8
+ Integrates [swagger-ui] with your "grapified" Rails application.
9
+
10
+ ## Dependencies
11
+
12
+ * [grape-swagger]
13
+ > Add swagger compliant documentation to your grape API
14
+
15
+ * [grape]
16
+ > An opinionated micro-framework for creating REST-like APIs in Ruby
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'grape-swagger-ui'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install grape-swagger-ui
31
+
32
+ ## Usage example:
33
+
34
+ class YourAPI < Grape::API
35
+ version 'v1'
36
+ format :json
37
+ ...
38
+ add_swagger_documentation :add_version => true,
39
+ :base_path => '/api'
40
+ end
41
+
42
+ *See https://github.com/ruby-grape/grape-swagger#configure for more configuration settings.*
43
+
44
+ If your api path is "api/v1" just go to
45
+
46
+ http://host:port/api/swagger
47
+
48
+ else
49
+
50
+ *Generate the main layout for customizations*
51
+
52
+ rails generate swagger:layout
53
+
54
+ and change the initializer.
55
+
56
+ Since this is a seperate layout and if you want to use this in your staging environment you need to precompile it.
57
+
58
+ #staging.rb
59
+ config.assets.precompile += %w(swagger_ui.js swagger_ui.css swagger_ui_print.css swagger_ui_screen.css)
60
+
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
69
+
70
+ ## License
71
+ MIT License, full text of license see [here][License]
72
+
73
+ *Free Software, Fuck Yeah!*
74
+
75
+ [License]: https://github.com/kendrikat/grape-swagger-ui/blob/master/LICENSE.txt "LICENSE"
76
+ [grape-swagger]: https://github.com/tim-vandecasteele/grape-swagger
77
+ [grape]: https://github.com/intridea/grape
78
+ [swagger-ui]: https://github.com/wordnik/swagger-ui/
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ class SwaggerController < ApplicationController
2
+
3
+ layout "swagger"
4
+
5
+ def index
6
+ end
7
+
8
+ end
@@ -0,0 +1,96 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html lang="<%= I18n.locale.to_s %>" xml:lang="<%= I18n.locale.to_s %>" xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>Swagger UI</title>
5
+ <%= javascript_include_tag :swagger_ui %>
6
+ <%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Droid+Sans:400,700" %>
7
+ <%= stylesheet_link_tag :swagger_ui_screen, :media => :screen %>
8
+ <%= stylesheet_link_tag :swagger_ui_print, :media => :print %>
9
+ <%= csrf_meta_tags %>
10
+
11
+ <script type="text/javascript">
12
+ $(function () {
13
+ var url = window.location.search.match(/url=([^&]+)/);
14
+ if (url && url.length > 1) {
15
+ url = decodeURIComponent(url[1]);
16
+ } else {
17
+ url = "http://<%= request.host%>:<%=request.port%>/api/v1/swagger_doc";
18
+ }
19
+
20
+ hljs.configure({
21
+ highlightSizeThreshold: 5000
22
+ });
23
+
24
+ // Pre load translate...
25
+ if(window.SwaggerTranslator) {
26
+ window.SwaggerTranslator.translate();
27
+ }
28
+ window.swaggerUi = new SwaggerUi({
29
+ url: url,
30
+ dom_id: "swagger-ui-container",
31
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
32
+ onComplete: function(swaggerApi, swaggerUi){
33
+ if(typeof initOAuth == "function") {
34
+ initOAuth({
35
+ clientId: "your-client-id",
36
+ clientSecret: "your-client-secret-if-required",
37
+ realm: "your-realms",
38
+ appName: "your-app-name",
39
+ scopeSeparator: ",",
40
+ additionalQueryStringParams: {}
41
+ });
42
+ }
43
+
44
+ if(window.SwaggerTranslator) {
45
+ window.SwaggerTranslator.translate();
46
+ }
47
+ },
48
+ onFailure: function(data) {
49
+ log("Unable to Load SwaggerUI");
50
+ },
51
+ docExpansion: "none",
52
+ jsonEditor: false,
53
+ defaultModelRendering: 'schema',
54
+ showRequestHeaders: false
55
+ });
56
+
57
+ $('#input_apiKey').change(function() {
58
+ var key = $('#input_apiKey')[0].value;
59
+ if(key && key.trim() != "") {
60
+ swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"));
61
+ }
62
+ })
63
+
64
+ window.swaggerUi.load();
65
+
66
+ function log() {
67
+ if ('console' in window) {
68
+ console.log.apply(console, arguments);
69
+ }
70
+ }
71
+ });
72
+ </script>
73
+
74
+ </head>
75
+
76
+
77
+ <body class="swagger-section">
78
+ <div id='header'>
79
+ <div class="swagger-ui-wrap">
80
+ <a id="logo" href="http://swagger.io"><span class="logo__title">swagger</span></a>
81
+ <form id='api_selector'>
82
+ <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
83
+ <div class="input">
84
+ <input id="input_apiKey" name="apiKey" placeholder="api_key" type="text"></input>
85
+ </div>
86
+ <div id='auth_container'></div>
87
+ <div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
88
+ </form>
89
+ </div>
90
+ </div>
91
+
92
+ <div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
93
+ <div id="swagger-ui-container" class="swagger-ui-wrap"></div>
94
+ </body>
95
+
96
+ </html>
File without changes
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape-swagger-ui/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "nedforce-grape-swagger-ui"
8
+ gem.version = Grape::Swagger::Ui::VERSION
9
+ gem.authors = ["Klaas Endrikat"]
10
+ gem.email = ["klaas.endrikat@googlemail.com"]
11
+ gem.description = %q{swagger ui js integration for grape and grape-swagger}
12
+ gem.summary = %q{swagger ui js integration for grape and grape-swagger}
13
+ gem.license = 'MIT'
14
+ gem.homepage = "https://github.com/nedforce/grape-swagger-ui"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency "railties", ">= 3.1"
22
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a dedicated layout for the swagger-ui
3
+
4
+ Example:
5
+ rails generate swagger:layout
6
+
7
+ This will create:
8
+ app/views/layouts/swagger.html.haml
@@ -0,0 +1,15 @@
1
+ module Swagger
2
+ module Generators
3
+ class LayoutGenerator < ::Rails::Generators::Base
4
+ desc 'Setup a dedicated layout for the swagger-ui'
5
+
6
+ def self.source_root
7
+ File.expand_path('../templates', __FILE__)
8
+ end
9
+
10
+ def create_swagger_layout
11
+ template 'swagger.html.haml', File.join('app', 'views', 'layouts', 'swagger.html.haml')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,96 @@
1
+ !!!
2
+ %html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => I18n.locale.to_s, "xml:lang" => I18n.locale.to_s }
3
+ %head
4
+ %title Swagger UI
5
+
6
+ = javascript_include_tag :swagger_ui
7
+ = stylesheet_link_tag :swagger_ui_screen, :media => :screen
8
+ = stylesheet_link_tag :swagger_ui_print, :media => :print
9
+ = csrf_meta_tags
10
+
11
+ :css
12
+ .swagger-ui-wrap {
13
+ max-width: 80%;
14
+ min-width: 960px;
15
+ margin-left: auto;
16
+ margin-right: auto;
17
+ }
18
+
19
+ :javascript
20
+ $(function () {
21
+ var url = window.location.search.match(/url=([^&]+)/);
22
+ if (url && url.length > 1) {
23
+ url = decodeURIComponent(url[1]);
24
+ } else {
25
+ url = "http://#{request.host}:#{request.port}/api/v1/swagger_doc";
26
+ }
27
+
28
+ hljs.configure({
29
+ highlightSizeThreshold: 5000
30
+ });
31
+
32
+ // Pre load translate...
33
+ if(window.SwaggerTranslator) {
34
+ window.SwaggerTranslator.translate();
35
+ }
36
+ window.swaggerUi = new SwaggerUi({
37
+ url: url,
38
+ dom_id: "swagger-ui-container",
39
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
40
+ onComplete: function(swaggerApi, swaggerUi){
41
+ if(typeof initOAuth == "function") {
42
+ initOAuth({
43
+ clientId: "your-client-id",
44
+ clientSecret: "your-client-secret-if-required",
45
+ realm: "your-realms",
46
+ appName: "your-app-name",
47
+ scopeSeparator: ",",
48
+ additionalQueryStringParams: {}
49
+ });
50
+ }
51
+
52
+ if(window.SwaggerTranslator) {
53
+ window.SwaggerTranslator.translate();
54
+ }
55
+ },
56
+ onFailure: function(data) {
57
+ log("Unable to Load SwaggerUI");
58
+ },
59
+ docExpansion: "none",
60
+ jsonEditor: false,
61
+ defaultModelRendering: 'schema',
62
+ showRequestHeaders: false
63
+ });
64
+
65
+ $('#input_apiKey').change(function() {
66
+ var key = $('#input_apiKey')[0].value;
67
+ if(key && key.trim() != "") {
68
+ swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("api_key", key, "query"));
69
+ }
70
+ })
71
+
72
+ window.swaggerUi.load();
73
+
74
+ function log() {
75
+ if ('console' in window) {
76
+ console.log.apply(console, arguments);
77
+ }
78
+ }
79
+ });
80
+
81
+ %body.swagger-section
82
+ #header
83
+ .swagger-ui-wrap
84
+ %a#logo{:href => "http://swagger.io"}
85
+ %span.logo__title swagger
86
+ %form#api_selector
87
+ .input
88
+ %input#input_baseUrl{:name => "baseUrl", :placeholder => "http://example.com/api", :type => "text"}/
89
+ .input
90
+ %input#input_apiKey{:name => "apiKey", :placeholder => "api_key", :type => "text"}
91
+ #auth_container
92
+ .input
93
+ %a#explore.header__btn{"data-sw-translate" => "", :href => "#"} Explore
94
+ #message-bar.swagger-ui-wrap{"data-sw-translate" => ""} &nbsp;
95
+ #swagger-ui-container.swagger-ui-wrap
96
+
@@ -0,0 +1,19 @@
1
+ require "grape-swagger-ui/version"
2
+ require "grape-swagger-ui/routes"
3
+
4
+ module Grape
5
+ module Swagger
6
+ module Ui
7
+ class Engine < ::Rails::Engine
8
+ config.draw_swagger_routes = true
9
+
10
+ initializer 'grape-swagger-ui.draw_routes' do |app|
11
+ if config.draw_swagger_routes && (!$rails_rake_task || (ARGV[0] =~ /routes\Z/))
12
+ app.routes.append{ Grape::Swagger::Ui::Routes.draw(self) }
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end