• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    Ruby
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility for comparing two Swagger specifications.

Swagger::Diff

Build Status Gem Version

Swagger::Diff in action

You can tell me by the way I walk - Genesis

Swagger::Diff is a utility for comparing two different Open API Initiative (OAI) specifications (fka Swagger specifications). Its intended use is to determine whether a newer API specification is backwards-compatible with an older API specification. It provides both an RSpec matcher and helper functions that can be used directly. Specifications are considered backwards compatible if:

  • all path and verb combinations in the old specification are present in the new one
  • no request parameters are required in the new specification that were not required in the old one
  • all request parameters in the old specification are present in the new one
  • all request parameters in the old specification have the same type in the new one
  • all response attributes in the old specification are present in the new one
  • all response attributes in the old specification have the same type in the new one

It can also be used to enumerate all changes between two specifications (i.e., to generate a changelog).

Read more on the Civis Analytics blog.

Installation

Add this line to your application's Gemfile:

gem 'swagger-diff'

And then execute:

$ bundle

Or install it yourself as:

$ gem install swagger-diff

Usage

OAI specifications can be any valid OAI file format, raw or parsed:

  • the path to a file containing an OAI specification. This may be local (e.g., /path/to/specification.json) or remote (e.g., http://host.domain/specification.yml)
  • a Hash containing a parsed OAI specification (e.g., the output of JSON.parse)
  • a string of JSON containing an OAI specification
  • a string of YAML containing an OAI specification

RSpec

expect(<new>).to be_compatible_with(<old>)

If new is incompatible with old, the spec will fail and print a list of backwards-incompatibilities.

Direct Invocation

If you are not using RSpec, you can directly invoke the comparison function:

diff = Swagger::Diff::Diff.new(<old>, <new>)
diff.compatible?

It will return true if new is compatible with old, false otherwise. #incompatibilities will return a hash containing the incompatible endpoints, request parameters, and response attributes; e.g.,

{ endpoints: ['put /a/{}'],
  request_params: {
    'get /a/' => ['missing request param: limit (in: query, type: integer)'],
    'post /a/' => ['new required request param: extra'],
    'put /b/{}' => ['new required request param: extra']
  },
  response_attributes: {
    'post /a/' => ['missing attribute from 200 response: description (in: body, type: string)'],
    'get /a/{}' => ['missing attribute from 200 response: description (in: body, type: string)'],
    'put /b/{}' => ['missing attribute from 200 response: description (in: body, type: string)']
  }
}

You can also directly invoke the changes function:

diff = Swagger::Diff::Diff.new(<old>, <new>)
diff.changes

#changes will return a hash containing the changed endpoints, request parameters, and response attributes; e.g.,

{ new_endpoints: ['delete /pets/{}', 'get /pets/{}', 'post /pets'],
  new_request_params: {
    'get /pets' => ['new request param: tags (in: query, type: array)',
                    'new request param: limit (in: query, type: integer)'] },
  new_response_attributes: {},
  removed_endpoints: [],
  removed_request_params: {},
  removed_response_attributes: {}
}

Command-Line

It also includes a command-line version:

$ swagger-diff -i <old> <new>

swagger-diff will print a list of any backwards-incompatibilities new has when compared to old.

For backwards-compatibility with previous versions of swagger-diff, the -i argument is optional:

$ swagger-diff <old> <new>

The command-line version can also be used to generate a list of all changes (i.e., a changelog):

$ swagger-diff -c <old> <new>

Gem Development

After checking out the repo, run bin/setup to install dependencies. Then, 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 to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

See CONTRIBUTING.

License

Swagger::Diff is released under the BSD 3-Clause License.

OpenAPI (fka Swagger) Specification License

Swagger::Diff includes an unmodified copy of the OpenAPI Specification. The OpenAPI Specification is licensed under the Apache License, Version 2.0.

JSON Schema Specification License

Swagger::Diff includes an unmodified copy of the JSON Schema Specification, draft v4. The JSON Schema Specification is licensed under the Simplified BSD License.

More Repositories

1

python-glmnet

A python port of the glmnet package for fitting generalized linear models via penalized maximum likelihood.
Python
262
star
2

ruby_audit

Checks Ruby and RubyGems against known security vulnerabilities.
Ruby
71
star
3

civisml-extensions

scikit-learn-compatible estimators from Civis Analytics
Python
59
star
4

muffnn

Multilayer Feed-Forward Neural Network predictive model implementations with TensorFlow and scikit-learn
Python
45
star
5

civis-python

Civis API Python Client
Python
34
star
6

dpwgan

Differentially-private Wasserstein GAN implementation in PyTorch
Python
27
star
7

iam-role-injector

Assumes an IAM role via awscli STS call, injecting temporary credentials into shell environment
Shell
26
star
8

datascience-python

Common dependencies for data science workflows
Dockerfile
25
star
9

potato

d3 force graph viz tool
CoffeeScript
25
star
10

tableau_api

Ruby interface to the Tableau API
Ruby
22
star
11

civis-r

Civis API Client for R: https://civisanalytics.com/products/civis-platform/
R
16
star
12

async-graph-data-flow

Asynchronous functions that pass data along a directed acyclic graph
Python
16
star
13

workflows-public

Civis workflows examples.
Python
13
star
14

d3_tutorial

How to use D3 to build data visualizations.
HTML
12
star
15

datascience-r

Docker image for R.
Dockerfile
11
star
16

civis-d4bl-data-viz

Materials for the 'Data Visualization for Black Lives' workshop presented by Brecia Young and Cameron Clarke (Civis Analytics) at the 2019 Data for Black Lives II conference.
R
11
star
17

GephiForceDiagramTool

Command-line tool for building Gephi force-directed graph diagrams.
Java
10
star
18

go-makefile

Compile a go project, package it to a defined format, and push a release to GitHub.
Shell
6
star
19

mistral_client

Ruby client for Mistral, OpenStack's workflow service
Ruby
5
star
20

civis-jupyter-r

Custom Jupyter Notebook image for R
Dockerfile
4
star
21

platform-code-examples

Python
4
star
22

model-deployment

App for deploying CivisML models as web APIs
Python
3
star
23

gogelf

Go Library for the Graylog Extended Log Format
Go
3
star
24

civis-jupyter-python3

Custom Jupyter Notebook image for Python 3
Dockerfile
3
star
25

civis_political_r_training

An R package for the "Introduction to Data Munging and Visualization in R" session at the Civis 2019 Political Community Summit.
R
2
star
26

civis-jupyter-python2

Custom Jupyter Notebook image for Python 2
Dockerfile
1
star
27

civis-services-streamlit

Civis Services Docker Image for Streamlit
Python
1
star
28

civis-services-flask

Example Flask app hosted in Civis
Python
1
star