Skip to content

Commit

Permalink
rename name by key
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 31, 2022
1 parent cf4146b commit 0bbfdbd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from httpx import HTTPStatusError
from pydantic import ValidationError
from pydantic.errors import PydanticValueError
from servicelib.error_codes import create_error_code

from ...core.settings import ApplicationSettings, BasicSettings
from ...models.schemas.solvers import Solver, SolverKeyId, SolverPort, VersionStr
Expand Down Expand Up @@ -191,10 +192,20 @@ async def list_solver_ports(
)
return ports

except (
ValidationError,
HTTPStatusError,
) as err:
except ValidationError as err:
error_code = create_error_code(err)
logger.exception(
"Corrupted port data for service %s [%s]",
f"{solver_key}:{version}",
f"{error_code}",
extra={"error_code": error_code},
)
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Port definition of {solver_key}:{version} seems corrupted [{error_code}]",
) from err

except HTTPStatusError as err:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Ports for solver {solver_key}:{version} not found",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,23 @@ def compose_resource_name(cls, solver_key, solver_version) -> str:


class SolverPort(BaseModel):
name: str = Field(
..., description="port identifier name", regex=PUBLIC_VARIABLE_NAME_RE
key: str = Field(
...,
description="port identifier name",
regex=PUBLIC_VARIABLE_NAME_RE,
title="Key name",
)
kind: PortKindStr
content_schema: Optional[dict[str, Any]] = None
content_schema: Optional[dict[str, Any]] = Field(
None,
description="jsonschema for the port's value. SEE https://json-schema.org",
)

class Config:
extra = Extra.ignore
schema_extra = {
"example": {
"name": "input_2",
"key": "input_2",
"kind": "input",
"content_schema": {
"title": "Sleep interval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_list_solver_ports(

assert resp.json() == [
{
"name": "input_1",
"key": "input_1",
"kind": "input",
"content_schema": {
"title": "Sleep interval",
Expand Down

0 comments on commit 0bbfdbd

Please sign in to comment.