From 2affb50d0593a8d9d4229970b034c0d317778c51 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Fri, 7 Feb 2025 14:54:16 +0000 Subject: [PATCH] Tweak validator for raw license links --- optimade/server/config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/optimade/server/config.py b/optimade/server/config.py index dd45a3bad..1ba800f13 100644 --- a/optimade/server/config.py +++ b/optimade/server/config.py @@ -240,7 +240,7 @@ class ServerConfig(BaseSettings): ] = "localhost:27017" license: Annotated[ - str | AnyHttpUrl | None, + AnyHttpUrl | str | None, Field( description="""Either an SPDX license identifier or a URL to a human-readable license, used to populate the `license` field in the info response. @@ -480,7 +480,9 @@ def check_license_info(cls, value: Any) -> AnyHttpUrl | None: if not value: return None - if not isinstance(value, AnyHttpUrl): + try: + value = AnyHttpUrl(value) + except ValueError: value = f"https://spdx.org/licenses/{value}" # Check if license URL is accessible