Skip to content

Commit

Permalink
[VNG-Realisatie#222] show available parsers in Content-Type header …
Browse files Browse the repository at this point in the history
…enum

Renderers are used for the output
  • Loading branch information
Sonny Bakker committed Sep 23, 2022
1 parent 073fb9b commit 0e68656
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions tests/test_content_type_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
Test that the required content type headers are present.
"""
from django.urls import path
from django.utils.translation import gettext_lazy as _

from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter
from rest_framework.parsers import JSONParser, MultiPartParser
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
Expand Down Expand Up @@ -64,17 +61,16 @@ def test_json_content_type():
def test_multipart_content_type():
schema = _generate_schema()

get_operation = schema.paths["/multipart"]["get"]
post_operation = schema.paths["/multipart"]["post"]
get_operation = schema["paths"]["/multipart"]["get"]
post_operation = schema["paths"]["/multipart"]["post"]

assert get_operation["parameters"] == []
assert "parameters" not in get_operation
assert post_operation["parameters"] == [
OpenApiParameter(
name="Content-Type",
location=OpenApiParameter.HEADER,
type=OpenApiTypes.STR,
required=True,
enum=["multipart/form-data"],
description=_("Content type of the request body."),
)
{
"description": "Content type of the request body.",
"in": "header",
"name": "Content-Type",
"required": True,
"schema": {"enum": ["multipart/form-data"], "type": "string"},
}
]
2 changes: 1 addition & 1 deletion vng_api_common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def get_request_parameters(self):
type=OpenApiTypes.STR,
location=OpenApiParameter.HEADER,
required=True,
enum=self.map_renderers("media_type"),
enum=self.map_parsers(),
description=_("Content type of the request body."),
)
]
Expand Down

0 comments on commit 0e68656

Please sign in to comment.