You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Our API is using the Accept HTTP header not only to change the format (csv, xml, json) of the response but the type of objects returned. This is useful for us since we have multiple flavor of a same object type. For example our object being a product it can be returned into its json structured label format or as a json flat key-value pair format or csv. We use the HTTP Accept header to request the different flavor of the objects. We use to be able to do these requests with the python language generator, using the argument accept_content_types for example: https://github.com/NASA-PDS/pds-api-client/blob/77846d343f3dd6f5dcde060f1ffc43ea9f926d7c/src/pds/api_client/test/integration/test_collections.py#L71:L73
The response was in returning the appropriate object type, as defined in the API specification.
With the python-nextgen generator, which is much better regarding the explicit prototype of the methods generated, I cannot get the objects described in the specification but only a dictionary object and the application/json Accept header is always used to do the server request.
Could we have the flexibility we used to have regarding the response format returned ? I made some tests adding the _header argument to the API calls, but the values get overridden. See below.
from __future__ importprint_functionfrompds.api_client.restimportApiExceptionfrompds.api_clientimportConfigurationfrompds.api_clientimportApiClientfrompds.api_client.api.all_products_apiimportAllProductsApifrompprintimportpprint# create an instance of the API classconfiguration=Configuration()
configuration.host='https://pds.nasa.gov/api/search/1'api_client=ApiClient(configuration)
all_products=AllProductsApi(api_client)
try:
# see ref doc onapi_response=all_products.select_by_lidvid_with_http_info(
'urn:nasa:pds:mars2020.spice:spice_kernels::3.0',
_headers={'Accept': 'application/vnd.nasa.pds.pds4+json'}
)
pprint(api_response['summary'])
exceptApiExceptionase:
print("Exception when calling CollectionsApi->get_collection: %s\n"%e)
The _headers Accept parameter is changed to application/json before the request is sent to the server.
The reponse to the request is always a dict instead of the objects defined in the OpenAPI specification.
Related issues/PRs
Suggest a fix
In the generated code we get in classes in the api subpackage:
...
# set the HTTP header `Accept`# Accept header can be passed in api call, for example:# api_response = all_products.select_by_lidvid_with_http_info(# 'urn:nasa:pds:mars2020.spice:spice_kernels::3.0',# _headers={'Accept': 'application/vnd.nasa.pds.pds4+json'}# )ifnot'Accept'in_header_params:
_header_params['Accept'] =self.api_client.select_header_accept(
['*/*', 'application/csv', 'application/json', 'application/kvp+json', 'application/vnd.nasa.pds.pds4+json', 'application/vnd.nasa.pds.pds4+xml', 'application/xml', 'text/csv', 'text/html', 'text/xml']) # noqa: E501# authentication setting_auth_settings= [] # noqa: E501# the 200 object depends on the Accept header value# and can be found from the OPENAPI specification used as input# See for example https://github.com/NASA-PDS/pds-api/blob/main/specs/PDS_APIs-search-1.1.1-swagger.yaml#L1251:L1286_response_types_map= {
'200': get_subtype_map(
'Plural', # super type used as a generic type for multiple Accept header values_header_params['Accept']
),
'400': "ErrorMessage",
'404': "ErrorMessage",
'500': "ErrorMessage",
'501': "ErrorMessage",
}
...
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Our API is using the
Accept
HTTP header not only to change the format (csv, xml, json) of the response but the type of objects returned. This is useful for us since we have multiple flavor of a same object type. For example our object being aproduct
it can be returned into itsjson structured label format
or as ajson flat key-value pair format
orcsv
. We use the HTTPAccept
header to request the different flavor of the objects. We use to be able to do these requests with thepython
language generator, using the argumentaccept_content_types
for example: https://github.com/NASA-PDS/pds-api-client/blob/77846d343f3dd6f5dcde060f1ffc43ea9f926d7c/src/pds/api_client/test/integration/test_collections.py#L71:L73The response was in returning the appropriate object type, as defined in the API specification.
With the
python-nextgen
generator, which is much better regarding the explicit prototype of the methods generated, I cannot get the objects described in the specification but only a dictionary object and theapplication/json
Accept header is always used to do the server request.Could we have the flexibility we used to have regarding the response format returned ? I made some tests adding the _header argument to the API calls, but the values get overridden. See below.
openapi-generator version
6.5.0, python-nextgen
OpenAPI declaration file content or url
https://raw.githubusercontent.com/NASA-PDS/pds-api/main/specs/PDS_APIs-search-1.1.1-swagger.yaml
Generation Details
Code generated with command:
openapi-generator generate -g python-nextgen -i {yaml openapi input file} --package-name pds.api_client --additional-properties=packageVersion=1.2.0'
Steps to reproduce
Running the python code using the generated code:
The _headers Accept parameter is changed to
application/json
before the request is sent to the server.The reponse to the request is always a dict instead of the objects defined in the OpenAPI specification.
Related issues/PRs
Suggest a fix
In the generated code we get in classes in the
api
subpackage:We need these fix:
The text was updated successfully, but these errors were encountered: