-
Notifications
You must be signed in to change notification settings - Fork 349
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
feat: add --seed CLI flag for deterministic generation of dynamic examples #2594
Conversation
…o works in Prefer header
Hi @brendarearden! Could we request a review on this from someone on your team? Thank you! |
Hi @ilanashapiro! I am no longer employed here but I think @lukaszzazulak might be able to help you out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks a lot Ilana 👍
@lukaszzazulak Can we do something to help speed up a review of this PR? |
Following up -- could @lukaszm-sb or @lukaszzazulak please help us get a review on this either by you or someone else on the Prism team? Thanks! |
@dgellow Thanks for your commitment here. We are looking into some issues we have with the automation process for deployment for some of the dependencies. As soon as we have some free time we will try to get to reviewing this PR. |
this is awesome, thanks! |
@ilanashapiro sorry for the delay, could you resolve conflicts ? |
89233b7
to
d63f121
Compare
@lukaszzazulak conflicts are resolved! thank you for approving the changes! |
Summary
Addresses issue #2590
We introduce a new CLI flag --seed that the user sets to a string. This string is feed as a seed into json-schema-faker as described in json-schema-faker/json-schema-faker#111, and allows for reproducible dynamic examples, which is useful in testing. The user can also set the seed in the Prefer header.
NOTE: if you are using --ignoreExamples for Prism to statically generate examples conforming to a schema, you do NOT need to use the --seed flag as this will have no effect. --ignoreExamples uses json-schema-sampler to statically generate examples, not json-schema-faker:
prism/packages/http/src/mocker/generator/JSONSchema.ts
Line 107 in 0d12d25
and json-schema-sampler is already deterministic: https://github.com/stoplightio/json-schema-sampler#:~:text=Deterministic%20(given%20a%20particular%20input%2C%20will%20always%20produce%20the%20same%20output).
Checklist
Screenshots
We mock the following .yaml spec:
Mocking with --dynamic and --seed gives us reproducible dynamic responses:
Vs mocking with just --dynamic gives us random/variable dynamic responses:
Finally, if you mock in dynamic mode but without a seed specified, you can still add the seed in the Prefer header. Note how in the following example, the first curl request doesn't add a Prefer header, but the second and third do and specify the same seed, and the second and third responses are identical to one another.