|
16 | 16 | import typing |
17 | 17 |
|
18 | 18 | from cloudevents.exceptions import PydanticFeatureNotInstalled |
| 19 | +from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS |
19 | 20 |
|
20 | 21 | try: |
21 | 22 | from pydantic import VERSION as PYDANTIC_VERSION |
@@ -72,7 +73,7 @@ def _ce_json_dumps( # type: ignore[no-untyped-def] |
72 | 73 | def _ce_json_loads( # type: ignore[no-untyped-def] |
73 | 74 | data: typing.AnyStr, *args, **kwargs # noqa |
74 | 75 | ) -> typing.Dict[typing.Any, typing.Any]: |
75 | | - """Perforns Pydantic-specific deserialization of the event. |
| 76 | + """Performs Pydantic-specific deserialization of the event. |
76 | 77 |
|
77 | 78 | Needed by the pydantic base-model to de-serialize the event correctly from json. |
78 | 79 | Without this function the data will be incorrectly de-serialized. |
@@ -104,125 +105,52 @@ def create( |
104 | 105 | return cls(attributes, data) |
105 | 106 |
|
106 | 107 | data: typing.Optional[typing.Any] = Field( |
107 | | - title="Event Data", |
108 | | - description=( |
109 | | - "CloudEvents MAY include domain-specific information about the occurrence." |
110 | | - " When present, this information will be encapsulated within data.It is" |
111 | | - " encoded into a media format which is specified by the datacontenttype" |
112 | | - " attribute (e.g. application/json), and adheres to the dataschema format" |
113 | | - " when those respective attributes are present." |
114 | | - ), |
| 108 | + title=FIELD_DESCRIPTIONS["data"].get("title"), |
| 109 | + description=FIELD_DESCRIPTIONS["data"].get("description"), |
| 110 | + example=FIELD_DESCRIPTIONS["data"].get("example"), |
115 | 111 | ) |
116 | 112 | source: str = Field( |
117 | | - title="Event Source", |
118 | | - description=( |
119 | | - "Identifies the context in which an event happened. Often this will include" |
120 | | - " information such as the type of the event source, the organization" |
121 | | - " publishing the event or the process that produced the event. The exact" |
122 | | - " syntax and semantics behind the data encoded in the URI is defined by the" |
123 | | - " event producer.\n" |
124 | | - "\n" |
125 | | - "Producers MUST ensure that source + id is unique for" |
126 | | - " each distinct event.\n" |
127 | | - "\n" |
128 | | - "An application MAY assign a unique source to each" |
129 | | - " distinct producer, which makes it easy to produce unique IDs since no" |
130 | | - " other producer will have the same source. The application MAY use UUIDs," |
131 | | - " URNs, DNS authorities or an application-specific scheme to create unique" |
132 | | - " source identifiers.\n" |
133 | | - "\n" |
134 | | - "A source MAY include more than one producer. In" |
135 | | - " that case the producers MUST collaborate to ensure that source + id is" |
136 | | - " unique for each distinct event." |
137 | | - ), |
138 | | - example="https://github.com/cloudevents", |
| 113 | + title=FIELD_DESCRIPTIONS["source"].get("title"), |
| 114 | + description=FIELD_DESCRIPTIONS["source"].get("description"), |
| 115 | + example=FIELD_DESCRIPTIONS["source"].get("example"), |
139 | 116 | ) |
140 | | - |
141 | 117 | id: str = Field( |
| 118 | + title=FIELD_DESCRIPTIONS["id"].get("title"), |
| 119 | + description=FIELD_DESCRIPTIONS["id"].get("description"), |
| 120 | + example=FIELD_DESCRIPTIONS["id"].get("example"), |
142 | 121 | default_factory=attribute.default_id_selection_algorithm, |
143 | | - title="Event ID", |
144 | | - description=( |
145 | | - "Identifies the event. Producers MUST ensure that source + id is unique for" |
146 | | - " each distinct event. If a duplicate event is re-sent (e.g. due to a" |
147 | | - " network error) it MAY have the same id. Consumers MAY assume that Events" |
148 | | - " with identical source and id are duplicates. MUST be unique within the" |
149 | | - " scope of the producer" |
150 | | - ), |
151 | | - example="A234-1234-1234", |
152 | 122 | ) |
153 | 123 | type: str = Field( |
154 | | - title="Event Type", |
155 | | - description=( |
156 | | - "This attribute contains a value describing the type of event related to" |
157 | | - " the originating occurrence. Often this attribute is used for routing," |
158 | | - " observability, policy enforcement, etc. The format of this is producer" |
159 | | - " defined and might include information such as the version of the type" |
160 | | - ), |
161 | | - example="com.github.pull_request.opened", |
| 124 | + title=FIELD_DESCRIPTIONS["type"].get("title"), |
| 125 | + description=FIELD_DESCRIPTIONS["type"].get("description"), |
| 126 | + example=FIELD_DESCRIPTIONS["type"].get("example"), |
162 | 127 | ) |
163 | 128 | specversion: attribute.SpecVersion = Field( |
| 129 | + title=FIELD_DESCRIPTIONS["specversion"].get("title"), |
| 130 | + description=FIELD_DESCRIPTIONS["specversion"].get("description"), |
| 131 | + example=FIELD_DESCRIPTIONS["specversion"].get("example"), |
164 | 132 | default=attribute.DEFAULT_SPECVERSION, |
165 | | - title="Specification Version", |
166 | | - description=( |
167 | | - "The version of the CloudEvents specification which the event uses. This" |
168 | | - " enables the interpretation of the context.\n" |
169 | | - "\n" |
170 | | - "Currently, this attribute will only have the 'major'" |
171 | | - " and 'minor' version numbers included in it. This allows for 'patch'" |
172 | | - " changes to the specification to be made without changing this property's" |
173 | | - " value in the serialization." |
174 | | - ), |
175 | | - example=attribute.DEFAULT_SPECVERSION, |
176 | 133 | ) |
177 | 134 | time: typing.Optional[datetime.datetime] = Field( |
| 135 | + title=FIELD_DESCRIPTIONS["time"].get("title"), |
| 136 | + description=FIELD_DESCRIPTIONS["time"].get("description"), |
| 137 | + example=FIELD_DESCRIPTIONS["time"].get("example"), |
178 | 138 | default_factory=attribute.default_time_selection_algorithm, |
179 | | - title="Occurrence Time", |
180 | | - description=( |
181 | | - " Timestamp of when the occurrence happened. If the time of the occurrence" |
182 | | - " cannot be determined then this attribute MAY be set to some other time" |
183 | | - " (such as the current time) by the CloudEvents producer, however all" |
184 | | - " producers for the same source MUST be consistent in this respect. In" |
185 | | - " other words, either they all use the actual time of the occurrence or" |
186 | | - " they all use the same algorithm to determine the value used." |
187 | | - ), |
188 | | - example="2018-04-05T17:31:00Z", |
189 | 139 | ) |
190 | | - |
191 | 140 | subject: typing.Optional[str] = Field( |
192 | | - title="Event Subject", |
193 | | - description=( |
194 | | - "This describes the subject of the event in the context of the event" |
195 | | - " producer (identified by source). In publish-subscribe scenarios, a" |
196 | | - " subscriber will typically subscribe to events emitted by a source, but" |
197 | | - " the source identifier alone might not be sufficient as a qualifier for" |
198 | | - " any specific event if the source context has internal" |
199 | | - " sub-structure.\n" |
200 | | - "\n" |
201 | | - "Identifying the subject of the event in context" |
202 | | - " metadata (opposed to only in the data payload) is particularly helpful in" |
203 | | - " generic subscription filtering scenarios where middleware is unable to" |
204 | | - " interpret the data content. In the above example, the subscriber might" |
205 | | - " only be interested in blobs with names ending with '.jpg' or '.jpeg' and" |
206 | | - " the subject attribute allows for constructing a simple and efficient" |
207 | | - " string-suffix filter for that subset of events." |
208 | | - ), |
209 | | - example="123", |
| 141 | + title=FIELD_DESCRIPTIONS["subject"].get("title"), |
| 142 | + description=FIELD_DESCRIPTIONS["subject"].get("description"), |
| 143 | + example=FIELD_DESCRIPTIONS["subject"].get("example"), |
210 | 144 | ) |
211 | 145 | datacontenttype: typing.Optional[str] = Field( |
212 | | - title="Event Data Content Type", |
213 | | - description=( |
214 | | - "Content type of data value. This attribute enables data to carry any type" |
215 | | - " of content, whereby format and encoding might differ from that of the" |
216 | | - " chosen event format." |
217 | | - ), |
218 | | - example="text/xml", |
| 146 | + title=FIELD_DESCRIPTIONS["datacontenttype"].get("title"), |
| 147 | + description=FIELD_DESCRIPTIONS["datacontenttype"].get("description"), |
| 148 | + example=FIELD_DESCRIPTIONS["datacontenttype"].get("example"), |
219 | 149 | ) |
220 | 150 | dataschema: typing.Optional[str] = Field( |
221 | | - title="Event Data Schema", |
222 | | - description=( |
223 | | - "Identifies the schema that data adheres to. " |
224 | | - "Incompatible changes to the schema SHOULD be reflected by a different URI" |
225 | | - ), |
| 151 | + title=FIELD_DESCRIPTIONS["dataschema"].get("title"), |
| 152 | + description=FIELD_DESCRIPTIONS["dataschema"].get("description"), |
| 153 | + example=FIELD_DESCRIPTIONS["dataschema"].get("example"), |
226 | 154 | ) |
227 | 155 |
|
228 | 156 | def __init__( # type: ignore[no-untyped-def] |
|
0 commit comments