[BUG] Python not serializing enums correctly
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have an endpoint that accepts an enum as part of its request body. Whenever I pass Products.allowed_values[('value',)]["TRANSACTIONS"]
as the value I get the failure:
E name.exceptions.ApiTypeError: Invalid type for variable '0'. Required value type is Products and passed type was str at ['initial_products'][0]
Python model serialization fails when type is not Products('transactions')
.
openapi-generator version
OpenAPI declaration file content or url
initial_products:
type: array
items:
$ref: '#/components/schemas/Products'
Products:
title: Products
enum:
- transactions
type: string
Generation Details
docker run --rm -v /mydrive:/local openapitools/openapi-generator-cli:v5.0.0 generate -g python -i local/api.yml -o local/build/generated-python \
-p packageName=name
Steps to reproduce
Pass in Products('transactions')
to the endpoint and get JSON as {value: 'transactions'}
. Should be just 'transactions'
.
Pass in Products.allowed_values[('value',)]["TRANSACTIONS"]
and get the failure mentioned above.
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/7058
Suggest a fix
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (13 by maintainers)
Top Results From Across the Web
Serialising an Enum member to JSON - Stack Overflow
The correct answer depends on what you intend to do with the serialized version. If you are going to unserialize back into Python, ......
Read more >enum.IntEnum is not compatible with JSON serialisation
Serialization isn't the only issue - you have to know how to deserialize as well. I use JSON extensively in Mailman's REST API....
Read more >Python type hinting - circular imports - enum serialization bug
With this class definition, all classes are properly imported, type hints are able to resolve and objects can be created. So it does...
Read more >Stop wasting time with enums in C# | Volare Software
Enums in C# can make you code easier to read: But enums don't cross in and out ... only needed if you serialized...
Read more >TypeScript string enums, and when and how to use them
No matter how much you know about TypeScript enums, this guide covers all ... String enums are serializable over transfer protocols and are ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All merged
Thanks so much for jumping in to fix here @spacether. Will keep an eye on the merge.