-
-
Notifications
You must be signed in to change notification settings - Fork 229
Allow location-based parameters to create/update functions to be Optional #535
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
Comments
I assume this is related to #453 in that there are 3 different locations for the same data, but the data itself is required. In order to have the types properly reflect the API's expected inputs, this probably needs to be a single required input which takes the location as part of it. Something like: def sync(
id: int,
*,
client: AuthenticatedClient,
body: Body[T],
) -> Optional[T]:
... where our from typing import Generic, TypeVar
T = TypeVar("T")
Location = TypeVar("Location") // This will have to be set to a union of possible locations
@attr.s(auto_attribs=True)
class Body(Generic[T], Generic[Location]):
"""A response from an endpoint"""
location: Location
data: T Either that or we'd have to generate multiple versions of Either way will get messy and we'll only want to do it in the special case where there are multiple ways to pass the same data. Another problem is it's possible for someone to accept two payloads of the same type but from different locations at the same time. In which case, they wouldn't want the "choose one" behavior. I'm not sure how the generator could know the difference. |
Yes, this seems reasonable. Also thank you for linking #453, I am also using Location = TypeVar("Location") // This will have to be set to a union of possible locations I like the C/Rust/Javascript style comment 😆 |
SPECTACULAR_SETTINGS = {
"PARSER_WHITELIST": ["rest_framework.parsers.JSONParser"],
} |
Gonna just track this in #453 since I think they are duplicates |
Is your feature request related to a problem? Please describe.
In generated
*partial_update.py
modules, the type signature is:This makes all of the arguments required, and means you have to call it with dummy parameters like:
Describe the solution you'd like
It seems like if the user only wants to provide data for one of the types of request data, such as
form_data
they should not have to pass the others and the function would look like:And could call it like:
The text was updated successfully, but these errors were encountered: