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

Add a way to use examples by default even when dynamic mode is turned on #2576

Closed
jack-bliss opened this issue Aug 1, 2024 · 1 comment
Closed

Comments

@jack-bliss
Copy link

  • I love prism, and being able to easily mock a server with some examples responses
  • it's also really useful that prism can automatically generate example data dynamically using faker
  • currently, when you have dynamic mode turned on, examples are not used by default
  • i would like a way to get the best of both worlds somehow

Context

  • i use prism to mock a schema from an open-api spec
  • i also use hey-api to automatically generate a typescript client for interacting with the server
  • the typescript client does not know about the Prefer header because this is not part of the real server's schema
  • i could add the Prefer header as a param to the spec, but this would only be for the sake of prism, as the real server does not actually care about this header (which would mean that the spec is actually wrong)
  • i can work around this issue by NOT using the automatically generated typescript client, but this seems a shame

Current Behavior

  • currently, when dynamic mode is turned off, prism will return the first listed example by default
  • any other examples are ignored unless you specifically request them using the Prefer header
  • when dynamic mode is turned on, all examples are ignored unless you use the Prefer header
  • when dynamic mode is turned on, auto-generated responses using faker are created for all endpoints regardless of if examples exist
  • the examples are only returned if you send a Prefer header

Expected Behavior

  • i would like a way to be able to get dynamically generated responses for the endpoints that don't have a Prefer header, and still get the hard-coded examples by default for endpoints that have examples defined
  • i don't want to have set a header that the real API doesn't know about (because then i can't use my automatically generated API client)

Possible Solution(s)

  • could add an extra flag, --use-examples, which only matters when dynamic mode is turned on
  • when this additional flag is set, you get an example by default if one is set
@jack-bliss
Copy link
Author

replaced by #2590

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

1 participant