question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An array of enum is not working as expected

See original GitHub issue

Describe 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:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
koxudaxicommented, Nov 21, 2020

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.

0reactions
koxudaxicommented, Nov 25, 2020

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 😣

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found