-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
Enable enforcing defaults #1616
Conversation
a477bba
to
f4f4858
Compare
I updated the PR with a solution that I think is a good middle ground. The standard I would have liked connexion to have an |
@@ -63,7 +63,8 @@ def fn(self) -> t.Callable: | |||
async def __call__( | |||
self, scope: Scope, receive: Receive, send: Send | |||
) -> StarletteResponse: | |||
return await self.fn(scope=scope, receive=receive, send=send) |
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.
Just a fix to get the AsyncApp
working correctly. Not related to enforcing defaults, but necessary to make the example work.
def __init__(self) -> None: | ||
self.apis: t.Dict[str, AsyncApi] = {} | ||
self.operations: t.Dict[str, AsyncOperation] = {} | ||
self.router = Router() | ||
super().__init__(self.router) | ||
|
||
def add_api(self, *args, **kwargs): | ||
api = AsyncApi(*args, **kwargs) | ||
self.apis[api.base_path] = api | ||
api = super().add_api(*args, **kwargs) |
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.
Just a fix to get the AsyncApp
working correctly. Not related to enforcing defaults, but necessary to make the example work.
while asyncio.iscoroutine(response): | ||
response = await response | ||
return response | ||
return await decorated_function(request) |
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.
Just a fix to get the AsyncApp
working correctly. Not related to enforcing defaults, but necessary to make the example work.
api = self.api_cls(specification, next_app=self.app, **kwargs) | ||
self.apis[api.base_path] = api | ||
return api |
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.
Just a fix to get the AsyncApp
working correctly. Not related to enforcing defaults, but necessary to make the example work.
@@ -62,10 +62,10 @@ paths: | |||
'201': | |||
description: New pet created | |||
requestBody: | |||
x-body-name: pet |
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.
Unrelated fix
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 agree that the proposed validator is a good middleground :)
Perhaps also good to put this in the updated documentation, as it might otherwise be hard to find
:return: A tuple (body, max_length) where max_length is the length of the larges message. | ||
""" | ||
more_body = True | ||
max_length = 256000 |
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.
Where does this number come from? I'm not aware of an ASGI limit
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 not constrained by ASGI, but by the server. I ran some tests with Uvicorn and this was the upper limit, although I couldn't find where this limit is defined.
connexion/validators/json.py
Outdated
async def read_body(self) -> t.Tuple[str, int]: | ||
"""Read the body from the receive channel. | ||
|
||
:return: A tuple (body, max_length) where max_length is the length of the larges message. |
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.
typo: largest
f4f4858
to
b64d494
Compare
Pull Request Test Coverage Report for Build 4015715852
💛 - Coveralls |
Pull Request Test Coverage Report for Build 4015715852
💛 - Coveralls |
This PR is a proposal to enforce defaults in json bodies.
I'm not sure which way to go here
default
flag instead of the custom validator now needed.If we do want to go this way, we should probably implement a similar fix for form data, as we also use json validators there.