Override this method to customize the sorting of the JSON schema (e.g., don't sort at all, sort all keys unconditionally, etc.) By default, alphabetically sort the keys in the JSON schema, skipping the 'properties' and 'default' keys to preserve field definition order. This sort is
(self, value: JsonSchemaValue, parent_key: str | None = None)
| 588 | return json_schema |
| 589 | |
| 590 | def sort(self, value: JsonSchemaValue, parent_key: str | None = None) -> JsonSchemaValue: |
| 591 | """Override this method to customize the sorting of the JSON schema (e.g., don't sort at all, sort all keys unconditionally, etc.) |
| 592 | |
| 593 | By default, alphabetically sort the keys in the JSON schema, skipping the 'properties' and 'default' keys to preserve field definition order. |
| 594 | This sort is recursive, so it will sort all nested dictionaries as well. |
| 595 | """ |
| 596 | sorted_dict: dict[str, JsonSchemaValue] = {} |
| 597 | keys = value.keys() |
| 598 | if parent_key not in ('properties', 'default'): |
| 599 | keys = sorted(keys) |
| 600 | for key in keys: |
| 601 | sorted_dict[key] = self._sort_recursive(value[key], parent_key=key) |
| 602 | return sorted_dict |
| 603 | |
| 604 | def _sort_recursive(self, value: Any, parent_key: str | None = None) -> Any: |
| 605 | """Recursively sort a JSON schema value.""" |