Skip to content
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

Allow providing a seed when using dynamic content generation #2590

Open
jack-bliss opened this issue Aug 13, 2024 · 3 comments
Open

Allow providing a seed when using dynamic content generation #2590

jack-bliss opened this issue Aug 13, 2024 · 3 comments

Comments

@jack-bliss
Copy link

Would be really helpful for tests to be able to get a stable response value

Context

  • i want to use prism for writing tests
  • setting the seed would be really useful for this to get stable values

Current Behavior

  • currently, faker/prism uses randomly generated responses with each request when using dynamic mode

Expected Behavior

  • i want to be able to get stable responses from the server using dynamic mode

Possible Solution(s)

  • accept a header, x-dynamic-seed, that i can set to a constant during testing
@dgellow
Copy link

dgellow commented Aug 16, 2024

We are also interested in providing a seed to control the RNG, our use case is using Prism to mock APIs and run tests for SDKs we generate from an OpenAPI spec.

For our use case, running Prism in CLI mode, we really want a --seed argument to get stable values when --dynamic or --ignoreExamples are being used.

@ilanashapiro
Copy link
Contributor

PR #2594 is up! One thing to note, when you use --ignoreExamples, the results are already deterministic. This is because --ignoreExamples uses json-schema-sampler to statically generate examples, not json-schema-faker, and json-schema-sampler is deterministic (https://github.com/stoplightio/json-schema-sampler).

@dgellow
Copy link

dgellow commented Aug 23, 2024

Awesome @ilanashapiro, thanks for this 🙇. I will do a full review shortly.

@jack-bliss Does that address your use case? Ilana PR adds support for both --seed and the header Prefer="seed=test_seed".

Just to clarify, Stainless did support this effort, but our aim is to ensure the solution benefits the broader community, not just our specific needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants