prism icon indicating copy to clipboard operation
prism copied to clipboard

Consider falling back to a statically generated response when no example key exists from Prefer header

Open louzena-inshur opened this issue 1 year ago • 2 comments

If you pass a Prefer header with an example key, and that key does not exist, then Prism returns an error

Request terminated with error: https://stoplight.io/prism/errors#NOT_FOUND: The server cannot find the requested content

It would be useful for Prism to fallback to static generation (or dynamic if set) if this happens instead of throwing an error.

Context

We are using Prefer headers to control the examples that we deliver, but don't necessarily need examples for every endpoint. It would be nice to still send the Prefer header key, but fallback to static generation if it doesn't exist

louzena-inshur avatar Sep 07 '23 16:09 louzena-inshur

thanks for the issue @louzena-inshur. we are reluctant to implement this as it could cause unexpected behavior in the case of typos or other bad configuration. we find it important that the client is aware of this mismatch. we would take a PR to improve the response error message (and status code).

daniel-white avatar Sep 08 '23 16:09 daniel-white

Thanks @daniel-white , that makes sense with improving the response error message and that you'd want to be explicit if a keyed example was not found.

Perhaps one to think about - having an argument on the CLI for fallbacks like this. Could fallback to a singular 'example' if it exists, when an argument is set?

louzena-inshur avatar Sep 13 '23 18:09 louzena-inshur

Released in 5.8.2.

lukaszzazulak avatar Jul 02 '24 18:07 lukaszzazulak