File: combine_any_of_object_v2.py

package info (click to toggle)
python-datamodel-code-generator 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,052 kB
  • sloc: python: 29,621; makefile: 15
file content (49 lines) | stat: -rw-r--r-- 1,114 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# generated by datamodel-codegen:
#   filename:  combine_any_of_object.json
#   timestamp: 2019-07-26T00:00:00+00:00

from __future__ import annotations

from typing import Optional, Union

from pydantic import BaseModel, ConfigDict, Field, RootModel


class MySchema1(BaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    AddressLine1: str
    AddressLine2: Optional[str] = None
    City: Optional[str] = None
    State: Optional[str] = None
    ZipCode: str


class MySchema2(BaseModel):
    model_config = ConfigDict(
        extra='allow',
    )
    AddressLine1: str
    AddressLine2: Optional[str] = None
    City: Optional[str] = None
    County: Optional[str] = None
    PostCode: str


class US(BaseModel):
    County: Optional[str] = None
    PostCode: str


class MySchema3(US):
    model_config = ConfigDict(
        extra='allow',
    )
    AddressLine1: str
    AddressLine2: Optional[str] = None
    City: Optional[str] = None


class MySchema(RootModel[Union[MySchema1, MySchema2, MySchema3]]):
    root: Union[MySchema1, MySchema2, MySchema3] = Field(..., title='My schema')