-
Notifications
You must be signed in to change notification settings - Fork 80
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
Allow "anyOf" in param["schema"]["type"] in openapi31 #143
Allow "anyOf" in param["schema"]["type"] in openapi31 #143
Conversation
This looks pretty good. If you can add a unit test for this functionality, I'll be happy to merge it and cut a release. |
Thanks for enabling the tests :)
|
Signed-off-by: Stephen Finucane <[email protected]>
c056043
to
83d8448
Compare
I pushed a test for you. It's currently failing which unless I've done something obviously wrong would suggest you've a bit more work to do here? |
Thanks a lot :) testrenderer = <sphinxcontrib.openapi.renderers._httpdomain.HttpdomainRenderer object at 0x7fa948dd5ff0>
testspec = {'info': {'title': 'Reproducer for issue #112', 'version': '2.0.0'}, 'openapi': '3.1.0', 'paths': {'/users': {'get': {...ath', 'name': 'userID', 'schema': {...}}], 'responses': {'200': {'content': {...}}}, 'summary': 'Get a user by ID.'}}}}
rendered = PosixPath('/home/runner/work/openapi/openapi/tests/renderers/httpdomain/rendered')
def test_render(testrenderer, testspec, rendered):
testspec_name, testspec = testspec
> rendered_markup = "\n".join(testrenderer.render_restructuredtext_markup(testspec))
tests/renderers/httpdomain/test_render.py:23:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
sphinxcontrib/openapi/renderers/_httpdomain.py:239: in render_restructuredtext_markup
yield from self.render_paths(spec.get("paths", {}))
sphinxcontrib/openapi/renderers/_httpdomain.py:268: in render_paths
yield from self.render_operation(endpoint, method, operation)
sphinxcontrib/openapi/renderers/_httpdomain.py:295: in render_operation
yield from indented(self.render_responses(operation["responses"]))
sphinxcontrib/openapi/renderers/_httpdomain.py:28: in indented
for item in generator:
sphinxcontrib/openapi/renderers/_httpdomain.py:399: in render_responses
yield from self.render_response(str(status_code), response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <sphinxcontrib.openapi.renderers._httpdomain.HttpdomainRenderer object at 0x7fa948dd5ff0>
status_code = '200'
response = {'content': {'application/json': {'schema': {'items': {'properties': {'deleted': {...}, 'id': {...}, 'username': {...}}, 'type': 'object'}, 'type': 'array'}}}}
def render_response(self, status_code, response):
"""Render OAS operation's response."""
yield f":statuscode {status_code}:"
yield from indented(
> self._convert_markup(response["description"]).strip().splitlines()
)
E KeyError: 'description'
sphinxcontrib/openapi/renderers/_httpdomain.py:406: KeyError It seems like |
The latest test failure was caused by the function One more note: on my local system, I use ruff for linting and code style checks, and it was applied to |
Thanks for running again! Could you please fix the end of the file |
Signed-off-by: Stephen Finucane <[email protected]>
This should be part of 0.8.2. Thanks for the quick turnaround on my review feedback 👍 |
Thank you for your time here, looking forward to the new release :) |
As hinted at in #112, our project is currently changing from pydantic v1 to v2. This means that type hints like
<type> | None
have become necessary due to pydantic's v2 changes away from implicit default values, at least as far as I can see. For a field to be optional, a default value of the corresponding type orNone
has to be provided now, even if the type of the field isOptional[<type>]
. This means a lot of defaultNone
values have been set by adapting to pydantic v2, which need to be accommodated by our endpoints' expected input and response models. Therefore, ourdocs/openapi-v1.json
entries now look similar to this:Since we are using version 3.1.0 of openapi, this leads to the following error:
This PR aims to remedy this issue by taking
type
if it's present inschema
or the set of types present inanyOf
otherwise. The fix is taking pretty directly from #113.