Asset Connector Documentation
Loading...
Searching...
No Matches
response_body.py
Go to the documentation of this file.
1
"""Defines the ResponseBody model and related utilities for HTTP response handling.
2
3
This module provides:
4
- ResponseBody: a Pydantic model for HTTP responses;
5
- create_response: a helper function to create ResponseBody instances.
6
"""
7
8
import
json
9
from
typing
import
Any, ClassVar
10
11
from
basyx.aas.adapter.json
import
AASToJsonEncoder
12
from
basyx.aas.model
import
ModelReference
as
Reference
13
from
basyx.aas.model
import
Submodel
14
from
pydantic
import
BaseModel, Field
15
16
17
class
ResponseBody
(BaseModel):
# noqa: D101
18
status_code: int = Field(
19
default=200,
20
description=
"The HTTP status code of the response."
,
21
alias=
"StatusCode"
,
22
example=200,
23
)
24
25
message: str = Field(
26
default=
"Successfully"
,
27
description=
"A message providing additional information about the response."
,
28
alias=
"Message"
,
29
example=
"Successfully invoked `/set-config` with raw JSON in payload"
,
30
)
31
32
payload: Any = Field(
33
default={},
34
description=
"Json content of the response."
,
35
alias=
"Payload"
,
36
example=
""
,
37
)
38
39
value: str = Field(
40
default=
""
,
41
description=
"The value returned by the operation, if applicable."
,
42
alias=
"Value"
,
43
example=
"myResult"
,
44
)
45
46
class
Config
:
# noqa: D106
47
arbitrary_types_allowed =
True
48
json_encoders: ClassVar = {Reference:
lambda
v: json.dumps(v, cls=AASToJsonEncoder), Submodel:
lambda
v: json.dumps(v, cls=AASToJsonEncoder)}
49
50
51
def
create_response(status_code: int, message: str, payload: str =
"{}"
, value: str =
""
) -> ResponseBody:
52
"""
53
Create a ResponseBody instance with the given parameters.
54
55
:param status_code: The HTTP status code of the response.
56
:param message: A message providing additional information about the response.
57
:param payload: Json content of the response.
58
:param value: The value returned by the operation, if applicable.
59
:return: An instance of ResponseBody.
60
"""
61
body =
ResponseBody
()
62
body.status_code = status_code
63
body.message = message
64
body.payload = payload
65
body.value = value
66
67
return
body
response_body.ResponseBody.Config
Definition
response_body.py:46
response_body.ResponseBody
Definition
response_body.py:17
python_connector
models
response_body.py
Generated by
1.9.8