diff --git a/gateway/models/kong.py b/gateway/models/kong.py index c117266..236681d 100644 --- a/gateway/models/kong.py +++ b/gateway/models/kong.py @@ -1,8 +1,8 @@ """Models for the Kong microservice.""" from enum import Enum -from kong_admin_client import CreateServiceRequest, CreateServiceRequestClientCertificate, Plugin, Consumer, KeyAuth, \ - ACL +from kong_admin_client import CreateServiceRequest, Plugin, Consumer, KeyAuth, \ + ACL, CreateServiceRequestClientCertificate from kong_admin_client.models.service import Service from pydantic import BaseModel, constr @@ -15,6 +15,7 @@ class DataStoreType(Enum): class ServiceRequest(CreateServiceRequest): """Improved version of the CreateServiceRequest with better defaults.""" + protocol: str | None = "http" port: int | None = 80 path: str | None = "/somewhere" @@ -23,6 +24,32 @@ class ServiceRequest(CreateServiceRequest): ca_certificates: list[str] | None = None enabled: bool = True + model_config = { + "json_schema_extra": { + "examples": [ + { + "name": "myNewDatastore", + "retries": 5, + "protocol": "http", + "host": "whonnock", + "port": 443, + "path": "/upload", + "connect_timeout": 6000, + "write_timeout": 6000, + "read_timeout": 6000, + "tags": [ + "example" + ], + "client_certificate": None, + "tls_verify": None, + "tls_verify_depth": None, + "ca_certificates": None, + "enabled": True + } + ] + } + } + class LinkDataStoreProject(BaseModel): route: Service diff --git a/gateway/routers/kong.py b/gateway/routers/kong.py index 105a8d4..9cf5583 100644 --- a/gateway/routers/kong.py +++ b/gateway/routers/kong.py @@ -116,10 +116,12 @@ async def delete_data_store( @kong_router.post("/datastore", response_model=Service, status_code=status.HTTP_201_CREATED) -async def create_data_store(data: Annotated[ServiceRequest, Body( - description="Required information for creating a new data store.", - title="Data store metadata." -)]): +async def create_data_store( + data: Annotated[ServiceRequest, Body( + description="Required information for creating a new data store.", + title="Data store metadata." + )] +): """Create a datastore by providing necessary metadata.""" configuration = kong_admin_client.Configuration(host=kong_admin_url)