cyprieng / swagger-parser

Give useful informations about your swagger files
MIT License
62 stars 59 forks source link

Should fix array definitions #19

Closed c-martinez closed 8 years ago

c-martinez commented 8 years ago

Not sure it is 100% correct, but maybe it works

cyprieng commented 8 years ago

Thanks for the PR, and sorry for the delay.

Why not just:

if def_spec.get('type') == 'array and 'items' in def_spec:
    self.definitions_example[def_name] = [ self.build_one_definition_example(self.get_definition_name_from_ref(def_spec['items']))]
    return True

if 'properties' in ....

See https://stackoverflow.com/questions/21069668/alternative-to-dict-comprehension-prior-to-python-2-7 for your test error.

c-martinez commented 8 years ago

Thanks. Would this work better?

cyprieng commented 8 years ago

Why not just:

if def_spec.get('type') == 'array and 'items' in def_spec:
    self.definitions_example[def_name] = [ self.build_one_definition_example(self.get_definition_name_from_ref(def_spec['items']))]
    return True

if 'properties' in ....

And do you want to make some test for this specific case (I can do it if you want) ?

c-martinez commented 8 years ago

Hmmm... I think that would fail if def_spec does not have a type defined or if items doesn't have a ref, wouldn't it?

svdgraaf commented 8 years ago

Any news on merging this?

cyprieng commented 8 years ago

Sorry for the wait.

@c-martinez I think the definition should have the type defined to array for array definitions. And do you have an example of items without $ref ? Also can you add a test for your changes ?

c-martinez commented 8 years ago

Hi @cyprieng ,

I think you are right about the array definition. But you can have items without $ref:

StringArray:
  type: array
  items:
    type: string

Tests -- yes, sorry, should have written them a while ago. Will append to this PR.

cyprieng commented 8 years ago

@c-martinez you're right. Thanks for the good work !

svdgraaf commented 8 years ago

awesome guys! Thanks! 👏