miro_api.models.item_data_create
Miro Developer Platform
### Miro Developer Platform concepts - New to the Miro Developer Platform? Interested in learning more about platform concepts?? Read our introduction page and familiarize yourself with the Miro Developer Platform capabilities in a few minutes. ### Getting started with the Miro REST API - Quickstart (video): try the REST API in less than 3 minutes. - Quickstart (article): get started and try the REST API in less than 3 minutes. ### Miro REST API tutorials Check out our how-to articles with step-by-step instructions and code examples so you can: - Get started with OAuth 2.0 and Miro ### Miro App Examples Clone our Miro App Examples repository to get inspiration, customize, and explore apps built on top of Miro's Developer Platform 2.0.
The version of the OpenAPI document: v2.0 Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
1# coding: utf-8 2 3""" 4Miro Developer Platform 5 6<img src=\"https://content.pstmn.io/47449ea6-0ef7-4af2-bac1-e58a70e61c58/aW1hZ2UucG5n\" width=\"1685\" height=\"593\"> ### Miro Developer Platform concepts - New to the Miro Developer Platform? Interested in learning more about platform concepts?? [Read our introduction page](https://beta.developers.miro.com/docs/introduction) and familiarize yourself with the Miro Developer Platform capabilities in a few minutes. ### Getting started with the Miro REST API - [Quickstart (video):](https://beta.developers.miro.com/docs/try-out-the-rest-api-in-less-than-3-minutes) try the REST API in less than 3 minutes. - [Quickstart (article):](https://beta.developers.miro.com/docs/build-your-first-hello-world-app-1) get started and try the REST API in less than 3 minutes. ### Miro REST API tutorials Check out our how-to articles with step-by-step instructions and code examples so you can: - [Get started with OAuth 2.0 and Miro](https://beta.developers.miro.com/docs/getting-started-with-oauth) ### Miro App Examples Clone our [Miro App Examples repository](https://github.com/miroapp/app-examples) to get inspiration, customize, and explore apps built on top of Miro's Developer Platform 2.0. 7 8The version of the OpenAPI document: v2.0 9Generated by OpenAPI Generator (https://openapi-generator.tech) 10 11Do not edit the class manually. 12""" # noqa: E501 13 14 15from __future__ import annotations 16import json 17import pprint 18from pydantic import BaseModel, Field, StrictStr, ValidationError, field_validator 19from typing import Any, List, Optional 20from miro_api.models.app_card_data import AppCardData 21from miro_api.models.card_data import CardData 22from miro_api.models.document_url_data import DocumentUrlData 23from miro_api.models.embed_url_data import EmbedUrlData 24from miro_api.models.image_url_data import ImageUrlData 25from miro_api.models.shape_data import ShapeData 26from miro_api.models.sticky_note_data import StickyNoteData 27from miro_api.models.text_data import TextData 28from pydantic import StrictStr, Field 29from typing import Union, List, Optional, Dict 30from typing_extensions import Literal, Self 31 32ITEMDATACREATE_ONE_OF_SCHEMAS = [ 33 "AppCardData", 34 "CardData", 35 "DocumentUrlData", 36 "EmbedUrlData", 37 "ImageUrlData", 38 "ShapeData", 39 "StickyNoteData", 40 "TextData", 41] 42 43 44class ItemDataCreate(BaseModel): 45 """ 46 Contains data information applicable for each item type. 47 """ 48 49 # data type: AppCardData 50 oneof_schema_1_validator: Optional[AppCardData] = None 51 # data type: CardData 52 oneof_schema_2_validator: Optional[CardData] = None 53 # data type: DocumentUrlData 54 oneof_schema_3_validator: Optional[DocumentUrlData] = None 55 # data type: EmbedUrlData 56 oneof_schema_4_validator: Optional[EmbedUrlData] = None 57 # data type: ImageUrlData 58 oneof_schema_5_validator: Optional[ImageUrlData] = None 59 # data type: ShapeData 60 oneof_schema_6_validator: Optional[ShapeData] = None 61 # data type: StickyNoteData 62 oneof_schema_7_validator: Optional[StickyNoteData] = None 63 # data type: TextData 64 oneof_schema_8_validator: Optional[TextData] = None 65 actual_instance: Optional[ 66 Union[AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData] 67 ] = None 68 one_of_schemas: List[str] = Field( 69 default=Literal[ 70 "AppCardData", 71 "CardData", 72 "DocumentUrlData", 73 "EmbedUrlData", 74 "ImageUrlData", 75 "ShapeData", 76 "StickyNoteData", 77 "TextData", 78 ] 79 ) 80 81 model_config = { 82 "validate_assignment": True, 83 "protected_namespaces": (), 84 } 85 86 def __init__(self, *args, **kwargs) -> None: 87 if args: 88 if len(args) > 1: 89 raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") 90 if kwargs: 91 raise ValueError("If a position argument is used, keyword arguments cannot be used.") 92 super().__init__(actual_instance=args[0]) 93 else: 94 super().__init__(**kwargs) 95 96 def __getattr__(self, attr: str): 97 return getattr(self.actual_instance, attr) 98 99 @field_validator("actual_instance") 100 def actual_instance_must_validate_oneof(cls, v): 101 instance = ItemDataCreate.model_construct() 102 error_messages = [] 103 match = 0 104 # validate data type: AppCardData 105 if not isinstance(v, AppCardData): 106 error_messages.append(f"Error! Input type `{type(v)}` is not `AppCardData`") 107 else: 108 match += 1 109 # validate data type: CardData 110 if not isinstance(v, CardData): 111 error_messages.append(f"Error! Input type `{type(v)}` is not `CardData`") 112 else: 113 match += 1 114 # validate data type: DocumentUrlData 115 if not isinstance(v, DocumentUrlData): 116 error_messages.append(f"Error! Input type `{type(v)}` is not `DocumentUrlData`") 117 else: 118 match += 1 119 # validate data type: EmbedUrlData 120 if not isinstance(v, EmbedUrlData): 121 error_messages.append(f"Error! Input type `{type(v)}` is not `EmbedUrlData`") 122 else: 123 match += 1 124 # validate data type: ImageUrlData 125 if not isinstance(v, ImageUrlData): 126 error_messages.append(f"Error! Input type `{type(v)}` is not `ImageUrlData`") 127 else: 128 match += 1 129 # validate data type: ShapeData 130 if not isinstance(v, ShapeData): 131 error_messages.append(f"Error! Input type `{type(v)}` is not `ShapeData`") 132 else: 133 match += 1 134 # validate data type: StickyNoteData 135 if not isinstance(v, StickyNoteData): 136 error_messages.append(f"Error! Input type `{type(v)}` is not `StickyNoteData`") 137 else: 138 match += 1 139 # validate data type: TextData 140 if not isinstance(v, TextData): 141 error_messages.append(f"Error! Input type `{type(v)}` is not `TextData`") 142 else: 143 match += 1 144 if match > 1: 145 # more than 1 match 146 raise ValueError( 147 "Multiple matches found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 148 + ", ".join(error_messages) 149 ) 150 elif match == 0: 151 # no match 152 raise ValueError( 153 "No match found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 154 + ", ".join(error_messages) 155 ) 156 else: 157 return v 158 159 @classmethod 160 def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: 161 return cls.from_json(json.dumps(obj)) 162 163 @classmethod 164 def from_json( 165 cls, json_str: str 166 ) -> Union[AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData]: 167 """Returns the object represented by the json string""" 168 instance = cls.model_construct() 169 error_messages = [] 170 matches = [] 171 172 # deserialize data into AppCardData 173 try: 174 instance.actual_instance = AppCardData.from_json(json_str) 175 matches.append(instance.actual_instance) 176 except (ValidationError, ValueError) as e: 177 error_messages.append(str(e)) 178 # deserialize data into CardData 179 try: 180 instance.actual_instance = CardData.from_json(json_str) 181 matches.append(instance.actual_instance) 182 except (ValidationError, ValueError) as e: 183 error_messages.append(str(e)) 184 # deserialize data into DocumentUrlData 185 try: 186 instance.actual_instance = DocumentUrlData.from_json(json_str) 187 matches.append(instance.actual_instance) 188 except (ValidationError, ValueError) as e: 189 error_messages.append(str(e)) 190 # deserialize data into EmbedUrlData 191 try: 192 instance.actual_instance = EmbedUrlData.from_json(json_str) 193 matches.append(instance.actual_instance) 194 except (ValidationError, ValueError) as e: 195 error_messages.append(str(e)) 196 # deserialize data into ImageUrlData 197 try: 198 instance.actual_instance = ImageUrlData.from_json(json_str) 199 matches.append(instance.actual_instance) 200 except (ValidationError, ValueError) as e: 201 error_messages.append(str(e)) 202 # deserialize data into ShapeData 203 try: 204 instance.actual_instance = ShapeData.from_json(json_str) 205 matches.append(instance.actual_instance) 206 except (ValidationError, ValueError) as e: 207 error_messages.append(str(e)) 208 # deserialize data into StickyNoteData 209 try: 210 instance.actual_instance = StickyNoteData.from_json(json_str) 211 matches.append(instance.actual_instance) 212 except (ValidationError, ValueError) as e: 213 error_messages.append(str(e)) 214 # deserialize data into TextData 215 try: 216 instance.actual_instance = TextData.from_json(json_str) 217 matches.append(instance.actual_instance) 218 except (ValidationError, ValueError) as e: 219 error_messages.append(str(e)) 220 221 if not matches: 222 # no match 223 raise ValueError( 224 "No match found when deserializing the JSON string into ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 225 + ", ".join(error_messages) 226 ) 227 228 # Return one match that has least additional_properties 229 if len(matches) > 1: 230 instance.actual_instance = sorted(matches, key=lambda m: len(m.additional_properties))[0] 231 232 return instance 233 234 def to_json(self) -> str: 235 """Returns the JSON representation of the actual instance""" 236 if self.actual_instance is None: 237 return "null" 238 239 if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): 240 return self.actual_instance.to_json() 241 else: 242 return json.dumps(self.actual_instance) 243 244 def to_dict( 245 self, 246 ) -> Optional[ 247 Union[ 248 Dict[str, Any], 249 AppCardData, 250 CardData, 251 DocumentUrlData, 252 EmbedUrlData, 253 ImageUrlData, 254 ShapeData, 255 StickyNoteData, 256 TextData, 257 ] 258 ]: 259 """Returns the dict representation of the actual instance""" 260 if self.actual_instance is None: 261 return None 262 263 if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): 264 return self.actual_instance.to_dict() 265 else: 266 # primitive type 267 return self.actual_instance 268 269 def to_str(self) -> str: 270 """Returns the string representation of the actual instance""" 271 return pprint.pformat(self.model_dump())
45class ItemDataCreate(BaseModel): 46 """ 47 Contains data information applicable for each item type. 48 """ 49 50 # data type: AppCardData 51 oneof_schema_1_validator: Optional[AppCardData] = None 52 # data type: CardData 53 oneof_schema_2_validator: Optional[CardData] = None 54 # data type: DocumentUrlData 55 oneof_schema_3_validator: Optional[DocumentUrlData] = None 56 # data type: EmbedUrlData 57 oneof_schema_4_validator: Optional[EmbedUrlData] = None 58 # data type: ImageUrlData 59 oneof_schema_5_validator: Optional[ImageUrlData] = None 60 # data type: ShapeData 61 oneof_schema_6_validator: Optional[ShapeData] = None 62 # data type: StickyNoteData 63 oneof_schema_7_validator: Optional[StickyNoteData] = None 64 # data type: TextData 65 oneof_schema_8_validator: Optional[TextData] = None 66 actual_instance: Optional[ 67 Union[AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData] 68 ] = None 69 one_of_schemas: List[str] = Field( 70 default=Literal[ 71 "AppCardData", 72 "CardData", 73 "DocumentUrlData", 74 "EmbedUrlData", 75 "ImageUrlData", 76 "ShapeData", 77 "StickyNoteData", 78 "TextData", 79 ] 80 ) 81 82 model_config = { 83 "validate_assignment": True, 84 "protected_namespaces": (), 85 } 86 87 def __init__(self, *args, **kwargs) -> None: 88 if args: 89 if len(args) > 1: 90 raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") 91 if kwargs: 92 raise ValueError("If a position argument is used, keyword arguments cannot be used.") 93 super().__init__(actual_instance=args[0]) 94 else: 95 super().__init__(**kwargs) 96 97 def __getattr__(self, attr: str): 98 return getattr(self.actual_instance, attr) 99 100 @field_validator("actual_instance") 101 def actual_instance_must_validate_oneof(cls, v): 102 instance = ItemDataCreate.model_construct() 103 error_messages = [] 104 match = 0 105 # validate data type: AppCardData 106 if not isinstance(v, AppCardData): 107 error_messages.append(f"Error! Input type `{type(v)}` is not `AppCardData`") 108 else: 109 match += 1 110 # validate data type: CardData 111 if not isinstance(v, CardData): 112 error_messages.append(f"Error! Input type `{type(v)}` is not `CardData`") 113 else: 114 match += 1 115 # validate data type: DocumentUrlData 116 if not isinstance(v, DocumentUrlData): 117 error_messages.append(f"Error! Input type `{type(v)}` is not `DocumentUrlData`") 118 else: 119 match += 1 120 # validate data type: EmbedUrlData 121 if not isinstance(v, EmbedUrlData): 122 error_messages.append(f"Error! Input type `{type(v)}` is not `EmbedUrlData`") 123 else: 124 match += 1 125 # validate data type: ImageUrlData 126 if not isinstance(v, ImageUrlData): 127 error_messages.append(f"Error! Input type `{type(v)}` is not `ImageUrlData`") 128 else: 129 match += 1 130 # validate data type: ShapeData 131 if not isinstance(v, ShapeData): 132 error_messages.append(f"Error! Input type `{type(v)}` is not `ShapeData`") 133 else: 134 match += 1 135 # validate data type: StickyNoteData 136 if not isinstance(v, StickyNoteData): 137 error_messages.append(f"Error! Input type `{type(v)}` is not `StickyNoteData`") 138 else: 139 match += 1 140 # validate data type: TextData 141 if not isinstance(v, TextData): 142 error_messages.append(f"Error! Input type `{type(v)}` is not `TextData`") 143 else: 144 match += 1 145 if match > 1: 146 # more than 1 match 147 raise ValueError( 148 "Multiple matches found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 149 + ", ".join(error_messages) 150 ) 151 elif match == 0: 152 # no match 153 raise ValueError( 154 "No match found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 155 + ", ".join(error_messages) 156 ) 157 else: 158 return v 159 160 @classmethod 161 def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self: 162 return cls.from_json(json.dumps(obj)) 163 164 @classmethod 165 def from_json( 166 cls, json_str: str 167 ) -> Union[AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData]: 168 """Returns the object represented by the json string""" 169 instance = cls.model_construct() 170 error_messages = [] 171 matches = [] 172 173 # deserialize data into AppCardData 174 try: 175 instance.actual_instance = AppCardData.from_json(json_str) 176 matches.append(instance.actual_instance) 177 except (ValidationError, ValueError) as e: 178 error_messages.append(str(e)) 179 # deserialize data into CardData 180 try: 181 instance.actual_instance = CardData.from_json(json_str) 182 matches.append(instance.actual_instance) 183 except (ValidationError, ValueError) as e: 184 error_messages.append(str(e)) 185 # deserialize data into DocumentUrlData 186 try: 187 instance.actual_instance = DocumentUrlData.from_json(json_str) 188 matches.append(instance.actual_instance) 189 except (ValidationError, ValueError) as e: 190 error_messages.append(str(e)) 191 # deserialize data into EmbedUrlData 192 try: 193 instance.actual_instance = EmbedUrlData.from_json(json_str) 194 matches.append(instance.actual_instance) 195 except (ValidationError, ValueError) as e: 196 error_messages.append(str(e)) 197 # deserialize data into ImageUrlData 198 try: 199 instance.actual_instance = ImageUrlData.from_json(json_str) 200 matches.append(instance.actual_instance) 201 except (ValidationError, ValueError) as e: 202 error_messages.append(str(e)) 203 # deserialize data into ShapeData 204 try: 205 instance.actual_instance = ShapeData.from_json(json_str) 206 matches.append(instance.actual_instance) 207 except (ValidationError, ValueError) as e: 208 error_messages.append(str(e)) 209 # deserialize data into StickyNoteData 210 try: 211 instance.actual_instance = StickyNoteData.from_json(json_str) 212 matches.append(instance.actual_instance) 213 except (ValidationError, ValueError) as e: 214 error_messages.append(str(e)) 215 # deserialize data into TextData 216 try: 217 instance.actual_instance = TextData.from_json(json_str) 218 matches.append(instance.actual_instance) 219 except (ValidationError, ValueError) as e: 220 error_messages.append(str(e)) 221 222 if not matches: 223 # no match 224 raise ValueError( 225 "No match found when deserializing the JSON string into ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 226 + ", ".join(error_messages) 227 ) 228 229 # Return one match that has least additional_properties 230 if len(matches) > 1: 231 instance.actual_instance = sorted(matches, key=lambda m: len(m.additional_properties))[0] 232 233 return instance 234 235 def to_json(self) -> str: 236 """Returns the JSON representation of the actual instance""" 237 if self.actual_instance is None: 238 return "null" 239 240 if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): 241 return self.actual_instance.to_json() 242 else: 243 return json.dumps(self.actual_instance) 244 245 def to_dict( 246 self, 247 ) -> Optional[ 248 Union[ 249 Dict[str, Any], 250 AppCardData, 251 CardData, 252 DocumentUrlData, 253 EmbedUrlData, 254 ImageUrlData, 255 ShapeData, 256 StickyNoteData, 257 TextData, 258 ] 259 ]: 260 """Returns the dict representation of the actual instance""" 261 if self.actual_instance is None: 262 return None 263 264 if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): 265 return self.actual_instance.to_dict() 266 else: 267 # primitive type 268 return self.actual_instance 269 270 def to_str(self) -> str: 271 """Returns the string representation of the actual instance""" 272 return pprint.pformat(self.model_dump())
Contains data information applicable for each item type.
87 def __init__(self, *args, **kwargs) -> None: 88 if args: 89 if len(args) > 1: 90 raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") 91 if kwargs: 92 raise ValueError("If a position argument is used, keyword arguments cannot be used.") 93 super().__init__(actual_instance=args[0]) 94 else: 95 super().__init__(**kwargs)
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError
][pydantic_core.ValidationError] if the input data cannot be
validated to form a valid model.
self
is explicitly positional-only to allow self
as a field name.
100 @field_validator("actual_instance") 101 def actual_instance_must_validate_oneof(cls, v): 102 instance = ItemDataCreate.model_construct() 103 error_messages = [] 104 match = 0 105 # validate data type: AppCardData 106 if not isinstance(v, AppCardData): 107 error_messages.append(f"Error! Input type `{type(v)}` is not `AppCardData`") 108 else: 109 match += 1 110 # validate data type: CardData 111 if not isinstance(v, CardData): 112 error_messages.append(f"Error! Input type `{type(v)}` is not `CardData`") 113 else: 114 match += 1 115 # validate data type: DocumentUrlData 116 if not isinstance(v, DocumentUrlData): 117 error_messages.append(f"Error! Input type `{type(v)}` is not `DocumentUrlData`") 118 else: 119 match += 1 120 # validate data type: EmbedUrlData 121 if not isinstance(v, EmbedUrlData): 122 error_messages.append(f"Error! Input type `{type(v)}` is not `EmbedUrlData`") 123 else: 124 match += 1 125 # validate data type: ImageUrlData 126 if not isinstance(v, ImageUrlData): 127 error_messages.append(f"Error! Input type `{type(v)}` is not `ImageUrlData`") 128 else: 129 match += 1 130 # validate data type: ShapeData 131 if not isinstance(v, ShapeData): 132 error_messages.append(f"Error! Input type `{type(v)}` is not `ShapeData`") 133 else: 134 match += 1 135 # validate data type: StickyNoteData 136 if not isinstance(v, StickyNoteData): 137 error_messages.append(f"Error! Input type `{type(v)}` is not `StickyNoteData`") 138 else: 139 match += 1 140 # validate data type: TextData 141 if not isinstance(v, TextData): 142 error_messages.append(f"Error! Input type `{type(v)}` is not `TextData`") 143 else: 144 match += 1 145 if match > 1: 146 # more than 1 match 147 raise ValueError( 148 "Multiple matches found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 149 + ", ".join(error_messages) 150 ) 151 elif match == 0: 152 # no match 153 raise ValueError( 154 "No match found when setting `actual_instance` in ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 155 + ", ".join(error_messages) 156 ) 157 else: 158 return v
164 @classmethod 165 def from_json( 166 cls, json_str: str 167 ) -> Union[AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData]: 168 """Returns the object represented by the json string""" 169 instance = cls.model_construct() 170 error_messages = [] 171 matches = [] 172 173 # deserialize data into AppCardData 174 try: 175 instance.actual_instance = AppCardData.from_json(json_str) 176 matches.append(instance.actual_instance) 177 except (ValidationError, ValueError) as e: 178 error_messages.append(str(e)) 179 # deserialize data into CardData 180 try: 181 instance.actual_instance = CardData.from_json(json_str) 182 matches.append(instance.actual_instance) 183 except (ValidationError, ValueError) as e: 184 error_messages.append(str(e)) 185 # deserialize data into DocumentUrlData 186 try: 187 instance.actual_instance = DocumentUrlData.from_json(json_str) 188 matches.append(instance.actual_instance) 189 except (ValidationError, ValueError) as e: 190 error_messages.append(str(e)) 191 # deserialize data into EmbedUrlData 192 try: 193 instance.actual_instance = EmbedUrlData.from_json(json_str) 194 matches.append(instance.actual_instance) 195 except (ValidationError, ValueError) as e: 196 error_messages.append(str(e)) 197 # deserialize data into ImageUrlData 198 try: 199 instance.actual_instance = ImageUrlData.from_json(json_str) 200 matches.append(instance.actual_instance) 201 except (ValidationError, ValueError) as e: 202 error_messages.append(str(e)) 203 # deserialize data into ShapeData 204 try: 205 instance.actual_instance = ShapeData.from_json(json_str) 206 matches.append(instance.actual_instance) 207 except (ValidationError, ValueError) as e: 208 error_messages.append(str(e)) 209 # deserialize data into StickyNoteData 210 try: 211 instance.actual_instance = StickyNoteData.from_json(json_str) 212 matches.append(instance.actual_instance) 213 except (ValidationError, ValueError) as e: 214 error_messages.append(str(e)) 215 # deserialize data into TextData 216 try: 217 instance.actual_instance = TextData.from_json(json_str) 218 matches.append(instance.actual_instance) 219 except (ValidationError, ValueError) as e: 220 error_messages.append(str(e)) 221 222 if not matches: 223 # no match 224 raise ValueError( 225 "No match found when deserializing the JSON string into ItemDataCreate with oneOf schemas: AppCardData, CardData, DocumentUrlData, EmbedUrlData, ImageUrlData, ShapeData, StickyNoteData, TextData. Details: " 226 + ", ".join(error_messages) 227 ) 228 229 # Return one match that has least additional_properties 230 if len(matches) > 1: 231 instance.actual_instance = sorted(matches, key=lambda m: len(m.additional_properties))[0] 232 233 return instance
Returns the object represented by the json string
235 def to_json(self) -> str: 236 """Returns the JSON representation of the actual instance""" 237 if self.actual_instance is None: 238 return "null" 239 240 if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): 241 return self.actual_instance.to_json() 242 else: 243 return json.dumps(self.actual_instance)
Returns the JSON representation of the actual instance
245 def to_dict( 246 self, 247 ) -> Optional[ 248 Union[ 249 Dict[str, Any], 250 AppCardData, 251 CardData, 252 DocumentUrlData, 253 EmbedUrlData, 254 ImageUrlData, 255 ShapeData, 256 StickyNoteData, 257 TextData, 258 ] 259 ]: 260 """Returns the dict representation of the actual instance""" 261 if self.actual_instance is None: 262 return None 263 264 if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): 265 return self.actual_instance.to_dict() 266 else: 267 # primitive type 268 return self.actual_instance
Returns the dict representation of the actual instance
270 def to_str(self) -> str: 271 """Returns the string representation of the actual instance""" 272 return pprint.pformat(self.model_dump())
Returns the string representation of the actual instance
Inherited Members
- pydantic.main.BaseModel
- model_extra
- model_fields_set
- model_construct
- model_copy
- model_dump
- model_dump_json
- model_json_schema
- model_parametrized_name
- model_post_init
- model_rebuild
- model_validate
- model_validate_json
- model_validate_strings
- dict
- json
- parse_obj
- parse_raw
- parse_file
- from_orm
- construct
- copy
- schema
- schema_json
- validate
- update_forward_refs