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

MockResolver should generate valid example data if no example is provided by the schema. #1719

Closed
mjp4 opened this issue Jul 5, 2023 · 1 comment · Fixed by #1891
Closed

Comments

@mjp4
Copy link
Contributor

mjp4 commented Jul 5, 2023

Description

If an OpenAPI spec has examples, then sensible reponses are returned. Including building up nested objects and arrays (as of #1148).

However, if no example field exists, then a default (and invalid) response is returned. This is causing a problem when trying to mock out a third-party schema (that I do not want to modify).

This issue is being resolved in #1718. An earlier attempt to solve the same problem never got merged #513.

Expected behaviour

Server returns some dummy data that matches the schema requirements.

Actual behaviour

Server returns a body of 'No example response was defined.'.

@RobbeSneyders
Copy link
Member

While I agree that generating example responses based on the schema would be useful, I don't want to take on the effort to maintain this in Connexion. This PR implements this logic only for the most simple schema's, which means that we'll get issues for every case where this is not working.

If there is a third-party library that can provide this behavior, I'm happy to integrate it.

Originally posted by @RobbeSneyders in #1718 (comment)

RobbeSneyders added a commit that referenced this issue Mar 20, 2024
Fixes #1719 .

Builds on work of #1718,
pulling in external library to provide the fake data from JSON schema.

Changes proposed in this pull request:

* Use JSF library to generate sample data for mocking APIs without
examples.
* Add this as a new extra dependency "mock"

See discussion on #1870

---------

Co-authored-by: Robbe Sneyders <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants