Json schema django rest framework, describe json field as json and not as string
Asked Answered
L

1

8

I have an Api in DRF, describes with swagger. In my serializer i have a field like that :

settings = serializers.DictField(child=serializers.JSONField())

Is it possible that in the swagger.json the field was describe as 'Json' and not as string:

"additionalProperties": {
            "type": "string"
}

but

"additionalProperties": {
        "type": "JSON"
}
Lamartine answered 21/6, 2019 at 9:43 Comment(0)
A
4

Sorry this is not possbile with JSON Schema.

The types are the primitive types allowed by JSON.

Astronavigation answered 26/6, 2019 at 12:18 Comment(3)
Do you now if it's possible to define a custom serializer Field with a custom type ? So I will be able to create a custom JsonField.Lamartine
I need my auto-generated input in my form to be a textarea and not just a text input (which is the input associated with String)...Lamartine
JSON Schema was designed for validating JSON data. If your field is a string encoded JSON (in your JSON), then you could use a regex (pattern keyword) to validate that the string is valid JSON. It would be helpful if you could include example JSON data you want to validate.Astronavigation

© 2022 - 2024 — McMap. All rights reserved.