diff --git a/src/openforms/contrib/kvk/migrations/0005_normalize_kvk_service_config.py b/src/openforms/contrib/kvk/migrations/0005_normalize_kvk_service_config.py index ecbdddf510..3cba6b0529 100644 --- a/src/openforms/contrib/kvk/migrations/0005_normalize_kvk_service_config.py +++ b/src/openforms/contrib/kvk/migrations/0005_normalize_kvk_service_config.py @@ -24,6 +24,10 @@ def set_kvk_service(apps, _): """ Derive the "common" API root for KVK interaction. + NOTE: the explanation below is kept for historical reasons. The API specs are + separate and so are the services/config. We don't use the API specs anymore, + but API gateways caused issues. See migration 0007 which reverts this change. + The zoeken/basisprofielen API's were historically separate services because they have their own OpenAPI specs and zgw_consumers requires api_root to be unique. Not doing this doesn't allow using zgw_consumers.Service.build_client (which needs the diff --git a/src/openforms/prefill/management/commands/generate_prefill_from_spec.py b/src/openforms/prefill/management/commands/generate_prefill_from_spec.py index d73d3a1859..f9fe11a316 100644 --- a/src/openforms/prefill/management/commands/generate_prefill_from_spec.py +++ b/src/openforms/prefill/management/commands/generate_prefill_from_spec.py @@ -4,8 +4,9 @@ from django.core.management import BaseCommand import black +import requests +import yaml from glom import GlomError, Path, glom -from zds_client.oas import SchemaFetcher from zgw_consumers.models import Service from ...attributes_generator import OpenApi3AttributesGenerator @@ -70,11 +71,18 @@ def select_schema(root_schema, api_schema): return None +def fetch_schema(url: str) -> dict: + # fetch the schema and load as yaml. Note that JSON documents are also valid YAML. + response = requests.get(url) + response.raise_for_status() + root_schema = yaml.safe_load(response.content) + return root_schema + + def generate_prefill_from_spec_url( url, api_path="", api_schema="", use_embeds=False, command="" ): - schema_fetcher = SchemaFetcher() - root_schema = schema_fetcher.fetch(url) + root_schema = fetch_schema(url) # find the call with the http parameters we're interested in if not api_path and not api_schema: @@ -333,7 +341,7 @@ def handle(self, **options): if url and not options["path"] and not options["schema"]: # be helpful and suggest paths and schemas - schema = SchemaFetcher().fetch(url) + schema = fetch_schema(url) if schema["paths"]: self.stdout.write("path:") diff --git a/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py b/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py index d7b3822baf..16e4963203 100644 --- a/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py +++ b/src/openforms/submissions/tests/form_logic/test_fetching_form_variable_values_from_services.py @@ -1,4 +1,3 @@ -from functools import lru_cache from pathlib import Path from typing import Any from unittest import skip @@ -47,16 +46,6 @@ def setUpClass(cls): ), ) - # prevent parsing the yaml over and over and over - cls.service.id = 1 # need pk for __hash__ - # FIXME: update to new client approach - cls.service.build_client = lru_cache(1)(cls.service.build_client) - - # populate the schema cache *before* any test runs, otherwise this causes flakiness - # in hypothesis tests - client = cls.service.build_client() - client.schema - @requests_mock.Mocker() def test_it_performs_simple_get(self, m): m.get("https://httpbin.org/get", json={"url": "https://httpbin.org/get"})