repocho / raml-mocker

Node module to create random responses to requests based on RAML rest definition.
MIT License
93 stars 33 forks source link

Add ability to render "example" if it's available for json response #9

Closed dmitrisweb closed 9 years ago

dmitrisweb commented 9 years ago

Hello,

Prehistory: We are using RAML format for documentation and we use to have separate service which was implementing same API for demo purposes. But it become kind of bottleneck for front-end developers to mock new data since it involves back-end part to be in place.

After that we started using services like https://anypoint.mulesoft.com and http://apiary.io/ to rapidly mock new APIs and responses.

That approach was not very handy for standalone development and collaboration. It would be much better to keep all RAML files under the source control and run mock server locally with no dependencies on the real backend and 3rd party services.

After some research I found your module which works perfectly with schemas, but unfortunately does not support rendering of the "example" output.

With few modifications it become possible to use your module for that.

Can you please review and possible release a new npm version for this update, so we can all switch to this version.

Thank you!

dmitrisweb commented 9 years ago

@RePoChO Hey David,

Did you had a chance to review the change? I would like to start using new version of your module with change I made. Do you have any objections to apply this merge? did you had chance to review the change? I would like to start using new version of your module with change I made. Do you have any objections to apply this merge?

repocho commented 9 years ago

Hi @dmitrisweb !!

Sorry about the delay... my apologizes !

I'm going to review your changes. My first issue about the changes is that I don't like to give more priority to examples than the json schemas because I think is more interesting to test against random mocks than statics examples if both are defined.

I'm going to try to add this functionallity to the generation part, like if you want to use other codes.

Thanks

repocho commented 9 years ago

Hi @dmitrisweb !

finally I changed the way you manage the examples. You can use the examples calling to example() instead of mock() function.

        var mock = m.mock();
        if (mock) {
            console.log(mock);
        }
        var example = m.example();
        if (example) {
            console.log(example);
        }

Look at the full example to see how it works.

Thanks for your help.

dmitrisweb commented 9 years ago

Thank you! In the last commit I made it optional, so it possible to pass a function to the mock function which will transform response

dmitrisweb commented 9 years ago

good, even better!

repocho commented 9 years ago

I've just realeased the new version to npm so you can try it with this new approach.

Thanks again @dmitrisweb !