subeeshcbabu-zz / swagmock

Mock data generator for swagger api
MIT License
173 stars 38 forks source link

use "example" values when generating mocks #33

Closed Remco75 closed 7 years ago

Remco75 commented 7 years ago

When mocks for properties are generated, swagger supports 'examples' to be set. Using this makes for much more sensible mocks.

Remco75 commented 7 years ago

you can simply do this by doing this check in generators/index.js if (schema.example) { mockStr = schema.example } But it's no use for me until #32 is solved. Now I cloned the repo for the time being and did this fix. If you want to solve #32 I will make a PR

subeeshcbabu-zz commented 7 years ago

I was using the example in the early versions, however some swagger specs defined wrong examples and not adhered to the spec when examples were defined. This led to failures of validator tools like is-my-json-valid.

This is the change - https://github.com/subeeshcbabu/swagmock/commit/2493b9c642baf453ebf8af83e325b03f2eeba770

I can introduce an option useExamples and based on the that flag, continue to support the schema.example, what say?

If you want to send a PR for this, it would be cool.

Remco75 commented 7 years ago

ok, I see your point. Personally I think it's the users responsibility to generate proper examples, or the validation of the swagger should take this into account.

But I think the useExamples is a very good idea. I will do a PR tomorrow. If you do a backport to the 0.0x branch (I will continue that discussion in #32 )

And thnx for the swift response!

Remco75 commented 7 years ago

Sorry, couldnt find the time, will submit pr after the weekend

Remco75 commented 7 years ago

@subeeshcbabu , created a PR #39 for this on the 0.0.x branch. if you approve I will also create it on the 1.x branch. THnx!

subeeshcbabu-zz commented 7 years ago

Great. Thx.