civisanalytics / swagger-diff

Utility for comparing two Swagger specifications.
BSD 3-Clause "New" or "Revised" License
265 stars 32 forks source link

response_attributes_inner': undefined method `each' for nil:NilClass (NoMethodError) #21

Closed 123dev closed 8 years ago

123dev commented 8 years ago

Great tool, thanks for sharing. We find that it works in some cases, but not in all cases.

swagger-diff 176.json 179.json

C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:206:in `response_attributes_inner': undefined method `each' for nil:NilClass (NoMethodError)
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:28:in `block in response_attributes'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:27:in `each'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:27:in `response_attributes'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:118:in `block (2 levels) in incompatible_response_attributes_enumerator'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:117:in `each'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:117:in `block in incompatible_response_attributes_enumerator'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:142:in `each'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:142:in `each'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:142:in `each'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:142:in `none?'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:142:in `responses_compatible?'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:10:in `compatible?'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/exe/swagger-diff:8:in `<top (required)>'
        from C:/U/Ruby/bin/swagger-diff:23:in `load'
        from C:/U/Ruby/bin/swagger-diff:23:in `<main>'

Here's another one with a different error. swagger-diff 122.json 1.1_5.4-37-176.json

C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-core-0.2.3/lib/swagger/api.rb:11:in `build_api': Swagger version  is not currently supported (ArgumentError)
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-core-0.2.3/lib/swagger.rb:24:in `build'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:65:in `rescue in parse_swagger'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:57:in `parse_swagger'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:6:in `initialize'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:5:in `new'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:5:in `initialize'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/exe/swagger-diff:6:in `new'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/exe/swagger-diff:6:in `<top (required)>'
        from C:/U/Ruby/bin/swagger-diff:23:in `load'
        from C:/U/Ruby/bin/swagger-diff:23:in `<main>'

D:\Dev\Schemas>swagger-diff 1.0_5.5-1-122.json 1.0_5.4-37-176.json
C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-core-0.2.3/lib/swagger/api.rb:11:in `build_api': Swagger version  is not currently supported (ArgumentError)
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-core-0.2.3/lib/swagger.rb:24:in `build'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:65:in `rescue in parse_swagger'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:57:in `parse_swagger'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/specification.rb:6:in `initialize'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:5:in `new'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/lib/swagger/diff/diff.rb:5:in `initialize'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/exe/swagger-diff:6:in `new'
        from C:/U/Ruby/lib/ruby/gems/2.2.0/gems/swagger-diff-1.0.5/exe/swagger-diff:6:in `<top (required)>'
        from C:/U/Ruby/bin/swagger-diff:23:in `load'
        from C:/U/Ruby/bin/swagger-diff:23:in `<main>'

Thanks

jeffreyc commented 8 years ago

Thank you for your feedback, and we're glad you're finding the tool useful!

For the first error, there could be a variety of causes, including an invalid Swagger specification and a corner case that we don't handle correctly.

The second error is usually raised when a Swagger specification is missing the required swagger element.

Have you validated your Swagger? You can validate your Swagger using the Swagger Validator Badge tool.

If your Swagger is valid, we would need a minimal example to diagnose the problem. You can diff a file against itself (swagger-diff 1.json 1.json), and it should still raise an exception if there's a problem parsing the file. If you can paste a minimal specification that's both valid and recreates the error into a comment on this issue, I'd be happy to look into it. You're welcome to include your full specification, too, but I know those can be sensitive, and we definitely don't need it, just to be able to recreate the error.

123dev commented 8 years ago

Thanks Jeffrey for a prompt response and guidance on where to look.

Investigation revealed that our json does not pass schema or spec validation. (using swagger-cli) So we're looking into that.

However here's a interesting point. We've been using swagger-diff for several months now through rapidly changing API, and have only experienced the reported problems recently I went back and validated old versions of the API, and other than very early version, most did not pass the validation yet swagger-diff was working fine.

for example. 81.json passes swagger validation 122.json fails swagger validation yet swagger-diff successfully reports the breaking APIs between 3754 and 3852.

Most likely fixing the schema / spec validation errors would also fix swagger-diff errors. I'll report back once we clear out the validation errors.

Thanks again

jeffreyc commented 8 years ago

swagger-diff does not use a validating parser, so it's possible that it will work with invalid Swagger. However, it was written using the Swagger specification, and invalid Swagger may not work correctly. Hopefully fixing your Swagger to pass validation will also address the issues you encountered, but if not, let us know and we can help diagnose the issue.

123dev commented 8 years ago

Thanks Jeffrey I think it is safe to close this issue. Once we fix the spec issue and still have Swagger-diff issues, I'll log a new ticket.

Thanks very much creating a great tool and being very responsive.

jeffreyc commented 8 years ago

Sounds good. I'll close this issue, but definitely create a new issue if you find something that doesn't work as expected. The Swagger specification is pretty expansive, and while we've tested a lot of it, it's always possible there's a corner of it that behaves differently. Thanks again for your feedback, and we're glad to hear you're finding the tool useful!