westfieldlabs / apivore

Tests your rails API against its Swagger description of end-points, models, and query parameters.
Apache License 2.0
213 stars 66 forks source link

RuntimeError: Unknown/unsupported Swagger version to validate against. #64

Closed shideneyu closed 8 years ago

shideneyu commented 8 years ago

Hi,

I followed the readme, installed apivore, but I get an issue that I can't manage to get rid of while running my specs

When I run my specs, I got this issue, that arises upon the call of instance_for for Apivre::SwaggerChecker :

RuntimeError: Unknown/unsupported Swagger version to validate against: 
from /home/shideneyu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/apivore-1.4.0/lib/apivore/swagger.rb:18:in `validate'

(after looking at the gem, I noticed that the variable 'version', alias of 'swagger' is nil (in /lib/apivore/swagger.rb); I added a debugger there for testing purposes and runned my tests upon it to discover this.)

My spec:

RSpec.describe 'Site API', type: :apivore, order: :defined do
  subject { Apivore::SwaggerChecker.instance_for('/api.json') }

  context 'has valid paths' do
    let(:params) { { "id" => 1 } }
    specify do
      expect(subject).to validate(
        :get, '/sites/{id}/pages/{id}.json', 200, params
      )
    end

    # or alternatively

    # it { is_expected.to validate( :get, '/deals/{id}.json', 200, params ) }
  end

  context 'and' do
    it 'tests all documented routes' do
      expect(subject).to validate_all_paths
    end
  end
end

By the way, as you can see in the attachment, my Swagger UI can successfully test the endpoint and renders 200, and the inputted url is http://localhost:3000/api.json

swaggerrr

hornc commented 8 years ago

Hi @shideneyu, thanks for getting in touch and reporting your issue.

The error message you are receiving is thrown when Apivore does not recognise (or cannot find) the Swagger version of your api spec. Currently Apivore only supports and validates Swagger 2.0, which is the current version. It is not yet backwards compatible with any earlier versions of swagger.

The way it checks for the swagger version is by looking for the property "swagger": which is a required field.

See https://github.com/westfieldlabs/apivore/blob/master/spec/data/sample2.0.json#L2 for an example.

The most likely cause is either you are using an older Swagger spec format, or that particular property is missing from your api.json? Let me know if that doesn't explain it, and maybe provide a link the swagger spec so I can look into it further, thanks!

shideneyu commented 8 years ago

Thanks you, I think that you are entirely right:

api.json

  {
  "apiVersion": "0.1",
  "swaggerVersion": "1.2",
  "produces": [
  "application/xml",
  "application/json",
  "application/octet-stream",
  "text/plain"
  ],
  "apis": [
  {
  "path": "/sites.{format}",
  "description": "Operations about sites"
  }
  ],
  "info": {}
  }

The thing is, I'm using grape-swagger , it is not compatible with Swagger 2.0.

Thanks you for your insight anyways !