| 2750 | self.mode = mode |
| 2751 | |
| 2752 | def __get_pydantic_json_schema__( |
| 2753 | self, core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler |
| 2754 | ) -> JsonSchemaValue: |
| 2755 | mode = self.mode or handler.mode |
| 2756 | json_schema = handler(core_schema) |
| 2757 | if mode != handler.mode: |
| 2758 | return json_schema |
| 2759 | examples = json_schema.get('examples') |
| 2760 | if examples is None: |
| 2761 | json_schema['examples'] = to_jsonable_python(self.examples) |
| 2762 | if isinstance(examples, dict): |
| 2763 | if isinstance(self.examples, list): |
| 2764 | warnings.warn( |
| 2765 | 'Updating existing JSON Schema examples of type dict with examples of type list. ' |
| 2766 | 'Only the existing examples values will be retained. Note that dict support for ' |
| 2767 | 'examples is deprecated and will be removed in v3.0.', |
| 2768 | UserWarning, |
| 2769 | ) |
| 2770 | json_schema['examples'] = to_jsonable_python( |
| 2771 | [ex for value in examples.values() for ex in value] + self.examples |
| 2772 | ) |
| 2773 | else: |
| 2774 | json_schema['examples'] = to_jsonable_python({**examples, **self.examples}) |
| 2775 | if isinstance(examples, list): |
| 2776 | if isinstance(self.examples, list): |
| 2777 | json_schema['examples'] = to_jsonable_python(examples + self.examples) |
| 2778 | elif isinstance(self.examples, dict): |
| 2779 | warnings.warn( |
| 2780 | 'Updating existing JSON Schema examples of type list with examples of type dict. ' |
| 2781 | 'Only the examples values will be retained. Note that dict support for ' |
| 2782 | 'examples is deprecated and will be removed in v3.0.', |
| 2783 | UserWarning, |
| 2784 | ) |
| 2785 | json_schema['examples'] = to_jsonable_python( |
| 2786 | examples + [ex for value in self.examples.values() for ex in value] |
| 2787 | ) |
| 2788 | |
| 2789 | return json_schema |
| 2790 | |
| 2791 | def __hash__(self) -> int: |
| 2792 | return hash(type(self.mode)) |