sinatra-swagger 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDc0OTRhNWUyNTY5YWI2MjAxODBhMmRhODk4ODBlNmExMGMxOTRiYg==
4
+ NTI2YmQ2ZGUxOTJmNjk0YmZlNTRhNTNlYmE4MjM1YTAzYjk2ZWZkNw==
5
5
  data.tar.gz: !binary |-
6
- YWNlNDJiZWY2YTc3ZDg1MDFmNTYyOWVkMjI1NjMxNDUzYjFhMjYwYw==
6
+ YzMxYzIzOTRmNTcyZWIyYTM2NTIxMGRkZjc3Yzk3Njk1MzQzODU0MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTU0NWQ4YmExNDZhZmUwNDM2Mjg5YWNkNTc0YzQxNzQ3ZDIxY2RmZWRkYzBi
10
- MzNhYjI1MmMzZmE3YWU0ZTU0MDhjMDRiMzk4Njg0Y2M0MmY3ZDAwNGRmZjc3
11
- ZWZkODJlMjc0MWQ2MTc3NTM3Zjc0OThjYzNmOWE5NWIyZjQ0OTk=
9
+ ODdhYTJlYzVjZDUzOWU5MTVhOTNjNTczYzdhMmY2M2VjNDliZjM4YzQ0Y2Ri
10
+ YzgyMTM1ZjU4NmE4ZDA4MzU3MzZhNjQ5Y2ExMjc5NWYwYjMzMGI4MzdhNDU5
11
+ Mjg2MTk1MDliZjFiNjJlMzZkNzQwY2VlNDRjYzMyOWVmNGZjMWU=
12
12
  data.tar.gz: !binary |-
13
- MzZjZTU0N2JkYjlhYjUxNTVlNDA2OTFhMDViMjYxYzlhNTIwZTA4NDlhMDUx
14
- YTdlYjkxNGE2NjQ4ZDI3NmE1ZTEyMzAzZTM0ZTEyNzliZmUzMDA5Y2I3MDI4
15
- ZjBmOTdiODJjYTMyZTdlNWVjZDc4MzhhODIwMzQ0NzMzYmFmY2Q=
13
+ MDZlZjU2YzZmN2EzYzdjMmFiZjRhYTQyMTkzYjBhMTk4OGRjZjlhMWU4N2Ew
14
+ ZWU1MzM3OWI2NjIxMjMzMGMyZWYxMmUzMDllNDJiYmVkNjgwOWNiMjM2YzI2
15
+ YjJmYjQ4ZDliMDBmMTgzMWZlYTU4N2U2MjQzNjJmY2NjYWQxNzM=
data/README.md CHANGED
@@ -4,6 +4,31 @@ Extensions & helper methods for accesing your swagger documentation from within
4
4
 
5
5
  This library is in the *very* early stages of development, there will be 'obvious' features that are missing and wild inefficiencies, but please feel free to file issues/enhancements if there's anything you think would be useful.
6
6
 
7
+ ## Recommended Setup
8
+
9
+ This extension encorporates all the extensions in a way that makes sense for most web applications, it's included by default for "classic" style applications.
10
+
11
+ ```
12
+ require "sinatra"
13
+ require "sinatra/swagger"
14
+
15
+ swagger "my-swagger.yaml"
16
+
17
+ # …etc
18
+ ```
19
+
20
+ ```
21
+ require "sinatra/base"
22
+ require "sinatra/swagger"
23
+
24
+ class Search < Sinatra::Base
25
+ register Sinatra::Swagger::RecommendedSetup
26
+ swagger "my-swagger.yaml"
27
+
28
+ # …etc
29
+ end
30
+ ```
31
+
7
32
  ## Param Validator
8
33
 
9
34
  This extension will use the `parameters` component of the route being accessed from your Swagger document to type cast your incoming parameters and raise `400` errors if any are incorrect:
@@ -115,4 +140,50 @@ end
115
140
 
116
141
  The `after` hook will check the response body and will run the schema validation and raise a `JSON::Schema::ValidationError` exception as the output doesn't match the schema.
117
142
 
