Module: Sinatra::RatPackSwagger
- Defined in:
- lib/rat_pack_swagger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_swagger_route(app) ⇒ Object
- #desc(description) ⇒ Object
- #info(&block) ⇒ Object
- #param(opts) ⇒ Object
- #swagger(version) ⇒ Object
Class Method Details
.route_added(verb, path, block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rat_pack_swagger.rb', line 67 def self.route_added(verb, path, block) return if path == "/v2/swagger.json" return unless ["GET", "POST", "PUT", "DELETE"].include?(verb) @@doc ||= {} @@doc["paths"] ||= {} @@doc["paths"][path] = { verb.downcase => { "description" => @@desc, "produces" => [ "application/json" ], "parameters" => @@parameters.map { |p| { "name" => p[:name], "in" => p[:type], "description" => p[:desc], "required" => p[:required] == true, "type" => p[:type] } }, "responses" => { "200" => { "description" => @@desc } } } } @@parameters = [] end |
Instance Method Details
#add_swagger_route(app) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/rat_pack_swagger.rb', line 60 def add_swagger_route(app) app.get "/v2/swagger.json" do content_type "application/json" @@doc.to_json end end |
#desc(description) ⇒ Object
49 50 51 |
# File 'lib/rat_pack_swagger.rb', line 49 def desc(description) @@desc = description end |
#info(&block) ⇒ Object
44 45 46 47 |
# File 'lib/rat_pack_swagger.rb', line 44 def info(&block) @@doc ||= {} @@doc["info"] = SwaggerInfo.new(&block).to_hash end |
#param(opts) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/rat_pack_swagger.rb', line 53 def param(opts) puts "in param" @@parameters ||= [] puts opts @@parameters << opts end |
#swagger(version) ⇒ Object
39 40 41 42 |
# File 'lib/rat_pack_swagger.rb', line 39 def swagger(version) @@doc ||= {} @@doc["swagger"] = version end |