Skip to content

Commit

Permalink
http.py: Fix cursor in response and set JSON Response as default (#311)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zrgt authored Oct 14, 2024
1 parent 71a602e commit dfca376
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions basyx/aas/adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def serialize(self, obj: ResponseData, cursor: Optional[int], stripped: bool) ->
data = obj
else:
data = {
"paging_metadata": {"cursor": cursor},
"paging_metadata": {"cursor": str(cursor)},
"result": obj
}
return json.dumps(
Expand Down Expand Up @@ -226,7 +226,7 @@ def get_response_type(request: Request) -> Type[APIResponse]:
"application/xml": XmlResponse,
"text/xml": XmlResponseAlt
}
if len(request.accept_mimetypes) == 0:
if len(request.accept_mimetypes) == 0 or request.accept_mimetypes.best in (None, "*/*"):
return JsonResponse
mime_type = request.accept_mimetypes.best_match(response_types)
if mime_type is None:
Expand Down

0 comments on commit dfca376

Please sign in to comment.