No Enum generated for underlying type of array
See original GitHub issueIf a field in a component has type array and subtype enum, no enum class is generated for this enum as it is for simple, non-composite enum field.
To Reproduce
Example schema:
"arrayFieldWithEnum": {
"items": {
"enum": [
"enum_value_1",
"enum_value_2",
],
"maxLength": 30,
"minLength": 1,
"pattern": "^.*$",
"type": "string"
},
"maxItems": 3,
"minItems": 1,
"nullable": true,
"type": "array",
"uniqueItems": true,
},
Generated with python:
generate(
input_=Path(schema_path),
output=Path(models_path),
reuse_model=True,
validation=True,
custom_template_dir=Path(templates_path),
disable_timestamp=True,
use_schema_description=True,
)
Expected behavior A separate Enum class is generated for underlying type
Version:
- OS: Ubuntu 18.04
- Python version: 3.7
- datamodel-code-generator version: 0.11.14
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - What's the use-case for specifying the underlying type in ...
The underlying type specifies how much storage is allocated for each enumerator. However, an explicit cast is needed to convert from enum type...
Read more >Enumeration declaration - cppreference.com
1) Declares an unscoped enumeration type whose underlying type is not fixed (in this case, the underlying type is an implementation-defined ...
Read more >EnumBuilder Class (System.Reflection.Emit) | Microsoft Learn
Retrieves an array of the values of the underlying type constants of this enumeration type. (Inherited from Type).
Read more >Use Enumerated Data in Simulink Models - MathWorks
An enumerated data type is a MATLAB ® class that defines a set of enumerated values. Each enumerated value consists of an enumerated...
Read more >Handbook - Enums - TypeScript
Computed and constant members · It is the first member in the enum and it has no initializer, in which case it's assigned...
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
Seems like a bug to me. Ignoring those properties when there’s an enum makes sense to me, but they should be consistently ignored
datamodel-code-generator
seems to ignore themaxLength
/minLength
/pattern
stuff sometimes, but not other times.For example, the following OpenAPI:
Generates the following models:
But just adding
maxItems
causes the enum to be lost: