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