Skip to content

Commit dfca376

Browse files
authored
http.py: Fix cursor in response and set JSON Response as default (#311)
Previously, our `cursor` in a http response was an integer (as it is a number). The specification asks however for this attribute ot be a string. Therefore, we adapt the type. Fixes #309 Previously, we returned XML by default, if the `accept_mimetypes` had `*/*` in it. This is non- compliant to the specification, which expects JSON to be returned. We fix the issue to return JSON by default now instead. Fixes #310
1 parent 71a602e commit dfca376

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

basyx/aas/adapter/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def serialize(self, obj: ResponseData, cursor: Optional[int], stripped: bool) ->
149149
data = obj
150150
else:
151151
data = {
152-
"paging_metadata": {"cursor": cursor},
152+
"paging_metadata": {"cursor": str(cursor)},
153153
"result": obj
154154
}
155155
return json.dumps(
@@ -226,7 +226,7 @@ def get_response_type(request: Request) -> Type[APIResponse]:
226226
"application/xml": XmlResponse,
227227
"text/xml": XmlResponseAlt
228228
}
229-
if len(request.accept_mimetypes) == 0:
229+
if len(request.accept_mimetypes) == 0 or request.accept_mimetypes.best in (None, "*/*"):
230230
return JsonResponse
231231
mime_type = request.accept_mimetypes.best_match(response_types)
232232
if mime_type is None:

0 commit comments

Comments
 (0)