An array of enum is not working as expected
See original GitHub issueDescribe the bug
It produces a Enumeration with key with None_
prepended and without quotes around the value
Traceback (most recent call last):
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/datamodel_code_generator/__main__.py", line 244, in main
generate(
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/datamodel_code_generator/__init__.py", line 202, in generate
results = parser.parse()
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 354, in parse
body = format_code(body, self.target_python_version)
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/datamodel_code_generator/format.py", line 26, in format_code
code = apply_black(code, python_version)
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/datamodel_code_generator/format.py", line 41, in apply_black
return black.format_str(
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/black.py", line 725, in format_str
src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
File "/Users/tomhemmes/miniconda3/envs/py38/lib/python3.8/site-packages/black.py", line 836, in lib2to3_parse
raise exc from None
black.InvalidInput: Cannot parse: 10:23: None_Item_1 = Item 1
To Reproduce
Example schema:
{
"$id": "item_types.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "item_types",
"description": "JSON Schema for item_types",
"type": "array",
"items": {
"enum": [
"Item 1",
"Item 2",
"Item 3"
]
}
}
Used commandline:
$ datamodel-codegen --input test.json --input-file-type jsonschema --output test.py
Expected behavior A clear and concise description of what you expected to happen
Version:
- OS: macOS Catalina 10.15.4 (19E287)
- Python version: Python 3.8
- datamodel-code-generator version: datamodel-codegen --version 0.6.2
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Array of enums not working as expected · Issue #808 - GitHub
I want to use this with a model property as follows: @ApiProperty({ enum: MyEnum, enumName: 'MyEnum', isArray: true }). This does not render ......
Read more >java enum new list creation is not working as expected
java enum new list creation is not working as expected ; new ArrayList ; for (UserRole userRole: originalList) { boolean ; found =...
Read more >MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column...
Read more >Java Enum Tutorial: 10 Examples of Enum in Java
In this Java Enum tutorial, we will see different Enum example in Java and ... Values() method returns an array of Enum constants...
Read more >How to fix "class, interface, or enum expected" error in Java ...
Since this is a small program, you can easily spot the additional curly brace at the end of the problem but it's very...
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
Thank you for your good suggestion. I agree We should implement an error message. Or, This code-generator has a feature of validation schemas. The error message may recommend using the option.
Thank you for your feedback. I don’t prefer to broke current behavior. The error messages should suggest using the validation option. I don’t want to think about implementing all error patterns 😣