We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const
required
Describe the bug Generating TypedDict definitions of a schema with const and required yields NotRequired[str].
TypedDict
NotRequired[str]
To Reproduce
Example schema:
{ "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "AndType": { "additionalProperties": false, "description": "...", "properties": { "kind": { "const": "and", "type": "string" } }, "required": [ "kind" ], "type": "object" } } }
Used commandline:
$ datamodel-codegen \ --input ./schema.json \ --output ./schema.py \ --output-model-type "typing.TypedDict" \ --target-python-version "3.11"
Generated code:
# generated by datamodel-codegen: # filename: schema.json # timestamp: 2025-02-09T17:42:53+00:00 from __future__ import annotations from typing import Any, NotRequired, TypedDict Model = Any class AndType(TypedDict): kind: NotRequired[str]
Expected behavior Generate kind: Literal["and"] since it is a required const property.
kind: Literal["and"]
Version:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
Generating
TypedDict
definitions of a schema withconst
andrequired
yieldsNotRequired[str]
.To Reproduce
Example schema:
Used commandline:
Generated code:
Expected behavior
Generate
kind: Literal["and"]
since it is arequired
const
property.Version:
The text was updated successfully, but these errors were encountered: