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

Mock response didn't return the expected example data #84

Closed
TristanSpeakEasy opened this issue Jan 14, 2024 · 3 comments
Closed

Mock response didn't return the expected example data #84

TristanSpeakEasy opened this issue Jan 14, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@TristanSpeakEasy
Copy link

This may be a bad assumption on my part but I would expect (or want) the responses returned by wiretap in mock mode to use the provided examples if in the spec and only provide truly mocked responses (ie generating responses based on the schema) if there were no provided examples.

If this isn't the intended behavior or my assumption was wrong would be good if it could be configured to react this way?

@TristanSpeakEasy
Copy link
Author

So this is likely to be a feature request I imagine.

It would be great to have a feature flag that determines whether fully mocked or partially mocked data is returned.

So in fully mocked mode it returns random generated data and in partial mode it returns any examples defined in the openapi documentation, just filling in the missing examples with generated data.

Another configuration might also be to determine how the defined examples are returned, do you round robin return the examples if there are multiple of them provided, or deterministically return only the first examples in the list (with an exception for arrays etc)

@daveshanley daveshanley added the enhancement New feature or request label Jan 19, 2024
@daveshanley daveshanley added bug Something isn't working and removed enhancement New feature or request labels Jan 27, 2024
@daveshanley
Copy link
Member

daveshanley commented Jan 27, 2024

This is actually a bug, it should always flow from object examples, to schema examples and then to inline example values within schemas and then generated values.

The last hope is generated values, the first choice should always be provided examples, then drop down to examples within in schema, then example then last hope.

daveshanley added a commit to pb33f/libopenapi that referenced this issue Jan 27, 2024
reported in pb33f/wiretap#84

Signed-off-by: quobix <dave@quobix.com>
@daveshanley daveshanley mentioned this issue Jan 27, 2024
daveshanley added a commit to pb33f/libopenapi that referenced this issue Jan 27, 2024
reported in pb33f/wiretap#84

Signed-off-by: quobix <dave@quobix.com>
@daveshanley
Copy link
Member

This should be resolved in v0.1.1

The default behavior is:

Look for Examples first, pick the first named example it finds (if using labels) or the first item in the index (if using an index). This choice can be overridden by using the Preferred header, using the label name, or the index value.

If there are no Examples then the Example value is used.

If there is no Example value, then the mock engine attempts to generate a value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants