Title: Optional enum fields are generated with the wrong type · Issue #311 · openapi-generators/openapi-python-client · GitHub
Open Graph Title: Optional enum fields are generated with the wrong type · Issue #311 · openapi-generators/openapi-python-client
X Title: Optional enum fields are generated with the wrong type · Issue #311 · openapi-generators/openapi-python-client
Description: 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 ...
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/openapi-generators/openapi-python-client/issues/311
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optional enum fields are generated with the wrong type","articleBody":"**Describe the bug**\r\nAn 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.\r\n\r\n**To Reproduce**\r\nThis is a minimal specification I came up with, which reproduces the problem:\r\n\r\nWe generate the client using simply `openapi-python-client generate` and the specification below, with no additional configuration.\r\n\r\nThe result of this is\r\n```Python\r\n@attr.s(auto_attribs=True)\r\nclass EnumWrapper:\r\n \"\"\" \"\"\"\r\n\r\n myenum: Union[Unset, None] = UNSET\r\n additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)\r\n\r\n def to_dict(self) -\u003e Dict[str, Any]:\r\n myenum = None\r\n\r\n field_dict: Dict[str, Any] = {}\r\n field_dict.update(self.additional_properties)\r\n field_dict.update({})\r\n if myenum is not UNSET:\r\n field_dict[\"myenum\"] = myenum\r\n\r\n return field_dict\r\n\r\n @staticmethod\r\n def from_dict(src_dict: Dict[str, Any]) -\u003e \"EnumWrapper\":\r\n d = src_dict.copy()\r\n myenum = None\r\n\r\n enum_wrapper = EnumWrapper(\r\n myenum=myenum,\r\n )\r\n\r\n enum_wrapper.additional_properties = d\r\n return enum_wrapper\r\n\r\n # Rest of the file omitted for brevity\r\n```\r\n**Expected behavior**\r\nWe 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 either `Optional[MyEnum]`, `Union[MyEnum, Unset]` or `Union[Optional[MyEnum], Unset]`\r\n\r\n**OpenAPI Spec File**\r\n```yaml\r\nopenapi: 3.0.2\r\ninfo:\r\n title: bar\r\n version: unknown\r\npaths:\r\n /foo:\r\n post:\r\n requestBody:\r\n content:\r\n application/json:\r\n schema:\r\n $ref: '#/components/schemas/EnumWrapper'\r\n required: true\r\n responses:\r\n '204':\r\n description: Successful Response\r\ncomponents:\r\n schemas:\r\n MyEnum:\r\n title: MyEnum\r\n enum:\r\n - TypeA\r\n - TypeB\r\n type: string\r\n description: An enumeration.\r\n EnumWrapper:\r\n title: EnumWrapper\r\n type: object\r\n properties:\r\n myenum:\r\n allOf:\r\n - $ref: '#/components/schemas/MyEnum'\r\n\r\n```\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: [Ubuntu 20.04]\r\n - Python Version: 3.7.9\r\n - openapi-python-client version: 0.7.3","author":{"url":"https://github.com/frjonsen","@type":"Person","name":"frjonsen"},"datePublished":"2021-01-22T13:36:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/311/openapi-python-client/issues/311"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:32576896-1f88-7af3-1b49-b8d2b1b017af |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C396:2DC2B9:9C5AC1:D4CF2B:698121B9 |
| html-safe-nonce | ee8afdda4b2feacac4205967db43d8a8f1fa5736d5d53f5474ac8d754e3d0f38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzk2OjJEQzJCOTo5QzVBQzE6RDRDRjJCOjY5ODEyMUI5IiwidmlzaXRvcl9pZCI6IjYwNjc0Mzg5NDI5MjY0Nzk4MDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aa6fa7632b4c9ccd45e78fcd8c9e01e53cda025b200b36677aaf09aa500fee3e |
| hovercard-subject-tag | issue:792010519 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openapi-generators/openapi-python-client/311/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8577dd13e462bd53aa25449d4718473f5610165758b97f97ce0e2940fbb9ccba/openapi-generators/openapi-python-client/issues/311 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8577dd13e462bd53aa25449d4718473f5610165758b97f97ce0e2940fbb9ccba/openapi-generators/openapi-python-client/issues/311 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | frjonsen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 39fe8101494cbb823c09b619b68c80cd4d05ab7279997038dbe06bb91608abe1 |
| turbo-cache-control | no-preview |
| go-import | github.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git |
| octolytics-dimension-user_id | 84925606 |
| octolytics-dimension-user_login | openapi-generators |
| octolytics-dimension-repository_id | 240776275 |
| octolytics-dimension-repository_nwo | openapi-generators/openapi-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 240776275 |
| octolytics-dimension-repository_network_root_nwo | openapi-generators/openapi-python-client |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d5b34a4e4898b066c629879feb4b184bc471d6a7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width