rdmo icon indicating copy to clipboard operation
rdmo copied to clipboard

Replace `django-rest-swagger` with `drf-spectacular`

Open afuetterer opened this issue 1 year ago • 9 comments

Rationale / Begründung

django-rest-swagger is deprecated since 2019. Should rdmo switch to an alternative openapi library? drf-spectacular looks promising.

Affected

Software group

References / Verweise

  • https://github.com/marcgibbons/django-rest-swagger
  • https://github.com/tfranzel/drf-spectacular

afuetterer avatar Sep 09 '23 11:09 afuetterer

Using django-rest-swagger

image


Using drf-spectacular

  • docs: https://drf-spectacular.readthedocs.io/en/latest/
  • https://drf-spectacular.readthedocs.io/en/latest/faq.html#i-get-a-lot-of-warnings
  • Access http://127.0.0.1:8000/api/v1/ -> Schema (openapi 3.0.3)
  • Access http://127.0.0.1:8000/api/v1/swagger -> Swagger UI
  • Access http://127.0.0.1:8000/api/v1/redoc -> Redoc UI
  • /manage.py spectacular --color --file schema.yml

afuetterer avatar Jul 11 '24 15:07 afuetterer

@jochenklar @MyPyDavid: Do you know, if the swagger UI used or is this just for convenience?

I want to switch out the deprecated library, that generates 100+ warnings when running the tests.

Is it important to generate the exact same UI under the exact same URL?

afuetterer avatar Jul 11 '24 16:07 afuetterer

Hi @afuetterer thanks for the effort! No I don't think we need swagger, I never liked it anyway. But I guess we need something like this, meaning a browsable API explorer thingy.

jochenklar avatar Jul 11 '24 17:07 jochenklar

Alright, thanks.

drf-spectacular generates the openapi schema in json/yaml and renders those in swagger/redoc.

I will submit a PR, then you can test it.

afuetterer avatar Jul 11 '24 19:07 afuetterer

Regarding the versioning here:

There is the RDMO version, e.g. 2.1.3 or 2.2.0, and there is a URL path versioning api/v1/.

What is the difference here?

Is the "version" of the API always "v1"?

afuetterer avatar Jul 12 '24 07:07 afuetterer

Yes, the version is always v1, and its there in case we have another one and need to run them both in parallel. A lot of people say that it is super important to version apis in this way, so I try to do it all the time. An I needed it once.

jochenklar avatar Jul 12 '24 08:07 jochenklar

$ python manage.py spectacular --color --file schema.yml --validate
[...]
Schema generation summary:
Warnings: 237 (109 unique)
Errors:   28 (5 unique)

afuetterer avatar Jul 13 '24 07:07 afuetterer

This is the swagger schema generated by django-rest-swagger: https://github.com/afuetterer/rdmo/blob/698-drf-spectacular/django-rest-swagger.yaml

npx open-swagger-ui --open django-rest-swagger.yaml

afuetterer avatar Jul 13 '24 07:07 afuetterer

What about this repo?

https://github.com/rdmorganiser/rdmo-openapi

afuetterer avatar Jul 13 '24 09:07 afuetterer