|
17 | 17 |
|
18 | 18 | from flask.signals import got_request_exception |
19 | 19 |
|
20 | | -from jsonschema import RefResolver |
| 20 | +from referencing import Registry |
21 | 21 |
|
22 | 22 | from werkzeug.utils import cached_property |
23 | 23 | from werkzeug.datastructures import Headers |
@@ -134,7 +134,7 @@ def __init__( |
134 | 134 | format_checker=None, |
135 | 135 | url_scheme=None, |
136 | 136 | default_swagger_filename="swagger.json", |
137 | | - **kwargs |
| 137 | + **kwargs, |
138 | 138 | ): |
139 | 139 | self.version = version |
140 | 140 | self.title = title or "API" |
@@ -830,7 +830,44 @@ def payload(self): |
830 | 830 | @property |
831 | 831 | def refresolver(self): |
832 | 832 | if not self._refresolver: |
833 | | - self._refresolver = RefResolver.from_schema(self.__schema__) |
| 833 | + # Create a registry that can resolve references within our schema |
| 834 | + registry = Registry() |
| 835 | + schema = self.__schema__ |
| 836 | + |
| 837 | + # If schema has definitions, register it |
| 838 | + if "definitions" in schema: |
| 839 | + schema_id = schema.get("$id", "http://localhost/schema.json") |
| 840 | + registry = registry.with_resource(schema_id, schema) |
| 841 | + else: |
| 842 | + # If no definitions in schema, register all models individually |
| 843 | + for name, model in self.models.items(): |
| 844 | + model_schema = model.__schema__ |
| 845 | + # Add $id to the model schema so it can be referenced |
| 846 | + if "$id" not in model_schema: |
| 847 | + model_schema = model_schema.copy() |
| 848 | + model_schema["$id"] = ( |
| 849 | + f"http://localhost/schema.json#/definitions/{name}" |
| 850 | + ) |
| 851 | + registry = registry.with_resource( |
| 852 | + f"http://localhost/schema.json#/definitions/{name}", |
| 853 | + model_schema, |
| 854 | + ) |
| 855 | + |
| 856 | + # Also register the root schema with definitions |
| 857 | + if self.models: |
| 858 | + definitions = {} |
| 859 | + for name, model in self.models.items(): |
| 860 | + definitions[name] = model.__schema__ |
| 861 | + |
| 862 | + schema_with_definitions = { |
| 863 | + "$id": "http://localhost/schema.json", |
| 864 | + "definitions": definitions, |
| 865 | + } |
| 866 | + registry = registry.with_resource( |
| 867 | + "http://localhost/schema.json", schema_with_definitions |
| 868 | + ) |
| 869 | + |
| 870 | + self._refresolver = registry |
834 | 871 | return self._refresolver |
835 | 872 |
|
836 | 873 | @staticmethod |
@@ -866,7 +903,7 @@ def _blueprint_setup_add_url_rule_patch( |
866 | 903 | "%s.%s" % (blueprint_setup.blueprint.name, endpoint), |
867 | 904 | view_func, |
868 | 905 | defaults=defaults, |
869 | | - **options |
| 906 | + **options, |
870 | 907 | ) |
871 | 908 |
|
872 | 909 | def _deferred_blueprint_init(self, setup_state): |
|
0 commit comments