-
-
Notifications
You must be signed in to change notification settings - Fork 227
Optional enum fields are generated with the wrong type #311
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
After further testing, I've realized what makes this break is the
This works fine, however
This also lead me to notice that this problem is not limited to enums, but any nested models where the Although it's not directly related to this library, I noticed this repo is tagged with "FastAPI", so I will also post the workaround I came up with until this is fixed. I added the following to the Config of my Pydantic models and described by their documentation: @staticmethod
def schema_extra(schema: Dict[str, Any]) -> None:
for field_name, field_values in schema.get("properties", {}).items():
if "allOf" not in field_values:
continue
# $ref fiels can't have siblings, so only keeping the $ref
schema["properties"][field_name] = {"$ref": field_values["allOf"][0]["$ref"]} This works for us because we don't have very complex nesting, but assuming "allOf" only has a single field could probably cause issues for more complex cases. |
It does indeed seem to be related to #98. Excellent to hear it's already being worked on. I will close this as a duplicate then. |
Describe the bug
An endpoint which takes a body which has enum fields is being incorrectly generated with the type
Union[Unset, None]
. Of not here is that the enum itself is correctly generated in its own file, but are not used (or even imported) in the model for the wrapping type.To Reproduce
This is a minimal specification I came up with, which reproduces the problem:
We generate the client using simply
openapi-python-client generate
and the specification below, with no additional configuration.The result of this is
Expected behavior
We only just upgraded to the version which uses
Unset
, so I am not quite sure what exactly the type should be, but I assume something along the lines of eitherOptional[MyEnum]
,Union[MyEnum, Unset]
orUnion[Optional[MyEnum], Unset]
OpenAPI Spec File
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: