When generating models from JSON Schema it would be nice to be able to generate Tuple[]
types using Tuple Validation.
Consider the following schema:
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"a": {
"type": "array",
"prefixItems": [
{ "type": "number" },
{ "type": "string" }
],
"minItems": 2,
"maxItems": 2
}
},
"required": ["a"]
}
Running datamodel-codegen --input test.json --input-file-type jsonschema --output-model-type typing.TypedDict --output model.py
, this produces the output:
from __future__ import annotations
from typing import List
from typing_extensions import TypedDict
class Model(TypedDict):
a: List
Ideally, it would produce the following instead:
from __future__ import annotations
from typing import Tuple
from typing_extensions import TypedDict
class Model(TypedDict):
a: Tuple[float, str]
The only real alternative to typing an array with heterogenous types is to replace the array with an object whose properties
can be typed individually. But changing a schema to use an object instead of an array isn't always possible.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too