ddy_swagger_docs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +3 -0
  7. data/CODE_OF_CONDUCT.md +13 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +195 -0
  11. data/Rakefile +1 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +7 -0
  14. data/lib/swagger_docs.rb +10 -0
  15. data/lib/swagger_docs/version.rb +3 -0
  16. data/swagger_docs.gemspec +32 -0
  17. data/vendor/assets/index.html +98 -0
  18. data/vendor/assets/javascripts/initializer.js +54 -0
  19. data/vendor/assets/javascripts/lib/backbone-min.js +15 -0
  20. data/vendor/assets/javascripts/lib/handlebars-2.0.0.js +28 -0
  21. data/vendor/assets/javascripts/lib/highlight.7.3.pack.js +1 -0
  22. data/vendor/assets/javascripts/lib/jquery-1.8.0.min.js +2 -0
  23. data/vendor/assets/javascripts/lib/jquery.ba-bbq.min.js +18 -0
  24. data/vendor/assets/javascripts/lib/jquery.slideto.min.js +1 -0
  25. data/vendor/assets/javascripts/lib/jquery.wiggle.min.js +8 -0
  26. data/vendor/assets/javascripts/lib/marked.js +1272 -0
  27. data/vendor/assets/javascripts/lib/shred.bundle.js +2765 -0
  28. data/vendor/assets/javascripts/lib/shred/content.js +193 -0
  29. data/vendor/assets/javascripts/lib/swagger-client.js +3297 -0
  30. data/vendor/assets/javascripts/lib/swagger-oauth.js +279 -0
  31. data/vendor/assets/javascripts/lib/underscore-min.js +5 -0
  32. data/vendor/assets/javascripts/swagger-ui.js +2240 -0
  33. data/vendor/assets/javascripts/swagger-ui.min.js +2 -0
  34. data/vendor/assets/javascripts/swagger_docs.js +14 -0
  35. data/vendor/assets/o2c.html +20 -0
  36. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-700.eot +0 -0
  37. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-700.svg +411 -0
  38. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-700.ttf +0 -0
  39. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-700.woff +0 -0
  40. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-700.woff2 +0 -0
  41. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-regular.eot +0 -0
  42. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-regular.svg +403 -0
  43. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-regular.ttf +0 -0
  44. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-regular.woff +0 -0
  45. data/vendor/assets/stylesheets/fonts/droid-sans-v6-latin-regular.woff2 +0 -0
  46. data/vendor/assets/stylesheets/images/explorer_icons.png +0 -0
  47. data/vendor/assets/stylesheets/images/logo_small.png +0 -0
  48. data/vendor/assets/stylesheets/images/pet_store_api.png +0 -0
  49. data/vendor/assets/stylesheets/images/throbber.gif +0 -0
  50. data/vendor/assets/stylesheets/images/wordnik_api.png +0 -0
  51. data/vendor/assets/stylesheets/reset.css +125 -0
  52. data/vendor/assets/stylesheets/screen.css +1204 -0
  53. data/vendor/assets/stylesheets/swagger_docs.css +6 -0
  54. data/vendor/assets/stylesheets/typography.css +26 -0
  55. metadata +168 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5d8b03caa1ac5c2e318cb3f61ffee4cd51ff8f3
