Commit bbd18e9b authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

improve config model

parent 6e297d46
"""Config model using pydantic"""
from typing import List, Union
from pydantic import BaseModel, HttpUrl
from typing import List, Optional, Union
from pydantic import BaseModel, HttpUrl, root_validator
class Link(BaseModel):
......@@ -26,10 +25,18 @@ class Catalog(BaseModel):
class Section(BaseModel):
name: str
title: str
description: str = ""
catalog: Union[HttpUrl, Catalog] = None
links: List[ExternalLink] = None
description: Optional[str] = ""
catalog: Optional[Union[HttpUrl, Catalog]] = None
links: Optional[List[ExternalLink]] = None
@root_validator
def check_catalog_or_links(cls, values):
catalog, links = values.get("catalog"), values.get("links")
if catalog is None and links is None:
raise ValueError("catalog or links field must be defined")
if catalog is not None and links is not None:
raise ValueError("only one of catalog and links must be defined")
return values
class Footer(BaseModel):
links: List[Link]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment