-
-
Notifications
You must be signed in to change notification settings - Fork 263
Help with weird Siemens Polarion endpoints #1196
-
I'm further struggling with the Siemens Polarion REST API, which seems to be not perfectly specified and need your expert opinion.
Here's the API specification to play around, the test drive server is open, although Polarion itself is not. You may need to register and generate an API key to run queries: https://testdrive.polarion.com/polarion/rest/v1
What puzzles me is the GET /projects/{projectId}/workitems endpoint's field item. It is defined as a SparseFields object, which should look like this:
{
"categories": "@all",
"documents": "@all",
...
}
When I click "Try it out", this translates to https://testdrive.polarion.com/polarion/rest/v1/projects/testproj/workitems?fields[categories]=@all&fields[documents]=@all. This seems strange query format, is this universally accepted?
The generated python client expects a SparseFields object that gets sent to the httpx request with to_dict() and each field is treated as an individual query parameter. When I call wil : workitems_list_get_response.WorkitemsListGetResponse = get_work_items.sync_detailed(client=client, project_id="testproj", fields=SparseFields(categories="@all", documents="@all")) this URL is requested: https://testdrive.polarion.com/polarion/rest/v1/projects/testproj/workitems?categories=@all&documents=@all')
I resolved it by patching get_work_items._get_kwargs() like this:
json_fields: Union[Unset, dict[str, Any]] = UNSET
if not isinstance(fields, Unset):
json_fields = fields.to_dict()
if not isinstance(json_fields, Unset):
f = {}
for k, v in json_fields.items():
f[f"fields[{k}]"]=v
params.update(f)
Is there anything better I colud do?
Am I misunderstading how to use the endpoint?
Or is it really weirdly coded?
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I actually patched the SparseFields model, as it is used in all GET tequests, but I'm still wondering if that's right.
Beta Was this translation helpful? Give feedback.