Openapi 3 with Django drf
Asked Answered
H

2

5

I am using Django with Django-Drf to write a restful BE.

I am also using drf-yasg to generate the swagger scheme for my service.

Unfortunately, drf-yasg does not yet support OpenApi3, and it doesn't look like it's going to in the foreseeable future.

Is there an alternative to drf-yasg, that does support Openapi 3 I can use together with Django-Drf?

Heliolatry answered 30/1, 2020 at 17:40 Comment(0)
S
9

Django DRF added OpenAPI3 support recently (3.10 i think), but it lacks a lot of functionality that drf-yasg has. The upcoming version (3.12) will add component support but still misses a lot of features like convenient customization options.

We found ourselves in exactly the same situation. After some serious searching we came up empty and thus created a heavily modified fork of the DRF OpenAPI3 implementation, which is slowly approaching the functionality of drf-yasg.

https://github.com/tfranzel/drf-spectacular

Give it a try. It's still shaping up, but already covers a lot of cases. Feedback is welcome!

Stubbs answered 3/3, 2020 at 0:41 Comment(2)
What features has drf-yasg that drf-spectacular don't?? I've just read the drf-spectacular docs, and in the section "Migrating from drf-yasg", it says that they are both pretty much equivalent.Washedup
@DanielGonzálezFernández some time has passed since my answer. there have been major improvements in drf-spectacular and yasg has no OpenAPI3 support yet. it's not that easy comparing the feature sets. you have to compare yourself whether your requirements are met. (FYI: there is a maintained fork of yasg now: drf-yasg2)Stubbs
C
0

You can create your own html file that will load a yaml or json with openAPI3 support, and publish it via Django.

A ready to use template can be found here: https://github.com/yousan/swagger-yaml-to-html/blob/master/swagger-yaml-to-html.py

basic openAPI template:

openapi: "3.0.0"
info:
    title: MY-Api
    description: My API
    version: 1.0.0
servers:
paths:

Write basic scripts that will propagate changes into the file and you are done.

You will lose automatic schema updates, that are made by DRF, or swagger packages. But you can generate them by using this command.

python manage.py generateschema
Candelabrum answered 8/8, 2022 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.