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
Tuple
#types.py from typing import List, Tuple from pydantic import BaseModel class Model(BaseModel): tuple: Tuple[str, int] list_of_tuples: List[Tuple[str, int]]
pydantic2ts --module ./types.py --output ./types.ts
yields:
//types.ts export interface Model { tuple: [] | [string] | [string, number]; list_of_tuples: [] | [string] | [string, number][]; }
The above Pydantic model should generate this:
export interface Model { tuple: [string, number]; list_of_tuples: [string, number][]; }
python: 3.7.9 pydantic: 1.6 | 1.8.2 pydantic-to-typescript: 1.0.7
The text was updated successfully, but these errors were encountered:
Hi, thanks for finding this. It's a bit of a funky one
It seems that the issue is resolved if the json schema has minItems: 2. If you run your test with this model, it passes
minItems: 2
from typing import List, Tuple from pydantic import BaseModel class Model(BaseModel): tuple: Tuple[str, int] list_of_tuples: List[Tuple[str, int]] class Config: @staticmethod def schema_extra(schema: dict) -> None: """Customize the generated JSON schema via mutation""" schema["properties"]["tuple"]["minItems"] = 2 schema["properties"]["list_of_tuples"]["items"]["minItems"] = 2
However, it appears that they already talked about adding this functionality into pydantic but decided against it: pydantic/pydantic#718
We can certainly implement it ourselves by adding some behavior to the clean_schema function (https://github.com/phillipdupuis/pydantic-to-typescript/blob/master/pydantic2ts/cli/script.py#L114) , just need to take care not to break anything else in doing so
clean_schema
Sorry, something went wrong.
No branches or pull requests
To reproduce:
yields:
Expected
The above Pydantic model should generate this:
Versions:
python: 3.7.9
pydantic: 1.6 | 1.8.2
pydantic-to-typescript: 1.0.7
The text was updated successfully, but these errors were encountered: