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