django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

swagger version 2 serializer fields

Open tcarver opened this issue 7 years ago • 13 comments

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.

tcarver avatar Jul 19 '16 11:07 tcarver

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.

decentral1se avatar Jul 19 '16 12:07 decentral1se

@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).

marcgibbons avatar Jul 19 '16 12:07 marcgibbons

@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']

tcarver avatar Jul 19 '16 12:07 tcarver

@marcgibbons thanks that is really good to know. Do you happen to know when typing may become available in DRF/CoreAPI?

tcarver avatar Jul 19 '16 12:07 tcarver

@tcarver Not sure. Will ping @tomchristie

marcgibbons avatar Jul 19 '16 21:07 marcgibbons

+1 for this feature. We're unable to use the latest version without more control of the generated swagger spec.

jmhobrien avatar Jul 27 '16 04:07 jmhobrien

Noted. On the feature list.

tomchristie avatar Jul 27 '16 09:07 tomchristie

Tracking this here: https://github.com/tomchristie/django-rest-framework/issues/4384

tomchristie avatar Aug 11 '16 10:08 tomchristie

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 capture d ecran 2017-01-17 a 11 38 42

Thanks

pavillet avatar Jan 17 '17 10:01 pavillet

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,

premanand17 avatar May 11 '17 14:05 premanand17

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

zbyte64 avatar Oct 14 '17 01:10 zbyte64

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.

m-haziq avatar Nov 13 '17 06:11 m-haziq

@pavillet did you get the issue of "string" resolved?

Am running version 2.1.2 and still getting all fields as "string"...

lukik avatar Feb 08 '18 08:02 lukik