Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger-diff failed #48

Closed
AndroidLearnerchn opened this issue Jul 21, 2017 · 5 comments
Closed

swagger-diff failed #48

AndroidLearnerchn opened this issue Jul 21, 2017 · 5 comments

Comments

@AndroidLearnerchn
Copy link

/var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:206:in hash_property': undefined method []' for true:TrueClass (NoMethodError) from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:223:in block in properties'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in each' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in properties'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:136:in schema' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:108:in refs'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:162:in nested' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:179:in properties_for_ref'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:226:in block in properties' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in each'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in properties' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:136:in schema'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:108:in refs' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:162:in nested'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:179:in properties_for_ref' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:226:in block in properties'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in each' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in properties'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:136:in schema' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:108:in refs'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:133:in schema' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:237:in block in request_params_inner'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:235:in each' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:235:in request_params_inner'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:19:in block in request_params' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:18:in each'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:18:in request_params' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:142:in block in changed_request_params_enumerator'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in change_hash'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:130:in new_or_changed_request_params' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:13:in changes'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:48:in changed_endpoints_message' from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:21:in changes_message'
from /var/lib/gems/2.1.0/gems/swagger-diff-1.1.0/exe/swagger-diff:40:in <top (required)>' from /usr/local/bin/swagger-diff:23:in load'
from /usr/local/bin/swagger-diff:23:in <main>

I am getting this error after I run a swagger-diff on 2 json. Can anyone help why it is crashing? How to find if something within my json is breaking it ?

I used swagger-diff -c old.json new.json

@jeffreyc
Copy link
Contributor

Thank you for your report. Looking at the code, my best guess is that you have additionalProperties: true somewhere in your specification. My understanding of the OAI specification is that, unlike JSON Schema, additionalProperties must be a hash (this is supported by swagger-api/swagger-codegen#1318 (comment)). If my guess is correct, you should be able to resolve this by removing any additionalProperties: true lines or updating them to be hashes.

If that doesn't help, you may want to validate your Swagger specifications using Swagger's Validator Badge to confirm there are no errors. The validator isn't perfect, but it will catch most common errors.

If that still doesn't identify any issues, it's hard to tell from the exception alone what might be wrong. If you are comfortable sharing your specifications, I would be happy to see if I can recreate the problem and identify the cause. Feel free to anonymize, obfuscate, or truncate the specification, as long as it's still valid; I only need a snippet that will allow me to recreate the problem, and not the full specification.

@AndroidLearnerchn
Copy link
Author

I changed that "additionalProperties": {"type":"string"}, and now I am getting this error :

/var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:178:in properties_for_ref': undefined method key?' for nil:NilClass (NoMethodError) from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:218:in block in properties'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in each' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in properties'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:136:in schema' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:108:in refs'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:162:in nested' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:179:in properties_for_ref'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:226:in block in properties' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in each'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:216:in properties' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:136:in schema'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:108:in refs' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:133:in schema'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:252:in block in response_attributes_inner' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:250:in each'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:250:in response_attributes_inner' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:29:in block in response_attributes'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:28:in each' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/specification.rb:28:in response_attributes'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:181:in block in changed_response_attributes_enumerator' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in each'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:112:in change_hash' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:176:in new_or_changed_response_attributes'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:15:in changes' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:48:in changed_endpoints_message'
from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/lib/swagger/diff/diff.rb:21:in changes_message' from /var/lib/gems/2.3.0/gems/swagger-diff-1.1.0/exe/swagger-diff:40:in <top (required)>'
from /usr/local/bin/swagger-diff:23:in load' from /usr/local/bin/swagger-diff:23:in

'
`
I checked the json on swagger validator, which showed 2 error regarding formdata, I removed those 2 as well from the path of my json. After that I started getting this error.

Any help / suggestion will be helpful.

@AndroidLearnerchn
Copy link
Author

And moreover, why does it is not showing error on online swagger editor after correction, but the same json is giving error with local swagger-validator ? This json, I have not changed the additionalProperties pattern.
Is there any difference between how those 2 tools works ? swagger-validator and swagger editor for validating json?

@jeffreyc
Copy link
Contributor

My best guess based on that error is you have an array without an items hash. Per https://swagger.io/specification/, under Fixed Fields, an items hash is required when specifying an array type.

Unfortunately, the Swagger specification isn't 100% machine validatable, so it's possible to run into these edge cases. I'm unfamiliar with the online Swagger editor you're referring to, so I can't speak as to its specific features or limitations.

@jeffreyc
Copy link
Contributor

It's been a month, so I'm going to trust that adding an items hash resolved your problem and close this issue. If you encounter additional problems, please either comment on this issue or create a new issue as appropriate. Thanks again for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants