I am working on a custom schema and got an error saying Object of type Boolean is not JSON serializable on the Swagger documentation page.
import coreapi
import coreschema
from rest_framework.schemas import AutoSchema
class CustomSchema(AutoSchema):
def get_manual_fields(self, path, method):
manual_fields = []
if method == "POST":
manual_fields.extend(
[
coreapi.Field(
"custom_field",
required=False,
location="form",
description="custom field",
type=coreschema.Boolean()
)
]
)
return manual_fields
I noticed that using location="query" would not yield the error above, but I need it in the form for Swagger. Is there any workaround? Thanks in advance!
Not necessarily solving the error above, but here's a workaround that worked for the same purpose:
Rather than calling
schema = CustomSchema()from theviews, Call thisCustomSerializerand specify awrite_onlyfield in the serializer automatically populates the Swagger schema for the POST method.