Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

How to force a DictField to be documented as an object, not a string? #568

Closed
tardate opened this issue Oct 19, 2016 · 1 comment
Closed

Comments

@tardate
Copy link

tardate commented Oct 19, 2016

When passing a dict/hash of arbitrary data in an API, we're using DictField (same applies for JSONField). A good example is an errors collection, where we really don't want to define a serializer with all the possible elements it may contain. So we declare like this:

class CustomSerializer(serializers.Serializer):
    errors = serializers.DictField(
        required=False, help_text="Error conditions, if any"
    )

The problem is this shows up in the swagger UI as a string:

CustomSerializer {
  errors (string): Error conditions, if any
}

Likewise in swagger doc:

"CustomSerializer": {
  "required": [
    "errors"
  ],
  "id": "CustomSerializer",
  "properties": {
    "errors": {
      "description": "Error conditions, if any",
      "required": false,
      "readOnly": false,
      "type": "string"
    }
  }
},

This is causing problems for API clients that are attempting to introspect on the basis of the swagger doc. Is there a way to define these elements better - at least not have them declared as a string? Am I missing something obvious?

Note we are still on 0.3.x branch (0.3.10)

@marcgibbons
Copy link
Owner

Unfortunately this is not supported in the 0.3.x., but is now possible in the latest version

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants