rat_pack_swagger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e40eeb8f6f982d76bec3166a5083fb9594077446
4
+ data.tar.gz: e6a5eeed42020edc342c618c8a4b7195be54df8e
5
+ SHA512:
6
+ metadata.gz: 8fc08f942f3e40ede0714b0351a849d558c9be8c5c99647dd058b15c51782a11327ac0f5c5f4e7a7ab552553c4ecbcf6f9dede07e49cdeda48330584792e64ec
7
+ data.tar.gz: 587bae87402c87cf695387f9432f842ba028a08f478b2f40d3c8fc850824679bc1d36c03ab573a1f950b88dcb547ba0ac455cb4ff73bc6be9b6cb3932ec8989e
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2015 Christopher Hildebrand
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Rat Pack Swagger
@@ -0,0 +1,100 @@
1
+ require 'sinatra/base'
2
+
3
+ class SwaggerInfo
4
+ def initialize(&block)
5
+ instance_eval &block
6
+ end
7
+
8
+ def title(app_title)
9
+ @title = app_title
10
+ end
11
+
12
+ def description(app_description)
13
+ @description = app_description
14
+ end
15
+
16
+ def version(app_version)
17
+ @version = app_version
18
+ end
19
+
20
+ def contact(app_contact)
21
+ @contact = app_contact
22
+ end
23
+
24
+ def to_hash
25
+ {
26
+ title: @title,
27
+ description: @description,
28
+ version: @version,
29
+ contact: {
30
+ name: @contact[:name],
31
+ email: @contact[:email]
32
+ }
33
+ }
34
+ end
35
+ end
36
+
37
+ module Sinatra
38
+ module RatPackSwagger
39
+ def swagger(version)
40
+ @@doc ||= {}
41
+ @@doc["swagger"] = version
42
+ end
43
+
44
+ def info(&block)
45
+ @@doc ||= {}
46
+ @@doc["info"] = SwaggerInfo.new(&block).to_hash
47
+ end
48
+
49
+ def desc(description)
50
+ @@desc = description
51
+ end
52
+
53
+ def param(opts)
54
+ puts "in param"
55
+ @@parameters ||= []
56
+ puts opts
57
+ @@parameters << opts
58
+ end
59
+
60
+ def add_swagger_route(app)
61
+ app.get "/v2/swagger.json" do
62
+ content_type "application/json"
63
+ @@doc.to_json
64
+ end
65
+ end
66
+
67
+ def self.route_added(verb, path, block)
68
+ return if path == "/v2/swagger.json"
69
+ return unless ["GET", "POST", "PUT", "DELETE"].include?(verb)
70
+
71
+ @@doc ||= {}
72
+ @@doc["paths"] ||= {}
73
+
74
+ @@doc["paths"][path] = {
75
+ verb.downcase => {
76
+ "description" => @@desc,
77
+ "produces" => [ "application/json" ],
78
+ "parameters" => @@parameters.map { |p|
79
+ {
80
+ "name" => p[:name],
81
+ "in" => p[:type],
82
+ "description" => p[:desc],
83
+ "required" => p[:required] == true,
84
+ "type" => p[:type]
85
+ }
86
+ },
87
+ "responses" => {
88
+ "200" => {
89
+ "description" => @@desc
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ @@parameters = []
96
+ end
97
+ end
98
+
99
+ register RatPackSwagger
100
+ end
@@ -0,0 +1,3 @@
1
+ module RatPackSwagger
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rat_pack_swagger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Hildebrand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ description: Rat Pack Swagger ties into the Sinatra DSL to build out a swagger 2.0
28
+ specification file
29
+ email: ratpackswagger@ckhrysze.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/rat_pack_swagger.rb
37
+ - lib/rat_pack_swagger/version.rb
38
+ homepage: https://github.com/ckhrysze/rat_pack_swagger
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.8
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Extend Sinatra DSL for Swagger
62
+ test_files: []