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

Generate examples in MockResolver with JSF library #1870

Closed
wants to merge 0 commits into from

Conversation

mjp4
Copy link
Contributor

@mjp4 mjp4 commented Feb 9, 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"

@mjp4
Copy link
Contributor Author

mjp4 commented Feb 9, 2024

@RobbeSneyders I hope that you will be happy to merge this in based on #1718 (comment)

Let me know if you have any questions or comments.

Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mjp4! This indeed looks like a good way to support example generation.

Comment on lines 215 to 214
try:
return generate_example(schema)
except KeyError:
raise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the generate_example will raise a KeyError. I think we only need to catch ImportErrors here since the dependency is optional?

Same for swagger2.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. I've reworked that code to be a bit nicer.

@RobbeSneyders
Copy link
Member

You'll need to bump the jsonschema version to >=4.17.3 to fix the pipeline.

Can you also add this to the CLI docs?

@RobbeSneyders
Copy link
Member

You'll need to bump typing-extensions to >=4.6.1 as well.

@mjp4 mjp4 closed this Feb 21, 2024
@mjp4 mjp4 mentioned this pull request Feb 21, 2024
RobbeSneyders added a commit that referenced this pull request 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 <robbe.sneyders@gmail.com>
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

Successfully merging this pull request may close these issues.

MockResolver should generate valid example data if no example is provided by the schema.
2 participants