Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rspec-rails-swagger
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rspec-rails-swagger
Commits
88083617
Commit
88083617
authored
Mar 16, 2017
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept tags for operation from parent contexts
parent
fe947519
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
13 deletions
+42
-13
helpers.rb
lib/rspec/rails/swagger/helpers.rb
+13
-3
make_site.sh
make_site.sh
+2
-0
request_spec.rb
spec/requests/request_spec.rb
+4
-10
helpers_spec.rb
spec/rspec/rails/swagger/helpers_spec.rb
+23
-0
No files found.
lib/rspec/rails/swagger/helpers.rb
View file @
88083617
...
...
@@ -42,13 +42,16 @@ module RSpec
attributes
.
symbolize_keys!
raise
ArgumentError
,
"Path must start with a /"
unless
template
.
starts_with?
(
'/'
)
#TODO template might be a $ref
meta
=
{
swagger_object: :path_item
,
swagger_document:
attributes
[
:swagger_document
]
||
RSpec
.
configuration
.
swagger_docs
.
keys
.
first
,
swagger_path_item:
{
path:
template
}
swagger_path_item:
{
path:
template
}
,
}
# Merge tags passed into the path with those from parent contexts.
if
attributes
[
:tags
]
meta
[
:tags
]
=
(
metadata
.
try
(
:[]
,
:tags
)
||
[])
+
attributes
[
:tags
]
end
describe
(
template
,
meta
,
&
block
)
end
end
...
...
@@ -58,6 +61,12 @@ module RSpec
def
operation
method
,
attributes
=
{},
&
block
attributes
.
symbolize_keys!
# Include tags from parent contexts so you can tag all the paths
# in a controller at once.
if
metadata
.
try
(
:[]
,
:tags
).
present?
attributes
[
:tags
]
||=
[]
attributes
[
:tags
]
+=
metadata
[
:tags
]
end
method
=
method
.
to_s
.
downcase
validate_method!
method
...
...
@@ -175,7 +184,8 @@ module RSpec
end
def
tags
*
tags
metadata
[
:swagger_operation
][
:tags
]
=
tags
metadata
[
:swagger_operation
][
:tags
]
||=
[]
metadata
[
:swagger_operation
][
:tags
]
+=
tags
end
def
response
status_code
,
attributes
=
{},
&
block
...
...
make_site.sh
View file @
88083617
...
...
@@ -28,3 +28,5 @@ fi
cd
-
bundle
exec
rspec
# Duplicating the body of the rake task. Need to figure out how to call it directly.
bundle
exec
rspec
-f
RSpec::Rails::Swagger::Formatter
--order
defined
-t
swagger_object
spec/requests/request_spec.rb
View file @
88083617
require
'swagger_helper'
RSpec
.
describe
"Requestsing"
,
type: :request
do
# path "/ping" do
# operation :put do
# response(200, {description: 'OK'})
# puts "in here"
# end
# end
path
'/posts'
do
operation
"GET"
,
summary
:"fetch list"
do
RSpec
.
describe
"Sample Requests"
,
type: :request
,
tags:
[
:context_tag
]
do
path
'/posts'
,
tags:
[
'path_tag'
]
do
operation
"GET"
,
summary:
"fetch list"
do
produces
'application/json'
tags
'operation_tag'
response
(
200
,
{
description:
"successful"
})
end
...
...
spec/rspec/rails/swagger/helpers_spec.rb
View file @
88083617
...
...
@@ -34,6 +34,17 @@ RSpec.describe RSpec::Rails::Swagger::Helpers::Paths do
subject
.
path
(
'/ping'
,
swagger_document:
'hello_swagger.json'
)
end
it
"passes tags through to the metadata"
do
expect
(
subject
).
to
receive
(
:describe
).
with
(
"/ping"
,
{
swagger_object: :path_item
,
swagger_document:
RSpec
.
configuration
.
swagger_docs
.
keys
.
first
,
swagger_path_item:
{
path:
'/ping'
},
tags:
[
'tag1'
]
})
subject
.
path
(
'/ping'
,
tags:
[
'tag1'
])
end
end
RSpec
.
describe
RSpec
::
Rails
::
Swagger
::
Helpers
::
PathItem
do
...
...
@@ -81,6 +92,18 @@ RSpec.describe RSpec::Rails::Swagger::Helpers::PathItem do
operationId:
'updatePetWithForm'
)
end
it
'includes tags from metadata of parent contexts'
do
subject
.
metadata
=
{
tags:
[
'baz'
]
}
expect
(
subject
).
to
receive
(
:describe
).
with
(
'get'
,
{
swagger_object: :operation
,
swagger_operation:
{
tags:
[
'foo'
,
'baz'
],
method: :get
}
})
subject
.
operation
(
:get
,
tags:
[
'foo'
])
end
end
described_class
::
METHODS
.
each
do
|
method
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment