File: use_annotated_with_field_constraints.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 (88 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# generated by datamodel-codegen:
#   filename:  api_constrained.yaml
#   timestamp: 2019-07-26T00:00:00+00:00

from __future__ import annotations

from typing import Annotated, List, Optional, Union

from pydantic import AnyUrl, BaseModel, Field


class Pet(BaseModel):
    id: Annotated[int, Field(ge=0, le=9223372036854775807)]
    name: Annotated[str, Field(max_length=256)]
    tag: Annotated[Optional[str], Field(max_length=64)] = None


class Pets(BaseModel):
    __root__: Annotated[List[Pet], Field(max_items=10, min_items=1, unique_items=True)]


class UID(BaseModel):
    __root__: Annotated[int, Field(ge=0)]


class Phone(BaseModel):
    __root__: Annotated[str, Field(min_length=3)]


class FaxItem(BaseModel):
    __root__: Annotated[str, Field(min_length=3)]


class User(BaseModel):
    id: Annotated[int, Field(ge=0)]
    name: Annotated[str, Field(max_length=256)]
    tag: Annotated[Optional[str], Field(max_length=64)] = None
    uid: UID
    phones: Annotated[Optional[List[Phone]], Field(max_items=10)] = None
    fax: Optional[List[FaxItem]] = None
    height: Annotated[Optional[Union[int, float]], Field(ge=1.0, le=300.0)] = None
    weight: Annotated[Optional[Union[float, int]], Field(ge=1.0, le=1000.0)] = None
    age: Annotated[Optional[int], Field(gt=0, le=200)] = None
    rating: Annotated[Optional[float], Field(gt=0.0, le=5.0)] = None


class Users(BaseModel):
    __root__: List[User]


class Id(BaseModel):
    __root__: str


class Rules(BaseModel):
    __root__: List[str]


class Error(BaseModel):
    code: int
    message: str


class Api(BaseModel):
    apiKey: Annotated[
        Optional[str], Field(description='To be used as a dataset parameter value')
    ] = None
    apiVersionNumber: Annotated[
        Optional[str], Field(description='To be used as a version parameter value')
    ] = None
    apiUrl: Annotated[
        Optional[AnyUrl], Field(description="The URL describing the dataset's fields")
    ] = None
    apiDocumentationUrl: Annotated[
        Optional[AnyUrl], Field(description='A URL to the API console for each API')
    ] = None


class Apis(BaseModel):
    __root__: List[Api]


class Event(BaseModel):
    name: Optional[str] = None


class Result(BaseModel):
    event: Optional[Event] = None