SwaggerCoverage

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.

Installation

Add this line to your application's Gemfile:

gem 'swagger_coverage'

And then execute:

$ bundle

Or install it yourself as:

$ gem install swagger_coverage

Usage

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.

routes = "users          GET     /users(.:format)          users#index
                        POST     /users(.:format)          users#create
          new_user       GET     /users/new(.:format)      users#new
          edit_user      GET     /users/:id/edit(.:format) users#edit
          api            GET     /api(.:format) redirect(301, /swagger/dist/index.html?url=/apidocs/api-docs.json)"
path_to_file = File.join(File.dirname(__FILE__), '../heroku-pets.json')
swaggercov = SwaggerCoverage::Parser.new(routes, path_to_file)

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'

comparison_results = swaggercov.check_coverage # => ["/users(.:format)", "users#create", "/api(.:format)"]

Development

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.

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.

Contributing

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 code of conduct.

License

The gem is available as open source under the terms of the MIT License.