swagger_coverage 0.0.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +35 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/code_parser.rb +48 -0
- data/lib/swagger_cov.rb +44 -0
- data/lib/swagger_coverage/version.rb +3 -0
- data/lib/swagger_parser.rb +39 -0
- data/swagger_coverage.gemspec +31 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41af26bf939196920c683199bca51301caac5305
|
4
|
+
data.tar.gz: 3ea266df6d6af53d250ae54d2031ef3a5501b1da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a781c9d0196ca1a0654f574859650acf424f8e11d284945757e27a007abfdb7685d253594ccbadcc21b15ee27c6224612f9dfad29118004d46376871fc6f82e6
|
7
|
+
data.tar.gz: 0291a28bdaec7448c818bc4a74f2ea4a8fe7aae19e6c11273099653e112850d43c1a107ef7989424c91934ce7758a3941ca0c6de8070b19e2dafea547b66f312
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
before_script:
|
2
|
+
["bundle install --jobs $(nproc) --path=/cache/bundler"]
|
3
|
+
|
4
|
+
stages:
|
5
|
+
- test
|
6
|
+
- build_gem
|
7
|
+
- deploy
|
8
|
+
|
9
|
+
unit_tests:
|
10
|
+
stage: test
|
11
|
+
tags:
|
12
|
+
- docker
|
13
|
+
script:
|
14
|
+
- bundle exec rspec spec/unit_tests
|
15
|
+
|
16
|
+
functional_tests:
|
17
|
+
stage: test
|
18
|
+
tags:
|
19
|
+
- docker
|
20
|
+
script:
|
21
|
+
- bundle exec rspec spec/functional_tests
|
22
|
+
|
23
|
+
build_gem:
|
24
|
+
stage: build_gem
|
25
|
+
only:
|
26
|
+
- master
|
27
|
+
script:
|
28
|
+
- gem build swagger_coverage.gemspec
|
29
|
+
|
30
|
+
deploy:
|
31
|
+
stage: deploy
|
32
|
+
only:
|
33
|
+
- master
|
34
|
+
script:
|
35
|
+
- ruby -v #will be changed to push gem to rubygems.org
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at andrewh@spiceworks.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Harthcock
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# SwaggerCoverage
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/swagger_coverage`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'swagger_coverage'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install swagger_coverage
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
An instance of SwaggerCoverage must first be created. The "routes" parameter accepts a string of all of the source code routes. Path_to_file is the path where your swagger doc is located. The swagger doc should be either yaml or json.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
routes = "users GET /users(.:format) users#index
|
27
|
+
POST /users(.:format) users#create
|
28
|
+
new_user GET /users/new(.:format) users#new
|
29
|
+
edit_user GET /users/:id/edit(.:format) users#edit
|
30
|
+
api GET /api(.:format) redirect(301, /swagger/dist/index.html?url=/apidocs/api-docs.json)"
|
31
|
+
path_to_file = File.join(File.dirname(__FILE__), '../heroku-pets.json')
|
32
|
+
swaggercov = SwaggerCoverage::Parser.new(routes, path_to_file)
|
33
|
+
|
34
|
+
```
|
35
|
+
To compare route coverage, call the "check_coverage" method. This method will return a string array of the routes that do not match. If the routes from the docs match the source code, an empty array will be returned. The check_coverage method also accepts a boolean parameter for testing api coverage. If passed as true, check_coverage will only compare routes that include '/api'
|
36
|
+
|
37
|
+
```
|
38
|
+
comparison_results = swaggercov.check_coverage # => ["/users(.:format)", "users#create", "/api(.:format)"]
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/swagger_coverage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "swagger_coverage"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/code_parser.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class CodeParser
|
2
|
+
|
3
|
+
def initialize(output)
|
4
|
+
@raw_routes_output = output
|
5
|
+
end
|
6
|
+
|
7
|
+
def api_endpoints(output = @raw_routes_output, api = false)
|
8
|
+
endpoints = []
|
9
|
+
parsed_routes(output).each do |route|
|
10
|
+
if api
|
11
|
+
endpoints << route[:route] if route[:route].include?('/api')
|
12
|
+
else
|
13
|
+
endpoints << route[:route]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
endpoints
|
17
|
+
end
|
18
|
+
|
19
|
+
#returns all route http request type
|
20
|
+
def http_requests(output = @raw_routes_output)
|
21
|
+
request_type = []
|
22
|
+
parsed_routes(output).each do |route|
|
23
|
+
if route[:request_type] =~ /[\/]/
|
24
|
+
request_type << route[:type]
|
25
|
+
else
|
26
|
+
request_type << route[:request_type]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
request_type
|
30
|
+
end
|
31
|
+
|
32
|
+
def parsed_routes(output = raw_routes_output)
|
33
|
+
#add 'none specified'
|
34
|
+
routes = []
|
35
|
+
output.strip.each_line do |line|
|
36
|
+
split = line.split(' ')
|
37
|
+
route = {}
|
38
|
+
route[:type] = split[0]
|
39
|
+
route[:request_type] = split[1]
|
40
|
+
route[:route] = split[2]
|
41
|
+
route[:controller] = split[3]
|
42
|
+
route[:action] = split[4]
|
43
|
+
routes << route
|
44
|
+
end
|
45
|
+
routes
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/swagger_cov.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "swagger_coverage/version"
|
2
|
+
require "swagger_parser"
|
3
|
+
require "code_parser"
|
4
|
+
|
5
|
+
module SwaggerCoverage
|
6
|
+
class Parser
|
7
|
+
|
8
|
+
def initialize(output, swagger_docs)
|
9
|
+
@output = output
|
10
|
+
@swagger_docs = swagger_docs
|
11
|
+
@swagger_parser = SwaggerParser.new(@swagger_docs)
|
12
|
+
@code_parser = CodeParser.new(output)
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_request_types
|
16
|
+
code_request_types = @code_parser.http_requests
|
17
|
+
swagger_request_types = @swagger_parser.http_requests
|
18
|
+
request_types_diff = compare_routes(code_request_types, swagger_request_types)
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_routes(api = false)
|
22
|
+
code_endpoints = @code_parser.api_endpoints(@output, api)
|
23
|
+
swagger_endpoints = @swagger_parser.api_endpoints
|
24
|
+
routes_diff = compare_routes(code_endpoints, swagger_endpoints)
|
25
|
+
end
|
26
|
+
|
27
|
+
def compare_routes(code_routes, swagger_routes)
|
28
|
+
endpoints_match = code_routes.eql?(swagger_routes)
|
29
|
+
endpoint_diff = []
|
30
|
+
if !endpoints_match
|
31
|
+
if code_routes.size() > swagger_routes.size()
|
32
|
+
endpoint_diff = code_routes - swagger_routes
|
33
|
+
#raise "DOCUMENTATION DOES NOT CONTAIN THE FOLLOWING ROUTES FROM SOURCE: #{endpoint_diff}"
|
34
|
+
else
|
35
|
+
endpoint_diff = swagger_routes - code_routes
|
36
|
+
#raise "SOURCE CODE CONTAINS THE FOLLOWING ROUTES NOT FOUND IN DOCUMENTATION: #{endpoint_diff}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
endpoint_diff
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class SwaggerParser
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
@yaml_file = @path.include?('yaml')
|
9
|
+
@yaml_file ? @docs = YAML.load_file(path) : @docs = File.read(path)
|
10
|
+
@yaml_file ? @parse = @docs : @parse = JSON.parse(@docs)
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_endpoints
|
14
|
+
endpoints = []
|
15
|
+
base_path = @parse['basePath']
|
16
|
+
@parse['paths'].each do |path|
|
17
|
+
endpoints << base_path + path.first.gsub('{', ':').gsub('}', '')
|
18
|
+
end
|
19
|
+
endpoints
|
20
|
+
end
|
21
|
+
|
22
|
+
def http_requests
|
23
|
+
request_types_arr = []
|
24
|
+
paths_arr = []
|
25
|
+
@parse['paths'].each do |path|
|
26
|
+
paths_arr << path.first
|
27
|
+
end
|
28
|
+
paths_arr.each do |path|
|
29
|
+
@yaml_file ? req = @parse['paths'] : req = @parse['paths'][path]
|
30
|
+
@yaml_file ? req = req[path] : req
|
31
|
+
req.each do |type|
|
32
|
+
result = (type.first).upcase
|
33
|
+
request_types_arr << result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
request_types_arr
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'swagger_coverage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "swagger_coverage"
|
8
|
+
spec.version = SwaggerCoverage::VERSION
|
9
|
+
spec.authors = ["Andrew Harthcock"]
|
10
|
+
spec.email = ["andrewh@spiceworks.com"]
|
11
|
+
|
12
|
+
spec.summary = "A tool designed to report on swagger documentation coverage for phoenix and rails APIs."
|
13
|
+
spec.description = "swagger_coverage programmatically compares Swagger API routes to existing routes from the source code and reports the difference(s)"
|
14
|
+
spec.homepage = "https://gitlab.spice.spiceworks.com/spiceworks/swagger-cov.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swagger_coverage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Harthcock
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
description: swagger_coverage programmatically compares Swagger API routes to existing
|
28
|
+
routes from the source code and reports the difference(s)
|
29
|
+
email:
|
30
|
+
- andrewh@spiceworks.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- ".gitlab-ci.yml"
|
37
|
+
- ".rspec"
|
38
|
+
- ".travis.yml"
|
39
|
+
- CODE_OF_CONDUCT.md
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/code_parser.rb
|
47
|
+
- lib/swagger_cov.rb
|
48
|
+
- lib/swagger_coverage/version.rb
|
49
|
+
- lib/swagger_parser.rb
|
50
|
+
- swagger_coverage.gemspec
|
51
|
+
homepage: https://gitlab.spice.spiceworks.com/spiceworks/swagger-cov.git
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.1
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.8
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A tool designed to report on swagger documentation coverage for phoenix and
|
75
|
+
rails APIs.
|
76
|
+
test_files: []
|