@@ -1,12 +1,11 @@
|
||||
import inspect
|
||||
import logging
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from rest_framework import serializers
|
||||
from rest_framework.utils import encoders, json
|
||||
|
||||
from .. import openapi
|
||||
from ..utils import decimal_as_float, is_list_view
|
||||
from ..utils import decimal_as_float, force_real_str, is_list_view
|
||||
|
||||
#: Sentinel value that inspectors must return to signal that they do not know how to handle an object
|
||||
NotHandled = object()
|
||||
@@ -196,9 +195,9 @@ class FieldInspector(BaseInspector):
|
||||
"""
|
||||
assert swagger_object_type in (openapi.Schema, openapi.Parameter, openapi.Items)
|
||||
assert not isinstance(field, openapi.SwaggerDict), "passed field is already a SwaggerDict object"
|
||||
title = force_text(field.label) if field.label else None
|
||||
title = force_real_str(field.label) if field.label else None
|
||||
title = title if swagger_object_type == openapi.Schema else None # only Schema has title
|
||||
description = force_text(field.help_text) if field.help_text else None
|
||||
description = force_real_str(field.help_text) if field.help_text else None
|
||||
description = description if swagger_object_type != openapi.Items else None # Items has no description either
|
||||
|
||||
def SwaggerType(existing_object=None, **instance_kwargs):
|
||||
|
||||
@@ -3,6 +3,8 @@ from collections import OrderedDict
|
||||
import coreschema
|
||||
from rest_framework.pagination import CursorPagination, LimitOffsetPagination, PageNumberPagination
|
||||
|
||||
from drf_yasg.utils import force_real_str
|
||||
|
||||
from .. import openapi
|
||||
from .base import FilterInspector, PaginatorInspector
|
||||
|
||||
@@ -48,7 +50,7 @@ class CoreAPICompatInspector(PaginatorInspector, FilterInspector):
|
||||
in_=location_to_in[field.location],
|
||||
type=coreapi_types.get(type(field.schema), openapi.TYPE_STRING),
|
||||
required=field.required,
|
||||
description=field.schema.description if field.schema else None,
|
||||
description=force_real_str(field.schema.description) if field.schema else None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from rest_framework.status import is_success
|
||||
from .. import openapi
|
||||
from ..errors import SwaggerGenerationError
|
||||
from ..utils import (
|
||||
force_serializer_instance, get_consumes, get_produces, guess_response_status, is_list_view, no_body,
|
||||
force_real_str, force_serializer_instance, get_consumes, get_produces, guess_response_status, is_list_view, no_body,
|
||||
param_list_to_odict
|
||||
)
|
||||
from .base import ViewInspector
|
||||
@@ -42,7 +42,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
|
||||
return openapi.Operation(
|
||||
operation_id=operation_id,
|
||||
description=description,
|
||||
description=force_real_str(description),
|
||||
responses=responses,
|
||||
parameters=parameters,
|
||||
consumes=consumes,
|
||||
@@ -246,7 +246,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
for sc, serializer in response_serializers.items():
|
||||
if isinstance(serializer, str):
|
||||
response = openapi.Response(
|
||||
description=serializer
|
||||
description=force_real_str(serializer)
|
||||
)
|
||||
elif not serializer:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user