118
- In order to not be restrictive, if the output doesn't look like JSON or if there's no schema defined, then no action will be taken and the body will be sent to the client.
143
+ In order to not be restrictive, if the output doesn't look like JSON or if there's no schema defined, then no action will be taken and the body will be sent to the client.
144
+
145
+ ## Spec Verb
146
+
147
+ This module configures your application to respond to requests to the root (`/`) using the **SPEC** verb. The response is `text/vnd.swagger.v2+yaml` with the full swagger document that your server is using.
148
+
149
+ ```ruby
150
+ require "sinatra/base"
151
+ require "sinatra/swagger"
152
+
153
+ class Search < Sinatra::Base
154
+ register Sinatra::Swagger::SpecVerb
155
+ swagger "swagger/shows.yaml"
156
+ end
157
+ ```
158
+
159
+ Inspecting a curl request:
160
+
161
+ ```bash
162
+ $ curl -v -X SPEC http://127.0.0.1:9292
163
+ > SPEC / HTTP/1.1
164
+ > User-Agent: curl/7.37.1
165
+ > Host: 127.0.0.1:9292
166
+ > Accept: */*
167
+ >
168
+ < HTTP/1.1 200 OK
169
+ < Content-Type: text/vnd.swagger.v2+yaml; charset=utf-8
170
+ ---
171
+ swagger: 2.0
172
+ paths:
173
+ /shows/{showId}:
174
+ # …etc
175
+ ```
176
+
177
+ ## Version Header
178
+
179
+ Adds an `X-Application-Version` header to every response which is set to the application title and version as set in the Swagger document, eg. `X-Application-Version: Application Title (0.1.0)`
180
+
181
+ ```ruby
182
+ require "sinatra/base"
183
+ require "sinatra/swagger"
184
+
185
+ class Search < Sinatra::Base
186
+ register Sinatra::Swagger::VersionHeader
187
+ swagger "swagger/shows.yaml"
188
+ end
189
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -107,6 +107,4 @@ module Sinatra
107
107
  end
108
108
  end
109
109
  end
110
-
111
- register Swagger::ParamValidator
112
110
  end
@@ -0,0 +1,19 @@
1
+ require "sinatra/swagger/param_validator"
2
+ require "sinatra/swagger/spec_enforcer"
3
+ require "sinatra/swagger/spec_verb"
4
+ require "sinatra/swagger/version_header"
5
+
6
+ module Sinatra
7
+ module Swagger
8
+ module RecommendedSetup
9
+ def self.registered(app)
10
+ app.register Sinatra::Swagger::SpecEnforcer unless app.production?
11
+ app.register Sinatra::Swagger::ParamValidator
12
+ app.register Sinatra::Swagger::SpecVerb
13
+ app.register Sinatra::Swagger::VersionHeader
14
+ end
15
+ end
16
+ end
17
+
18
+ register Swagger::RecommendedSetup
19
+ end
@@ -0,0 +1,18 @@
1
+ require "sinatra/multi_route"
2
+ require "sinatra/swagger/swagger_linked"
3
+
4
+ module Sinatra
5
+ module Swagger
6
+ module SpecVerb
7
+ def self.registered(app)
8
+ app.register Sinatra::MultiRoute
9
+ app.register Swagger::SwaggerLinked
10
+
11
+ app.route 'SPEC', '/' do
12
+ content_type "text/vnd.swagger.v2+yaml; charset=utf-8"
13
+ YAML.dump(settings.swagger.spec)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ require "sinatra/swagger/swagger_linked"
2
+
3
+ module Sinatra
4
+ module Swagger
5
+ module VersionHeader
6
+ def self.registered(app)
7
+ app.register Swagger::SwaggerLinked
8
+
9
+ app.before do
10
+ headers['X-Application-Version'] = "#{settings.swagger['info']['title']} (#{settings.swagger['info']['version']})"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,6 @@
1
1
  require "sinatra/swagger/version"
2
2
  require "sinatra/swagger/param_validator"
3
3
  require "sinatra/swagger/spec_enforcer"
4
+ require "sinatra/swagger/spec_verb"
5
+ require "sinatra/swagger/version_header"
6
+ require "sinatra/swagger/recommended"
data/lib/swagger/base.rb CHANGED
@@ -19,6 +19,8 @@ module Swagger
19
19
  end
20
20
 
21
21
  class Base
22
+ attr_reader :spec
23
+
22
24
  # Pre-load JSON-schema files used for validation
23
25
  Dir.glob(File.join(__dir__, "../../schema/*-schema.json")) do |schema|
24
26
  data = JSON.parse(File.read(schema))
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "json-schema", "~> 2.5", ">= 2.5.1"
23
23
  s.add_dependency "sinatra", "~> 1.4"
24
+ s.add_dependency "sinatra-contrib", "~>1.4"
24
25
 
25
26
  s.add_development_dependency "rake", "~> 10.4"
26
27
  s.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.4'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra-contrib
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.4'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.4'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -88,9 +102,12 @@ files:
88
102
  - VERSION
89
103
  - lib/sinatra/swagger.rb
90
104
  - lib/sinatra/swagger/param_validator.rb
105
+ - lib/sinatra/swagger/recommended_setup.rb
91
106
  - lib/sinatra/swagger/spec_enforcer.rb
107
+ - lib/sinatra/swagger/spec_verb.rb
92
108
  - lib/sinatra/swagger/swagger_linked.rb
93
109
  - lib/sinatra/swagger/version.rb
110
+ - lib/sinatra/swagger/version_header.rb
94
111
  - lib/swagger/base.rb
95
112
  - lib/swagger/rack.rb
96
113
  - schema/README.md