Missing support for "const" keyword
See original GitHub issueDescribe the bug
OpenAPI 3 references JSONSchema 2019-09 (since https://github.com/OAI/OpenAPI-Specification/pull/1977), which includes support for the const
keyword. The const
keyword is for defining constant value properties in schemas.
To Reproduce
Example schema (this is part of an OpenAPI specification):
{
"components": {
"schemas": {
"Namespace": {
"type": "object",
"required": [
"apiVersion",
"kind"
],
"properties": {
"apiVersion": {
"const": "v1"
},
"kind": {
"const": "Namespace"
},
"metadata": {
"$ref": "#/compoments/schemas/ObjectMeta"
}
}
}
}
}
}
Used commandline:
$ datamodel-codegen --input openapi.json --input-file-type openapi --output models.py
Expected behavior
I expected the generated model to look something like this:
class Namespace
apiVersion: str = "v1"
kind: str = "Namespace"
metadata: ObjectMeta
But what the cli currently generates is:
class Namespace:
apiVersion: Any
kind: Any
metadata: ObjectMeta
Version:
- OS: Fedora 35
- Python version: 3.10.0
- datamodel-code-generator version: 0.11.15
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
SyntaxError: missing = in const declaration - JavaScript | MDN
The JavaScript exception "missing = in const declaration" occurs when a const declaration was not given a value in the same statement (like ......
Read more >Suggestion: Support ES6 'let' and 'const' keyword #19 - GitHub
Personally I like the idea of having const and readonly as an option. It may make things more complicated, but I like that...
Read more >C++ const correctness / missing const constructor for class ...
To me it looks like I need to have a constructor for creating a const object, which isn't available in C++. So I...
Read more >SyntaxError: missing = in const declaration - JavaScript
The JavaScript exception "missing = in const declaration" occurs when a const declaration was not given a value in the same statement (like...
Read more >What is the 'const' Keyword in JavaScript? | by Mayank Gupta
The const keyword represents a constant value ... In the below example, we have created a variable “userName” which is a constant variable....
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
@larsks I’m sorry for my late reply. Thank you for sharing the feature. I will add the feature to the cli.
Is there any progress for the implementation of the “const” keyword?