Closed AndroidLearnerchn closed 7 years ago
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 https://github.com/swagger-api/swagger-codegen/issues/1318#issuecomment-146302879). 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.
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
Any help / suggestion will be helpful.
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?
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.
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!
/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:ineach' 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:inschema' 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:innested' 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:inblock 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:inproperties' 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:inrefs' 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:inproperties_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:ineach' 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:inschema' 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:inschema' 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:ineach' 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:inblock 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:inrequest_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:ineach' 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:ineach' 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:innew_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:inchanged_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