OpenAPI Schema generation missing titlte

46 views
Skip to first unread message

Dan Davis

unread,
Aug 28, 2017, 5:42:55 PM8/28/17
to Django REST framework
Hi guys, 

I'm trying to understand what I would need to do to get the schema generation to include verbose_name from my model or a label from a serializer form.  I'm converting the schema all the way through to to try to drive a React schema-driven form using the javascript package reach-jsonschema-form, playground for which is https://mozilla-services.github.io/react-jsonschema-form/.

However, the OpenAPI schema generated does not include a label for a field, whether I specify it as the verbose_name on my model, or as the label on Serializer.   

I've tried to look at the CoreAPI intermediate form, for which I post the following:

Field(name='barcode', required=True, location='form', schema=<coreschema.schemas.String object at 0x00000000075CF630>, description=None, type=None, example=None)
Field(name='universal_sequence', required=True, location='form', schema=<coreschema.schemas.String object at 0x00000000075CF7F0>, description=None, type=None, example=None)
Field(name='index_sequence', required=True, location='form', schema=<coreschema.schemas.String object at 0x00000000075CF8D0>, description=None, type=None, example=None)
Field(name='full_sequence', required=True, location='form', schema=<coreschema.schemas.String object at 0x00000000075CF908>, description=None, type=None, example=None)
Field(name='index_type', required=True, location='form', schema=<coreschema.schemas.Enum object at 0x00000000075CF898>, description=None, type=None, example=None)

You can see some of the Python from which I produced this brief result in a Gist - https://gist.github.com/danizen/6f441f575d04258329d65ba25ec2ea74



I'm posting here because I've eliminated django-rest-swagger from the tools - the API is using purely Django rest framework, with a custom renderer based on the openapi_codec package, as shown in the Django Rest Framework documentation.   I've come a long way in understanding how CoreAPI is an sometimes internal view, but a schema view can be made external.   I've made that an operation on a ViewSet so that it can be browsed through the API explorer itself.

The problem here is getting it to include the title for a form...

Dan Davis

unread,
Aug 29, 2017, 2:00:04 PM8/29/17
to Django REST framework
I've now discovered that either verbose_name or label automatic flow through to the label, when looking at the Metadata using the SimpleMetadata:

  "actions": {
    "POST": {
      "user": {
        "label": "User",
        "type": "field",
        "read_only": false,
        "required": true
      },
      "vendor": {
        "max_length": 100,
        "required": true,
        "label": "Vendor",
        "type": "string",
        "help_text": "Vendor of NGS adapter kit",
        "read_only": false
      },
      "version": {
        "label": "Version",
        "type": "string",
        "read_only": false,
        "max_length": 100,
        "required": true
      },
      "kit": {
        "label": "Adapter Kit",
        "type": "string",
        "read_only": false,
        "max_length": 100,
        "required": true
      },
      "subkit": {
        "label": "Adapter Subkit",
        "type": "string",
        "read_only": false,
        "required": true
      },
      "id": {
        "label": "ID",
        "type": "integer",
        "read_only": true,
        "required": false
      }
    }
 
Perhaps this turns this into an exercise for me to write my own metadata class to return JSON schema, and maybe that already exists elsewhere and I will find it.

Reply all
Reply to author
Forward
0 new messages