Skip to content

Commit

Permalink
docs(kong): improve datastore example in swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Apr 5, 2024
1 parent df15180 commit 8becce7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
31 changes: 29 additions & 2 deletions gateway/models/kong.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions gateway/routers/kong.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8becce7

Please sign in to comment.