Skip to content

Commit 0f6390e

Browse files
author
Jeff Cousens
committed
Initial commit.
0 parents  commit 0f6390e

31 files changed

+2280
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

.rubocop.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Metrics/AbcSize:
2+
Max: 30
3+
4+
Metrics/ClassLength:
5+
Max: 200
6+
7+
Metrics/LineLength:
8+
Max: 120
9+
10+
Metrics/MethodLength:
11+
Max: 25
12+
13+
Metrics/PerceivedComplexity:
14+
Max: 10
15+
16+
Style/Documentation:
17+
Enabled: false
18+
19+
Style/FileName:
20+
Enabled: false

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.2.2

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: ruby
2+
cache: bundler
3+
script:
4+
- bundle exec rubocop

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in swagger-diff.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2015, Civis Analytics
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of Civis Analytics nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Swagger::Diff
2+
3+
[![Build Status](https://travis-ci.org/civisanalytics/swagger-diff.svg?branch=master)](https://travis-ci.org/civisanalytics/swagger-diff)
4+
5+
![Swagger::Diff in action](swagger-diff.gif)
6+
7+
> You can tell me by the way I walk - Genesis
8+
9+
Swagger::Diff is a utility for comparing two different
10+
[Swagger](http://swagger.io/) specifications.
11+
Its intended use is to determine whether a newer API specification is
12+
backwards-compatible with an older API specification.
13+
It provides both an [RSpec](http://rspec.info/) matcher and helper functions
14+
that can be used directly.
15+
Specifications are considered backwards compatible if:
16+
17+
- all path and verb combinations in the old specification are present in the
18+
new one
19+
- no request parameters are required in the new specification that were not
20+
required in the old one
21+
- all request parameters in the old specification are present in the new one
22+
- all request parameters in the old specification have the same type in the
23+
new one
24+
- all response attributes in the old specification are present in the new one
25+
- all response attributes in the old specification have the same type in the new
26+
one
27+
28+
## Installation
29+
30+
Add this line to your application's Gemfile:
31+
32+
```ruby
33+
gem 'swagger-diff'
34+
```
35+
36+
And then execute:
37+
38+
$ bundle
39+
40+
Or install it yourself as:
41+
42+
$ gem install swagger-diff
43+
44+
## Usage
45+
46+
Swagger::Diff uses the [Swagger](https://github.com/swagger-rb/swagger-rb) gem
47+
to parse Swagger specifications.
48+
Specifications can be any
49+
[supported format](https://github.com/swagger-rb/swagger-rb/tree/v0.2.3#parsing):
50+
51+
- the path to a file containing a Swagger specification.
52+
This may be local (*e.g.*, `/path/to/swagger.json`) or remote (*e.g.*,
53+
`http://host.domain/swagger.yml`)
54+
- a Hash containing a parsed Swagger specification (*e.g.*, the output of
55+
`JSON.parse`)
56+
- a string of JSON containing Swagger specification
57+
- a string of YAML containing Swagger specification
58+
59+
### RSpec
60+
61+
```ruby
62+
expect(<new>).to be_compatible_with(<old>)
63+
```
64+
65+
If `new` is incompatible with `old`, the spec will fail and print a list of
66+
backwards-incompatibilities.
67+
68+
### Direct Invocation
69+
70+
If you are not using RSpec, you can directly invoke the comparison function:
71+
72+
```ruby
73+
diff = Swagger::Diff::Diff.new(<old>, <new>)
74+
diff.compatible?
75+
```
76+
77+
It will return `true` if `new` is compatible with `old`, `false` otherwise.
78+
`#incompatibilities` will return a hash containing the incompatible endpoints,
79+
request parameters, and response attributes; *e.g.*,
80+
81+
```ruby
82+
{ endpoints: ['put /a/{}'],
83+
request_params: {
84+
'get /a/' => ['missing request param: limit (type: integer)'],
85+
'post /a/' => ['new required request param: extra'],
86+
'put /b/{}' => ['new required request param: extra']
87+
},
88+
response_attributes: {
89+
'post /a/' => ['missing attribute from 200 response: description (type: string)'],
90+
'get /a/{}' => ['missing attribute from 200 response: description (type: string)'],
91+
'put /b/{}' => ['missing attribute from 200 response: description (type: string)']
92+
}
93+
}
94+
```
95+
96+
### Command-Line
97+
98+
It also includes a command-line version:
99+
100+
```bash
101+
$ swagger-diff <old> <new>
102+
```
103+
104+
`swagger-diff` will print a list of any backwards-incompatibilities `new` has
105+
when compared to `old`.
106+
107+
## Gem Development
108+
109+
After checking out the repo, run `bin/setup` to install dependencies.
110+
Then, run `bin/console` for an interactive prompt that will allow you to experiment.
111+
112+
To install this gem onto your local machine, run `bundle exec rake install`.
113+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
114+
115+
## Contributing
116+
117+
1. Fork it ( https://github.com/civisanalytics/swagger-diff/fork )
118+
2. Create your feature branch (`git checkout -b my-new-feature`)
119+
3. Commit your changes (`git commit -am 'Add some feature'`)
120+
4. Push to the branch (`git push origin my-new-feature`)
121+
5. Create a new Pull Request
122+
123+
## License
124+
125+
Swagger::Diff is released under the [BSD 3-Clause License](LICENSE.txt).

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'bundler/gem_tasks'

bin/console

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'bundler/setup'
4+
require 'swagger/diff'
5+
6+
require 'pry'
7+
Pry.start

0 commit comments

Comments
 (0)