-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
Support for generating examples in MockResolver for... #1718
Conversation
…ber, integer, bool
…imum/maximum values on integers.
@Ruwann @RobbeSneyders could you review or make any comments? |
connexion/operations/openapi.py
Outdated
except KeyError: | ||
pass | ||
try: | ||
return(generate_example(schema)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return(generate_example(schema)) | |
return generate_example(schema) |
connexion/operations/swagger2.py
Outdated
except KeyError: | ||
pass | ||
try: | ||
return(generate_example(schema)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return(generate_example(schema)) | |
return generate_example(schema) |
@@ -10,6 +10,7 @@ | |||
import pkgutil | |||
import sys | |||
import typing as t | |||
from rstr import xeger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an external dependency that will need to be added to https://github.com/spec-first/connexion/blob/main/pyproject.toml#L46.
It should possibly be optional (like flask
and swagger-ui
).
tests/test_mock2.py
Outdated
from re import fullmatch, Match | ||
|
||
|
||
def test_short_string(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better name would be test_generate_example_string
. And similar below.
tests/test_mock2.py
Outdated
|
||
example = generate_example(schema) | ||
|
||
assert type(fullmatch(pattern, example)) == Match and isinstance(example, str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fullmatch
either returns a Match
object or None. Instead of checking the if the returned type is
Match, it is cleaner to do the inverse and check it is not
None`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I'd tried previously, it didn't work for some reason. It's working now though so I'll correct that.
Thanks @NanuakShadow! 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. |
Closing this based on my comment above. |
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>
…string, number, integer, bool
Fixes # .
Changes proposed in this pull request: