-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocumentspec_union.py
More file actions
168 lines (125 loc) · 4.84 KB
/
documentspec_union.py
File metadata and controls
168 lines (125 loc) · 4.84 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from glean.api_client import models, utils
from glean.api_client.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
class DocumentSpecUgcType2(str, Enum, metaclass=utils.OpenEnumMeta):
r"""The type of the user generated content (UGC datasource)."""
ANNOUNCEMENTS = "ANNOUNCEMENTS"
ANSWERS = "ANSWERS"
ARTIFACTS = "ARTIFACTS"
COLLECTIONS = "COLLECTIONS"
SHORTCUTS = "SHORTCUTS"
CHATS = "CHATS"
class DocumentSpec4TypedDict(TypedDict):
ugc_type: DocumentSpecUgcType2
r"""The type of the user generated content (UGC datasource)."""
ugc_id: str
r"""The string id for user generated content. Used for CHATS."""
doc_type: NotRequired[str]
r"""The specific type of the user generated content type."""
class DocumentSpec4(BaseModel):
ugc_type: Annotated[DocumentSpecUgcType2, pydantic.Field(alias="ugcType")]
r"""The type of the user generated content (UGC datasource)."""
ugc_id: Annotated[str, pydantic.Field(alias="ugcId")]
r"""The string id for user generated content. Used for CHATS."""
doc_type: Annotated[Optional[str], pydantic.Field(alias="docType")] = None
r"""The specific type of the user generated content type."""
@field_serializer("ugc_type")
def serialize_ugc_type(self, value):
if isinstance(value, str):
try:
return models.DocumentSpecUgcType2(value)
except ValueError:
return value
return value
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["docType"])
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))
if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val
return m
class DocumentSpecUgcType1(str, Enum, metaclass=utils.OpenEnumMeta):
r"""The type of the user generated content (UGC datasource)."""
ANNOUNCEMENTS = "ANNOUNCEMENTS"
ANSWERS = "ANSWERS"
COLLECTIONS = "COLLECTIONS"
SHORTCUTS = "SHORTCUTS"
CHATS = "CHATS"
class DocumentSpec3TypedDict(TypedDict):
ugc_type: DocumentSpecUgcType1
r"""The type of the user generated content (UGC datasource)."""
content_id: int
r"""The numeric id for user generated content. Used for ANNOUNCEMENTS, ANSWERS, COLLECTIONS, SHORTCUTS."""
doc_type: NotRequired[str]
r"""The specific type of the user generated content type."""
class DocumentSpec3(BaseModel):
ugc_type: Annotated[DocumentSpecUgcType1, pydantic.Field(alias="ugcType")]
r"""The type of the user generated content (UGC datasource)."""
content_id: Annotated[int, pydantic.Field(alias="contentId")]
r"""The numeric id for user generated content. Used for ANNOUNCEMENTS, ANSWERS, COLLECTIONS, SHORTCUTS."""
doc_type: Annotated[Optional[str], pydantic.Field(alias="docType")] = None
r"""The specific type of the user generated content type."""
@field_serializer("ugc_type")
def serialize_ugc_type(self, value):
if isinstance(value, str):
try:
return models.DocumentSpecUgcType1(value)
except ValueError:
return value
return value
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(["docType"])
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k, serialized.get(n))
if val != UNSET_SENTINEL:
if val is not None or k not in optional_fields:
m[k] = val
return m
class DocumentSpec2TypedDict(TypedDict):
id: str
r"""The ID of the document."""
class DocumentSpec2(BaseModel):
id: str
r"""The ID of the document."""
class DocumentSpec1TypedDict(TypedDict):
url: str
r"""The URL of the document."""
class DocumentSpec1(BaseModel):
url: str
r"""The URL of the document."""
DocumentSpecUnionTypedDict = TypeAliasType(
"DocumentSpecUnionTypedDict",
Union[
DocumentSpec1TypedDict,
DocumentSpec2TypedDict,
DocumentSpec3TypedDict,
DocumentSpec4TypedDict,
],
)
DocumentSpecUnion = TypeAliasType(
"DocumentSpecUnion",
Union[DocumentSpec1, DocumentSpec2, DocumentSpec3, DocumentSpec4],
)
try:
DocumentSpec4.model_rebuild()
except NameError:
pass
try:
DocumentSpec3.model_rebuild()
except NameError:
pass