| 
1 |  | -from typing import Any, Literal  | 
 | 1 | +from typing import Annotated, Any, Literal  | 
2 | 2 | 
 
  | 
3 | 3 | from pydantic import BaseModel, ConfigDict, Field  | 
 | 4 | +from pydantic.config import JsonDict  | 
4 | 5 | 
 
  | 
5 | 6 | from ..basic_regex import PUBLIC_VARIABLE_NAME_RE  | 
6 | 7 | from ..services import ServiceInput, ServiceOutput  | 
 | 
10 | 11 |     update_schema_doc,  | 
11 | 12 | )  | 
12 | 13 | 
 
  | 
13 |  | -PortKindStr = Literal["input", "output"]  | 
14 |  | - | 
15 | 14 | 
 
  | 
16 | 15 | class ServicePortGet(BaseModel):  | 
17 |  | -    key: str = Field(  | 
18 |  | -        ...,  | 
19 |  | -        description="port identifier name",  | 
20 |  | -        pattern=PUBLIC_VARIABLE_NAME_RE,  | 
21 |  | -        title="Key name",  | 
22 |  | -    )  | 
23 |  | -    kind: PortKindStr  | 
 | 16 | +    key: Annotated[  | 
 | 17 | +        str,  | 
 | 18 | +        Field(  | 
 | 19 | +            description="Port identifier name",  | 
 | 20 | +            pattern=PUBLIC_VARIABLE_NAME_RE,  | 
 | 21 | +            title="Key name",  | 
 | 22 | +        ),  | 
 | 23 | +    ]  | 
 | 24 | +    kind: Literal["input", "output"]  | 
24 | 25 |     content_media_type: str | None = None  | 
25 |  | -    content_schema: dict[str, Any] | None = Field(  | 
26 |  | -        None,  | 
27 |  | -        description="jsonschema for the port's value. SEE https://json-schema.org/understanding-json-schema/",  | 
28 |  | -    )  | 
29 |  | -    model_config = ConfigDict(  | 
30 |  | -        json_schema_extra={  | 
31 |  | -            "example": {  | 
32 |  | -                "key": "input_1",  | 
33 |  | -                "kind": "input",  | 
34 |  | -                "content_schema": {  | 
35 |  | -                    "title": "Sleep interval",  | 
36 |  | -                    "type": "integer",  | 
37 |  | -                    "x_unit": "second",  | 
38 |  | -                    "minimum": 0,  | 
39 |  | -                    "maximum": 5,  | 
40 |  | -                },  | 
41 |  | -            }  | 
 | 26 | +    content_schema: Annotated[  | 
 | 27 | +        dict[str, Any] | None,  | 
 | 28 | +        Field(  | 
 | 29 | +            description="jsonschema for the port's value. SEE https://json-schema.org/understanding-json-schema/",  | 
 | 30 | +        ),  | 
 | 31 | +    ] = None  | 
 | 32 | + | 
 | 33 | +    @staticmethod  | 
 | 34 | +    def _update_json_schema_extra(schema: JsonDict) -> None:  | 
 | 35 | +        example_input: dict[str, Any] = {  | 
 | 36 | +            "key": "input_1",  | 
 | 37 | +            "kind": "input",  | 
 | 38 | +            "content_schema": {  | 
 | 39 | +                "title": "Sleep interval",  | 
 | 40 | +                "type": "integer",  | 
 | 41 | +                "x_unit": "second",  | 
 | 42 | +                "minimum": 0,  | 
 | 43 | +                "maximum": 5,  | 
 | 44 | +            },  | 
42 | 45 |         }  | 
 | 46 | +        schema.update(  | 
 | 47 | +            {  | 
 | 48 | +                "example": example_input,  | 
 | 49 | +                "examples": [  | 
 | 50 | +                    example_input,  | 
 | 51 | +                    {  | 
 | 52 | +                        "key": "output_1",  | 
 | 53 | +                        "kind": "output",  | 
 | 54 | +                        "content_media_type": "text/plain",  | 
 | 55 | +                        "content_schema": {  | 
 | 56 | +                            "type": "string",  | 
 | 57 | +                            "title": "File containing one random integer",  | 
 | 58 | +                            "description": "Integer is generated in range [1-9]",  | 
 | 59 | +                        },  | 
 | 60 | +                    },  | 
 | 61 | +                ],  | 
 | 62 | +            }  | 
 | 63 | +        )  | 
 | 64 | + | 
 | 65 | +    model_config = ConfigDict(  | 
 | 66 | +        json_schema_extra=_update_json_schema_extra,  | 
43 | 67 |     )  | 
44 | 68 | 
 
  | 
45 | 69 |     @classmethod  | 
46 |  | -    def from_service_io(  | 
 | 70 | +    def from_domain_model(  | 
47 | 71 |         cls,  | 
48 |  | -        kind: PortKindStr,  | 
 | 72 | +        kind: Literal["input", "output"],  | 
49 | 73 |         key: str,  | 
50 | 74 |         port: ServiceInput | ServiceOutput,  | 
51 | 75 |     ) -> "ServicePortGet":  | 
 | 
0 commit comments