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
d6556e33
Commit
d6556e33
authored
Sep 27, 2016
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show path, method and status code while generating docs
Fixes #10
parent
b8d7d6a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
10 deletions
+49
-10
formatter.rb
lib/rspec/rails/swagger/formatter.rb
+49
-10
No files found.
lib/rspec/rails/swagger/formatter.rb
View file @
d6556e33
require
'rspec/core/formatters/base_text_formatter'
RSpec
::
Support
.
require_rspec_core
"formatters/base_text_formatter"
RSpec
::
Support
.
require_rspec_core
"formatters/console_codes"
module
RSpec
module
RSpec
module
Rails
module
Rails
module
Swagger
module
Swagger
class
Formatter
<
RSpec
::
Core
::
Formatters
::
BaseTextFormatter
class
Formatter
<
RSpec
::
Core
::
Formatters
::
BaseTextFormatter
RSpec
::
Core
::
Formatters
.
register
self
,
:example_finished
,
:close
RSpec
::
Core
::
Formatters
.
register
self
,
:example_group_started
,
:example_passed
,
:example_pending
,
:example_failed
,
:example_finished
,
:close
def
documents
def
documents
# We don't try to load the docs in `initalize` because when running
# We don't try to load the docs in `initalize` because when running
...
@@ -13,22 +16,58 @@ module RSpec
...
@@ -13,22 +16,58 @@ module RSpec
@documents
||=
::
RSpec
.
configuration
.
swagger_docs
@documents
||=
::
RSpec
.
configuration
.
swagger_docs
end
end
def
example_group_started
(
notification
)
output
.
print
*
group_output
(
notification
)
end
def
example_passed
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:success
)
end
def
example_pending
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:pending
)
end
def
example_failed
(
notification
)
output
.
print
RSpec
::
Core
::
Formatters
::
ConsoleCodes
.
wrap
(
example_output
(
notification
),
:failure
)
end
def
example_finished
(
notification
)
def
example_finished
(
notification
)
metadata
=
notification
.
example
.
metadata
metadata
=
notification
.
example
.
metadata
return
unless
metadata
[
:swagger_object
]
==
:response
return
unless
metadata
[
:swagger_object
]
==
:response
# metadata.each do |k, v|
# Then add everything to the document
# puts "#{k}\t#{v}" if k.to_s.starts_with?("swagger")
# end
document
=
document_for
(
metadata
[
:swagger_document
])
document
=
document_for
(
metadata
[
:swagger_document
])
path_item
=
path_item_for
(
document
,
metadata
[
:swagger_path_item
])
path_item
=
path_item_for
(
document
,
metadata
[
:swagger_path_item
])
operation
=
operation_for
(
path_item
,
metadata
[
:swagger_operation
])
operation
=
operation_for
(
path_item
,
metadata
[
:swagger_operation
])
response_for
(
operation
,
metadata
[
:swagger_response
])
response
=
response_for
(
operation
,
metadata
[
:swagger_response
])
end
end
def
close
(
_notification
)
def
close
(
_notification
)
documents
.
each
{
|
k
,
v
|
write_json
(
k
,
v
)}
documents
.
each
{
|
k
,
v
|
write_json
(
k
,
v
)}
self
end
private
def
group_output
(
notification
)
metadata
=
notification
.
group
.
metadata
# This is a little odd because I didn't want to split the logic across
# a start and end method. Instead we just start a new line for each
# path and operation and just let the status codes pile up on the end.
# There's probably a better way that doesn't have the initial newline.
case
metadata
[
:swagger_object
]
when
:path_item
[
"
\n
"
,
metadata
[
:swagger_path_item
][
:path
]]
when
:operation
[
"
\n
"
,
metadata
[
:swagger_operation
][
:method
].
to_s
,
"
\t
"
]
end
end
def
example_output
(
notification
)
"
#{
notification
.
example
.
metadata
[
:swagger_response
][
:status_code
]
}
"
end
end
def
write_json
(
name
,
document
)
def
write_json
(
name
,
document
)
...
@@ -91,9 +130,9 @@ module RSpec
...
@@ -91,9 +130,9 @@ module RSpec
end
end
def
prepare_examples
(
examples
)
def
prepare_examples
(
examples
)
if
examples
[
"application/json"
].
present?
if
examples
[
'application/json'
].
kind_of?
String
begin
begin
examples
[
"application/json"
]
=
JSON
.
parse
(
examples
[
"application/json"
])
examples
[
'application/json'
]
=
JSON
.
parse
(
examples
[
'application/json'
])
rescue
JSON
::
ParserError
rescue
JSON
::
ParserError
end
end
end
end
...
...
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