|
1 | 1 | from dataclasses import dataclass, field
|
2 |
| -from typing import TYPE_CHECKING, AsyncGenerator, List, Optional, Union |
| 2 | +from typing import TYPE_CHECKING, AsyncGenerator, Generator, List, Optional, Union |
3 | 3 |
|
4 | 4 | from synapseclient.api.json_schema_services import (
|
5 | 5 | bind_json_schema_to_entity,
|
6 | 6 | delete_json_schema_from_entity,
|
7 | 7 | get_invalid_json_schema_validation,
|
| 8 | + get_invalid_json_schema_validation_sync, |
8 | 9 | get_json_schema_derived_keys,
|
9 | 10 | get_json_schema_from_entity,
|
10 | 11 | get_json_schema_validation_statistics,
|
11 | 12 | validate_entity_with_json_schema,
|
12 | 13 | )
|
13 |
| -from synapseclient.core.async_utils import async_to_sync |
| 14 | +from synapseclient.core.async_utils import async_to_sync, skip_async_to_sync |
14 | 15 | from synapseclient.models.protocols.json_schema_protocol import (
|
15 | 16 | BaseJSONSchemaProtocol,
|
16 | 17 | ContainerEntityJSONSchemaProtocol,
|
@@ -412,9 +413,10 @@ async def get_schema_validation_statistics_async(
|
412 | 413 | number_of_unknown_children=response.get("numberOfUnknownChildren", None),
|
413 | 414 | )
|
414 | 415 |
|
| 416 | + @skip_async_to_sync |
415 | 417 | async def get_invalid_validation_async(
|
416 | 418 | self, *, synapse_client: Optional["Synapse"] = None
|
417 |
| - ) -> AsyncGenerator[InvalidJSONSchemaValidation, None]: |
| 419 | + ) -> AsyncGenerator[InvalidJSONSchemaValidation, None, None]: |
418 | 420 | """
|
419 | 421 | Get invalid JSON schema validation results for a container entity.
|
420 | 422 |
|
@@ -473,3 +475,66 @@ async def get_invalid_validation_async(
|
473 | 475 | ],
|
474 | 476 | ),
|
475 | 477 | )
|
| 478 | + |
| 479 | + def get_invalid_validation( |
| 480 | + self, *, synapse_client: Optional["Synapse"] = None |
| 481 | + ) -> Generator[InvalidJSONSchemaValidation, None, None]: |
| 482 | + """ |
| 483 | + Get invalid JSON schema validation results for a container entity. |
| 484 | +
|
| 485 | + Arguments: |
| 486 | + synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided, |
| 487 | + the last created instance from the Synapse class constructor will be used. |
| 488 | +
|
| 489 | + Yields: |
| 490 | + InvalidJSONSchemaValidation: An object containing the validation response, all validation messages, |
| 491 | + and the validation exception details. |
| 492 | + """ |
| 493 | + gen = get_invalid_json_schema_validation_sync( |
| 494 | + synapse_client=synapse_client, synapse_id=self.id |
| 495 | + ) |
| 496 | + |
| 497 | + for item in gen: |
| 498 | + yield InvalidJSONSchemaValidation( |
| 499 | + validation_response=JSONSchemaValidation( |
| 500 | + object_id=item.get("objectId", None), |
| 501 | + object_type=item.get("objectType", None), |
| 502 | + object_etag=item.get("objectEtag", None), |
| 503 | + id=item.get("schema$id", None), |
| 504 | + is_valid=item.get("isValid", None), |
| 505 | + validated_on=item.get("validatedOn", None), |
| 506 | + ), |
| 507 | + validation_error_message=item.get("validationErrorMessage", None), |
| 508 | + all_validation_messages=item.get("allValidationMessages", []), |
| 509 | + validation_exception=ValidationException( |
| 510 | + pointer_to_violation=item.get("validationException", {}).get( |
| 511 | + "pointerToViolation", None |
| 512 | + ), |
| 513 | + message=item.get("validationException", {}).get("message", None), |
| 514 | + schema_location=item.get("validationException", {}).get( |
| 515 | + "schemaLocation", None |
| 516 | + ), |
| 517 | + causing_exceptions=[ |
| 518 | + CausingException( |
| 519 | + keyword=ce.get("keyword", None), |
| 520 | + pointer_to_violation=ce.get("pointerToViolation", None), |
| 521 | + message=ce.get("message", None), |
| 522 | + schema_location=ce.get("schemaLocation", None), |
| 523 | + causing_exceptions=[ |
| 524 | + CausingException( |
| 525 | + keyword=nce.get("keyword", None), |
| 526 | + pointer_to_violation=nce.get( |
| 527 | + "pointerToViolation", None |
| 528 | + ), |
| 529 | + message=nce.get("message", None), |
| 530 | + schema_location=nce.get("schemaLocation", None), |
| 531 | + ) |
| 532 | + for nce in ce.get("causingExceptions", []) |
| 533 | + ], |
| 534 | + ) |
| 535 | + for ce in item.get("validationException", {}).get( |
| 536 | + "causingExceptions", [] |
| 537 | + ) |
| 538 | + ], |
| 539 | + ), |
| 540 | + ) |
0 commit comments