django-rest-swagger
django-rest-swagger copied to clipboard
swagger version 2 serializer fields
Using swagger v2 is it possible to get DRF ChoiceField and FileField serializer fields to be recognised in the django-rest-swagger (SwaggerUIRenderer) interface? These are just being displayed as 'formData' parameter types and 'string' data types at the moment via the rest_framework.schemas.SchemaGenerator(). (With the older swagger versions we just used 'enum' and 'file' in the YAML).
Also I haven't found how to get the description to be added - I tried 'help_text' and 'label' on the serializer fields.
It would be great to have documentation on transferring to swagger v2 from previous versions. Thanks.
Improved usage documentation is being tracked with https://github.com/marcgibbons/django-rest-swagger/issues/485.
It would be great to have documentation on transferring to swagger v2 from previous versions.
Unfortunately, I think this is going to have to be 'best effort' for everyone.
As described in the release notes:
Version 2.0 is fundamentally different from previous versions
If you can translate this issue into a clearer example of your problem, it would be more helpful.
@tcarver Thanks for the message. The v2 is a major change from previous versions as now, the schema is being generated by DRF and CoreAPI. Currently, the only type is string, though this is still undergoing development, and certainly typing is a requested feature.
As for descriptions, these will also be coming from the Django REST Framework schema generator (which I don't think is implemented yet).
@lwm thanks for pointing to the tracked issue for improved documentation. Essentially the serializers I am using are as follows:
store_data = serializers.CharField(')
fruit = serializers.ChoiceField(choices=['Apple', 'Banana', 'Orange'],
default='Apple', help_text="Fruit selection")
Previous swagger versions made use of the following YAML parameters to provide file and dropdown options for these:
parameters:
- name: store_data
description: store data file
type: file
required: true
- name: freq
description: frequency
required: true
type: string
paramType: form
defaultValue: 'Apple'
enum: ['Apple', 'Banana', 'Orange']
@marcgibbons thanks that is really good to know. Do you happen to know when typing may become available in DRF/CoreAPI?
@tcarver Not sure. Will ping @tomchristie
+1 for this feature. We're unable to use the latest version without more control of the generated swagger spec.
Noted. On the feature list.
Tracking this here: https://github.com/tomchristie/django-rest-framework/issues/4384
Since https://github.com/tomchristie/django-rest-framework/issues/4384 is closed does that mean it should work on rest swagger side @marcgibbons ?
I'm only seeing model as string instead of choices
Thanks
Hi @tomchristie, @marcgibbons,
Is there any updates on the issue as pointed by @tcarver please. (DRF ChoiceField and FileField serializer fields to be recognised in the django-rest-swagger)
Thank you,
Also interested in this feature so I took a peak at the current state of things. DRF defines a class for generating the coreapi schema: rest_framework.schemas.SchemaGenerator
. It seems this is responsible for treating foreignkeys as strings: https://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/inspectors.py#L51 . Looks like choice field works. It is using a package called coreschema
which offers a Ref
type which may be preferable: https://github.com/core-api/python-coreschema/blob/master/coreschema/encodings/jsonschema.py
I am using customized SchemaGenerator class for my swagger, which helps me include YAML for APIs with type:file, as here : https://github.com/m-haziq/django-rest-swagger-docs#advance-usage It may seem a bit hacky but working fine for me.
@pavillet did you get the issue of "string" resolved?
Am running version 2.1.2 and still getting all fields as "string"...