By default, when using drf-spectacular
to generate the OpenAPI schema, the JSONField will be typed as object
or array
. However, I have a JSON Field which is validated against a JSON Schema and I'd like this JSON Schema to be included on the OpenAPI schema.
I couldn't find this specific scenario described on the docs of drf-spectacular
, but however, I tried modifying it using @extend_schema
but with no success.
The model looks like this:
Car(models.Model):
name = models.CharField()
data = models.JSONField("Car Data", validators=[JSONSchemaValidator(limit_value=my_schema)])
On the generated OpenAPI schema, this is represented as:
data:
type: object
additionalProperties: {}
nullable: true
title: Car Data
I'm not including a sample on how it should look because I'm seeking answers where this is possible in some pre-defined way.