mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
changes http API (reflected in openapi specification)
This commit is contained in:
parent
80243487cb
commit
554d6f7daa
@ -37,14 +37,31 @@ paths:
|
|||||||
readonly: false
|
readonly: false
|
||||||
type: float
|
type: float
|
||||||
value: 12.1
|
value: 12.1
|
||||||
DoesNotExist:
|
'400':
|
||||||
summary: Attribute or does not exist
|
description: Could not get attribute
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/SerializedException'
|
||||||
|
examples:
|
||||||
|
List:
|
||||||
|
summary: List out of index
|
||||||
value:
|
value:
|
||||||
docs: null
|
docs: null
|
||||||
full_access_path: device.channel[0].voltage
|
full_access_path: ""
|
||||||
|
name: SerializationPathError
|
||||||
readonly: false
|
readonly: false
|
||||||
type: "None"
|
type: Exception
|
||||||
value: null
|
value: "Index '2': list index out of range"
|
||||||
|
Attribute:
|
||||||
|
summary: Attribute or dict key does not exist
|
||||||
|
value:
|
||||||
|
docs: null
|
||||||
|
full_access_path: ""
|
||||||
|
name: SerializationPathError
|
||||||
|
readonly: false
|
||||||
|
type: Exception
|
||||||
|
value: "Key 'invalid_attribute': 'invalid_attribute'."
|
||||||
/api/v1/update_value:
|
/api/v1/update_value:
|
||||||
put:
|
put:
|
||||||
tags:
|
tags:
|
||||||
@ -79,7 +96,7 @@ paths:
|
|||||||
type: Exception
|
type: Exception
|
||||||
value: "Index '2': list index out of range"
|
value: "Index '2': list index out of range"
|
||||||
Attribute:
|
Attribute:
|
||||||
summary: Attribute or does not exist
|
summary: Attribute does not exist
|
||||||
value:
|
value:
|
||||||
docs: null
|
docs: null
|
||||||
full_access_path: ""
|
full_access_path: ""
|
||||||
|
@ -19,6 +19,9 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
API_VERSION = "v1"
|
API_VERSION = "v1"
|
||||||
|
|
||||||
|
STATUS_OK = 200
|
||||||
|
STATUS_FAILED = 400
|
||||||
|
|
||||||
|
|
||||||
def create_api_application(state_manager: StateManager) -> aiohttp.web.Application:
|
def create_api_application(state_manager: StateManager) -> aiohttp.web.Application:
|
||||||
api_application = aiohttp.web.Application(
|
api_application = aiohttp.web.Application(
|
||||||
@ -30,12 +33,14 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
|
|
||||||
access_path = request.rel_url.query["access_path"]
|
access_path = request.rel_url.query["access_path"]
|
||||||
|
|
||||||
|
status = STATUS_OK
|
||||||
try:
|
try:
|
||||||
result = get_value(state_manager, access_path)
|
result = get_value(state_manager, access_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
result = dump(e)
|
result = dump(e)
|
||||||
return aiohttp.web.json_response(result)
|
status = STATUS_FAILED
|
||||||
|
return aiohttp.web.json_response(result, status=status)
|
||||||
|
|
||||||
async def _update_value(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def _update_value(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
data: UpdateDict = await request.json()
|
data: UpdateDict = await request.json()
|
||||||
@ -46,7 +51,7 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
return aiohttp.web.json_response()
|
return aiohttp.web.json_response()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return aiohttp.web.json_response(dump(e), status=400)
|
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
||||||
|
|
||||||
async def _trigger_method(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
async def _trigger_method(request: aiohttp.web.Request) -> aiohttp.web.Response:
|
||||||
data: TriggerMethodDict = await request.json()
|
data: TriggerMethodDict = await request.json()
|
||||||
@ -56,7 +61,7 @@ def create_api_application(state_manager: StateManager) -> aiohttp.web.Applicati
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return aiohttp.web.json_response(dump(e))
|
return aiohttp.web.json_response(dump(e), status=STATUS_FAILED)
|
||||||
|
|
||||||
api_application.router.add_get("/get_value", _get_value)
|
api_application.router.add_get("/get_value", _get_value)
|
||||||
api_application.router.add_post("/update_value", _update_value)
|
api_application.router.add_post("/update_value", _update_value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user