@@ -37,7 +37,7 @@ rails generate rspec:swagger_install
3737## Documenting Your API
3838
3939Now you can edit ` spec/swagger_helper.rb ` and start filling in the top level
40- Swagger documention , e.g. basePath, [ definitions] ( http://swagger.io/specification/#definitionsObject ) ,
40+ Swagger documentation , e.g. basePath, [ definitions] ( http://swagger.io/specification/#definitionsObject ) ,
4141[ parameters] ( http://swagger.io/specification/#parametersDefinitionsObject ) ,
4242[ tags] ( http://swagger.io/specification/#tagObject ) , etc.
4343
@@ -66,7 +66,7 @@ works pretty well and supports multiple documents.
6666
6767## RSpec DSL
6868
69- The DSL follows the hierachy of the Swagger Schema:
69+ The DSL follows the hierarchy of the Swagger Schema:
7070
7171- [ Paths Object] ( http://swagger.io/specification/#paths-object-29 )
7272 - [ Path Item Object] ( http://swagger.io/specification/#path-item-object-32 )
@@ -98,7 +98,7 @@ RSpec.describe "Posts Controller", type: :request do
9898 # Path Object
9999 path ' /posts/{post_id}' do
100100 # Parameter Object
101- parameter " post_id" , {in: :path , type: :integer }
101+ parameter " post_id" , { in: :path , type: :integer }
102102 let(:post_id ) { 1 }
103103
104104 # Operation Object
@@ -113,30 +113,30 @@ RSpec.describe "Posts Controller", type: :request do
113113 # Parameter Object for content type could be defined like:
114114 consumes ' application/json'
115115 # or:
116- parameter ' Content-Type' , {in: :header , type: :string }
116+ parameter ' Content-Type' , { in: :header , type: :string }
117117 let(:'Content-Type' ) { ' application/json' }
118118 # one of them would be considered
119119
120120 # authorization token in the header:
121- parameter ' Authorization' , {in: :header , type: :string }
121+ parameter ' Authorization' , { in: :header , type: :string }
122122 let(:'Authorization' ) { ' Bearer <token-here>' }
123123
124124 # Parameter Object
125- parameter " post_id" , {in: :path , type: :integer }
125+ parameter " post_id" , { in: :path , type: :integer }
126126 let(:post_id ) { 1 }
127127
128128 # Parameter Object for Body
129- parameter " body" , {in: :body , required: true , schema: {
129+ parameter " body" , { in: :body , required: true , schema: {
130130 type: :object ,
131131 properties: {
132132 title: { type: :string },
133133 author_email: { type: :email }
134134 }
135135 }
136136 let (:body ) {
137- { post:
138- { title: ' my example' ,
139- author_email: ' [email protected] ' }
137+ { post:
138+ { title: ' my example' ,
139+ author_email: ' [email protected] ' }
140140 }
141141 }
142142 }
@@ -158,12 +158,44 @@ These methods are available inside of an RSpec contexts with the `type: :request
158158#### ` path(template, attributes = {}, &block) `
159159Defines a new Path Item.
160160
161+ The ` attributes ` parameter accepts:
162+ - ` swagger_doc ` a key in ` RSpec.configuration.swagger_docs ` that determines
163+ which file the path belongs in.
164+ - ` tags ` with an array of tags that will be applied to the child Operations.
165+
166+ You can also provide a default file and tags by setting them on a parent RSpec
167+ context block:
168+ ``` rb
169+ RSpec .describe " Sample Requests" , type: :request do
170+ # The swagger_doc will be used as a default for the paths defined within the
171+ # context block. Similarly, the tags will be merged with those set on paths
172+ # defined within them.
173+ context " setting defaults" , swagger_doc: ' default_document.json' , tags: [:context_tag ] do
174+ path ' /posts' , swagger_doc: ' overridden_document.yaml' tags: [' path_tag' ] do
175+ operation " GET" , summary: " fetch list" do
176+ produces ' application/json'
177+ tags ' operation_tag'
178+
179+ response(200 , { description: " successful" })
180+ end
181+ end
182+ end
183+ end
184+ ```
185+ The ` GET /posts ` operation in this example will be saved in the ` 'overridden_document.yaml' `
186+ file and tagged with ` ["context_tag", "path_tag", "operation_tag"] ` .
187+
188+
161189### Path Item Object
162190These methods are available inside of blocks passed to the ` path ` method.
163191
164192#### ` operation(method, attributes = {}, &block) `
165193Defines a new Operation Object. The ` method ` is case insensitive.
166194
195+ The ` attributes ` parameter accepts:
196+ - ` tags ` with an array of tags. These will be merged with tags passed to the
197+ Path Item or ` tags ` method inside the Operation's block.
198+
167199#### ` delete(attributes = {}, &block) `
168200Alias for ` operation(:delete, attributes, block) ` .
169201
@@ -203,7 +235,7 @@ parameter ref: "#/parameters/site_id"
203235Values for the parameters are set using ` let ` :
204236``` rb
205237post summary: " create" do
206- parameter " body" , in: :body , schema: { foo: :bar }
238+ parameter " body" , in: :body , schema: { foo: :bar }
207239 let(:body ) { { post: { title: ' asdf' , body: " blah" } } }
208240 # ...
209241end
@@ -245,7 +277,7 @@ RSpec.describe "Sample Requests", type: :request, tags: [:context_tag] do
245277 produces ' application/json'
246278 tags ' operation_tag'
247279
248- response(200 , {description: " successful" })
280+ response(200 , { description: " successful" })
249281 end
250282 end
251283end
0 commit comments