Skip to content

Pydantic models generation#29

Merged
bogdandm merged 14 commits intomasterfrom
pydantic
May 10, 2020
Merged

Pydantic models generation#29
bogdandm merged 14 commits intomasterfrom
pydantic

Conversation

@bogdandm
Copy link
Copy Markdown
Owner

@bogdandm bogdandm commented May 3, 2020

Add pydantic converter:

json2models -f pydantic ...

Example (testing_tools/real_apis/f1.py):

from datetime import date
from pydantic import BaseModel, Field
from typing import List
from typing_extensions import Literal


class DriverStandings(BaseModel):
    season: int
    round_: int = Field(..., alias="round")
    DriverStandings: List['DriverStanding']


class DriverStanding(BaseModel):
    position: int
    position_text: int = Field(..., alias="positionText")
    points: int
    wins: int
    driver: 'Driver' = Field(..., alias="Driver")
    constructors: List['Constructor'] = Field(..., alias="Constructors")


class Driver(BaseModel):
    driver_id: str = Field(..., alias="driverId")
    permanent_number: int = Field(..., alias="permanentNumber")
    code: str
    url: str
    given_name: str = Field(..., alias="givenName")
    family_name: str = Field(..., alias="familyName")
    date_of_birth: date = Field(..., alias="dateOfBirth")
    nationality: str


class Constructor(BaseModel):
    constructor_id: str = Field(..., alias="constructorId")
    url: str
    name: str
    nationality: Literal["American", "Austrian", "British", "French", "German", "Italian"]

@coveralls
Copy link
Copy Markdown

coveralls commented May 3, 2020

Coverage Status

Coverage increased (+0.008%) to 98.503% when pulling 0eb0fe1 on pydantic into a3fcbec on master.

@bogdandm bogdandm changed the title Pydantic Pydantic models generation May 3, 2020
@bogdandm
Copy link
Copy Markdown
Owner Author

bogdandm commented May 4, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 5
           

Complexity increasing per file
==============================
- json_to_models/dynamic_typing/complex.py  4
- json_to_models/models/string_converters.py  1
- json_to_models/models/pydantic.py  8
         

Complexity decreasing per file
==============================
+ json_to_models/cli.py  -1
         

Clones added
============
- json_to_models/dynamic_typing/complex.py  7
         

See the complete overview on Codacy

bogdandm added 8 commits May 4, 2020 18:47
* Add types_styles parameter

* Pydantic: rewrite string_serializable replace with actual types using types_style

* Integrate StringLiteral into core

* Pydantic: Implement StringLiteral logic

* Use StringLiteral for base generator and dataclass generator

* Add --max-strings-literals CLI arg

* Add test for type styles and string literals
Repository owner deleted a comment from coveralls May 4, 2020
@bogdandm bogdandm marked this pull request as ready for review May 10, 2020 15:25
@bogdandm bogdandm merged commit b090449 into master May 10, 2020
@bogdandm bogdandm deleted the pydantic branch May 10, 2020 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants