Skip to content

Commit 883b9a0

Browse files
IgnacioHerediaalvarolopez
authored andcommitted
fix default content type management
- do not automatically add application/json to the content-type list for modules that already provide an accept arg with possible content-types - use the first possible content-type choice as default if no default has been provided
1 parent a83f481 commit 883b9a0

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

deepaas/api/v2/predict.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from aiohttp import web
1818
import aiohttp_apispec
19+
import marshmallow
1920
from webargs import aiohttpparser
2021
import webargs.core
2122

@@ -36,11 +37,11 @@ def _get_model_response(model_name, model_obj):
3637
def _get_handler(model_name, model_obj):
3738
aux = model_obj.get_predict_args()
3839
accept = aux.get("accept", None)
39-
if accept and "application/json" not in accept.validate.choices:
40-
accept.validate.choices.insert(0, "application/json")
40+
if accept:
4141
accept.validate.choices.append("*/*")
42-
accept.default = "application/json"
43-
accept.missing = "application/json"
42+
# If no default value use first possible choice:
43+
if isinstance(accept.missing, marshmallow.utils._Missing):
44+
accept.missing = accept.validate.choices[0]
4445
accept.location = "headers"
4546

4647
handler_args = webargs.core.dict2schema(aux)

doc/source/user/v2-api.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ string, and will be returned in the following JSON response::
156156
"predictions": "<model response as string>"
157157
}
158158

159-
However, it is reccomended that you specify a custom custom response schema.
159+
However, it is recommended that you specify a custom response schema.
160160
This way the API exposed will be richer and it will be easier for developers to
161161
build applications against your API, as they will be able to discover the
162162
response schemas from your endpoints.
@@ -255,15 +255,9 @@ types that you are able to return as follows::
255255
validate=validate.OneOf(["text/plain"]),
256256
}
257257

258-
Consequantly, the predict calls will receive an ``accept`` argument containing
259-
the content type requested by the user.
260-
261-
.. important:: Please be aware the the JSON content type (i.e.
262-
``application/json``) must be always supported and it will be defined and
263-
presented to the user even if you do not define it in your ``accept``
264-
argument. This means that if you do not receive an accept argument, or the
265-
accept argument is empty you **must** return content that can be redered as
266-
a JSON following the schema definition described above.
258+
Consequently, the predict calls will receive an ``accept`` argument containing
259+
the content type requested by the user. Find `here <https://www.iana.org/assignments/media-types/media-types.xhtml>`_
260+
a comprehensive list of possible content types.
267261

268262
Using classes
269263
-------------

0 commit comments

Comments
 (0)