-
-
Notifications
You must be signed in to change notification settings - Fork 291
Closed as not planned
Labels
enhancementNew feature or requestNew feature or requeststaleIssue marked stale by stale-botIssue marked stale by stale-bot
Description
Is your feature request related to a problem? Please describe.
In order to improve flexibility and composability over inheritance it would be beneficial to improve the design using static duck typing PEP 544
Describe the solution you'd like
This is a very basic example how we can use it to adopt standard dataclasses as replacement of pydantic data models but at the same type leave the flexibility to use them for data validation in a fancy way without touching the core:
from typing import Any, Protocol
from pydantic import RootModel
from pydantic.dataclasses import dataclass as p_dataclass
from dataclasses import dataclass
from pygeoapi.models.openapi import SupportedFormats
class OAPIFormat(Protocol):
"""Interface for OpenAPI Format"""
root: SupportedFormats
class OAPIPydantic(RootModel):
root: SupportedFormats = SupportedFormats.YAML.value
@dataclass
class OAPI(OAPIFormat):
"""OpenAPI definition"""
root:SupportedFormats
@p_dataclass
class OAPI_PydanticDataclass(OAPIFormat):
"""OpenAPI definition"""
root:SupportedFormats
def check_openapi_format(format: OAPIFormat):
"""Check OpenAPI Format"""
print(format)
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
C-Loftus and vprivat-ads
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requeststaleIssue marked stale by stale-botIssue marked stale by stale-bot