4
+ data.tar.gz: 52adf92b2d46187e054fc721e4d4858fd5f23015
5
+ SHA512:
6
+ metadata.gz: 0584f7d0ab2cb934d912d7cf736240c968e069c4e436edb4b7a14e7f49fafc5cb9587e1e5e614a862c6b2176612b2107df69868ffc417f9b2ced7f9709b1c66c
7
+ data.tar.gz: c9fea2b243ce052b45bd38b09d1179069cbc34d34386bf5da8e37b3cce4171aa8563990d2e35c73c72439a4ab156a3abe3cd4e8f5757561e06c905c4a17b2664
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.log
11
+ spec/dummy/tmp
12
+ spec/dummy/log
13
+ spec/dummy/vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ swagger_docs
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swagger_docs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jan van der Pas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # Swagger Docs
2
+
3
+ Swagger Docs, is a gem which includes the [Swagger::Docs](https://github.com/richhollis/swagger-docs) gem and the assets for the SwaggerUI.
4
+
5
+ ## Goal of Swagger Docs
6
+
7
+ To easily setup API documentation with Swagger and the SwaggerUI.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ # Use this to fetch the gem from Gitlab
15
+ gem 'swagger_docs', git: 'git@lab.digidentity.eu:jvanderpas/swagger_docs.git'
16
+
17
+ # Use this to fetch the gem from RubyGems.org
18
+ gem 'ddy_swagger_docs', require: 'swagger_docs'
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ 1. Add the stylesheet and javascript manifests to your assets:
24
+
25
+ ```
26
+ # app/assets/javascripts/application.js
27
+ //= require swagger_docs
28
+ ```
29
+
30
+ ```
31
+ # app/assets/stylesheets/application.css
32
+ *= require swagger_docs
33
+ ```
34
+
35
+ 2. Add the `Swagger::Docs` configuration to your initializers:
36
+
37
+ ```ruby
38
+ # config/initializers/swagger_docs.rb
39
+ class Swagger::Docs::Config
40
+ def self.transform_path(path, api_version)
41
+ # Make a distinction between the APIs and API documentation paths.
42
+ "api/#{path}"
43
+ end
44
+ end
45
+
46
+ Swagger::Docs::Config.register_apis(
47
+ {
48
+ '1.0' => {
49
+ api_extension_type: :json,
50
+ controller_base_path: '',
51
+ api_file_path: 'public/api',
52
+ base_path: 'http://localhost:3000',
53
+ clean_directory: true,
54
+ camelize_model_properties: false,
55
+ attributes: {
56
+ info: {
57
+ title: 'Dummy API',
58
+ description: 'JSON-based API accessible only for authorized users. Resource objects can be retrieved and written via this API. Keep in mind that any tries you do via this API will be done via the currently logged in profile.'
59
+ }
60
+ }
61
+ }
62
+ }
63
+ )
64
+ ```
65
+
66
+ 3. Create a page in which you want to display the SwaggerUI, and add:
67
+
68
+ ```html
69
+ <div class="swagger-section">
70
+ <div class="swagger-ui-wrap" id="message-bar"></div>
71
+ <div class="swagger-ui-wrap" id="swagger-ui-container"></div>
72
+ </div>
73
+ ```
74
+
75
+ 4. Visit the page and verify that the SwaggerUI is displayed.
76
+
77
+
78
+
79
+ ## Usage
80
+
81
+ Write the API documentation with the `Swagger::Docs` DSL in your controllers:
82
+
83
+ ```ruby
84
+ module Api
85
+ class PostsController < BaseController
86
+
87
+ swagger_controller :users, 'Posts'
88
+
89
+ swagger_model :Post do
90
+ description 'Post'
91
+ property :id, :string, :required, '#id', example: '1430311887'
92
+ property :title, :string, :required, '#title', example: 'My morning breakfast'
93
+ property :body, :text, :optional, '#body', example: 'Every morning I make myself a cup of coffee, some orange juice and a bowl of muesli.'
94
+ end
95
+
96
+ swagger_api :index do
97
+ summary 'Lists Posts'
98
+ response :ok, nil
99
+ end
100
+
101
+ def index
102
+ @posts = Post.all
103
+
104
+ render json: @posts
105
+ end
106
+
107
+ swagger_api :show do
108
+ summary 'Find a Post'
109
+ param :path, :id, :string, :required, 'Post#id'
110
+ response :ok, nil, :Post
111
+ response :not_found
112
+ end
113
+
114
+ def show
115
+ @post = Post.find(params[:id])
116
+
117
+ render json: @post
118
+ end
119
+
120
+ swagger_api :create do
121
+ summary 'Create a Post'
122
+ param :body, :post, :post_params, :required
123
+ response :created, nil, :Post
124
+ response :unprocessable_entity, 'Unprocessable entity. Contains a JSON array of error messages.'
125
+ end
126
+
127
+ def create
128
+ @post = Post.create(post_params)
129
+
130
+ if @post.persisted?
131
+ render json: @post, status: :created
132
+ else
133
+ render json: { errors: @post.errors.messages }, status: :unprocessable_entity
134
+ end
135
+ end
136
+
137
+ swagger_api :update do
138
+ summary 'Update a Post'
139
+ param :path, :id, :string, :required, 'Post#id'
140
+ param :body, :post, :post_params, :required
141
+ response :accepted, nil, :Post
142
+ response :unprocessable_entity, 'Unprocessable entity. Contains a JSON array of error messages.'
143
+ response :not_found
144
+ end
145
+
146
+ def update
147
+ @post = Post.find(params[:id])
148
+
149
+ if @post.update_attributes(post_params)
150
+ render json: @post, status: :accepted
151
+ else
152
+ render json: { errors: @post.errors.messages }, status: :unprocessable_entity
153
+ end
154
+ end
155
+
156
+ swagger_api :destroy do
157
+ summary 'Delete a Post'
158
+ param :path, :id, :string, :required, 'Post#id'
159
+ response :no_content, 'No content. Successful deleted the resource.'
160
+ response :unprocessable_entity, 'Unprocessable entity. Contains a JSON array of error messages.'
161
+ response :not_found
162
+ end
163
+
164
+ def destroy
165
+ @post = Post.find(params[:id])
166
+
167
+ if @post.destroy
168
+ head :no_content
169
+ else
170
+ render json: { errors: @post.errors.messages }, status: :unprocessable_entity
171
+ end
172
+ end
173
+
174
+ private
175
+
176
+ swagger_model :post_params do
177
+ description 'Post params'
178
+ property :title, :string, :required, '#title', example: 'My lunch'
179
+ property :body, :string, :optional, '#body', example: 'During the lunch I make myself two sandwiches with peanut butter and jam.'
180
+ end
181
+
182
+ def post_params
183
+ params.require(:post).permit(:title, :body)
184
+ end
185
+
186
+ end
187
+ end
188
+ ```
189
+
190
+ Generate the Swagger API documentation using a `Rake` task:
191
+
192
+ `$ rake swagger:docs`
193
+
194
+
195
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "swagger_docs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require 'swagger/docs'
2
+
3
+ require 'swagger_docs/version'
4
+
5
+ module SwaggerDocs
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module SwaggerDocs
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'swagger_docs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ddy_swagger_docs'
8
+ spec.version = SwaggerDocs::VERSION
9
+ spec.authors = ['Jan van der Pas']
10
+ spec.email = ['jvanderpas@digidentity.eu']
11
+
12
+ spec.summary = %q{Swagger Docs, a gem which contains the SwaggerUI assets}
13
+ spec.description = %q{Swagger Docs, a gem which contains the SwaggerUI assets}
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.9'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rails'
29
+
30
+ spec.add_runtime_dependency 'railties'
31
+ spec.add_runtime_dependency 'swagger-docs'
32
+ end
@@ -0,0 +1,98 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Swagger UI</title>
5
+ <link href='stylesheets/typography.css' media='screen' rel='stylesheet' type='text/css'/>
6
+ <link href='stylesheets/reset.css' media='screen' rel='stylesheet' type='text/css'/>
7
+ <link href='stylesheets/screen.css' media='screen' rel='stylesheet' type='text/css'/>
8
+ <link href='stylesheets/reset.css' media='print' rel='stylesheet' type='text/css'/>
9
+ <link href='stylesheets/screen.css' media='print' rel='stylesheet' type='text/css'/>
10
+ <script type="text/javascript" src="javascripts/lib/shred.bundle.js"></script>
11
+ <script src='javascripts/lib/jquery-1.8.0.min.js' type='text/javascript'></script>
12
+ <script src='javascripts/lib/jquery.slideto.min.js' type='text/javascript'></script>
13
+ <script src='javascripts/lib/jquery.wiggle.min.js' type='text/javascript'></script>
14
+ <script src='javascripts/lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
15
+ <script src='javascripts/lib/handlebars-2.0.0.js' type='text/javascript'></script>
16
+ <script src='javascripts/lib/underscore-min.js' type='text/javascript'></script>
17
+ <script src='javascripts/lib/backbone-min.js' type='text/javascript'></script>
18
+ <script src='javascripts/lib/swagger-client.js' type='text/javascript'></script>
19
+ <script src='javascripts/swagger-ui.js' type='text/javascript'></script>
20
+ <script src='javascripts/lib/highlight.7.3.pack.js' type='text/javascript'></script>
21
+ <script src='javascripts/lib/marked.js' type='text/javascript'></script>
22
+
23
+ <!-- enabling this will enable oauth2 implicit scope support -->
24
+ <script src='javascripts/lib/swagger-oauth.js' type='text/javascript'></script>
25
+ <script type="text/javascript">
26
+ $(function () {
27
+ var url = window.location.search.match(/url=([^&]+)/);
28
+ if (url && url.length > 1) {
29
+ url = decodeURIComponent(url[1]);
30
+ } else {
31
+ url = "http://petstore.swagger.io/v2/swagger.json";
32
+ }
33
+ window.swaggerUi = new SwaggerUi({
34
+ url: url,
35
+ dom_id: "swagger-ui-container",
36
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
37
+ onComplete: function(swaggerApi, swaggerUi){
38
+ if(typeof initOAuth == "function") {
39
+ /*
40
+ initOAuth({
41
+ clientId: "your-client-id",
42
+ realm: "your-realms",
43
+ appName: "your-app-name"
44
+ });
45
+ */
46
+ }
47
+ $('pre code').each(function(i, e) {
48
+ hljs.highlightBlock(e)
49
+ });
50
+ },
51
+ onFailure: function(data) {
52
+ log("Unable to Load SwaggerUI");
53
+ },
54
+ docExpansion: "none",
55
+ sorter : "alpha"
56
+ });
57
+
58
+ function addApiKeyAuthorization() {
59
+ var key = $('#input_apiKey')[0].value;
60
+ log("key: " + key);
61
+ if(key && key.trim() != "") {
62
+ log("added key " + key);
63
+ window.authorizations.add("api_key", new ApiKeyAuthorization("api_key", key, "query"));
64
+ }
65
+ }
66
+
67
+ $('#input_apiKey').change(function() {
68
+ addApiKeyAuthorization();
69
+ });
70
+
71
+ // if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
72
+ /*
73
+ var apiKey = "myApiKeyXXXX123456789";
74
+ $('#input_apiKey').val(apiKey);
75
+ addApiKeyAuthorization();
76
+ */
77
+
78
+ window.swaggerUi.load();
79
+ });
80
+ </script>
81
+ </head>
82
+
83
+ <body class="swagger-section">
84
+ <div id='header'>
85
+ <div class="swagger-ui-wrap">
86
+ <a id="logo" href="http://swagger.io">swagger</a>
87
+ <form id='api_selector'>
88
+ <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
89
+ <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
90
+ <div class='input'><a id="explore" href="#">Explore</a></div>
91
+ </form>
92
+ </div>
93
+ </div>
94
+
95
+ <div id="message-bar" class="swagger-ui-wrap">&nbsp;</div>
96
+ <div id="swagger-ui-container" class="swagger-ui-wrap"></div>
97
+ </body>
98
+ </html>