Use Open API data model
Use Open API data model
Prepare the REST API to Open API (swagger).
To be simple comparison, I migrated bookstore_api project to bookstore_openapi.
What's in the bookstore_openapi project?
Install drf-yasg :
pip install -U drf-yasg
The lastest
djangorestframework
is 3.12, which is not compatible withdrf-yasg
.Make sure you have
pip install djangorestframework==3.11.1
Also check drf-yasg document https://github.com/axnsan12/drf-yasg for how to set up
settings.py
andurls.py
Then copy the whole book models, serializers, api.
Start server. In browser, open
http://127.0.0.1:8000/swagger.yaml
.
Code Generator
https://openapi-generator.tech/ : this is openapi code generator home page,
you may got lost in here.
jar file repository page, to download the latest one. Or in windows, open PowerShell to download it :
Invoke-WebRequest -OutFile swagger-codegen-cli.jar https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar
To use cli
Generate Flask code
Generate nodejs code : use the swagger-codegen-cli.jar.
Generate go code
Actually, [django REST framework support] OpenAPI(https://www.django-rest-framework.org/community/3.10-announcement/); however, the way to download yaml file is odd. Need further investigate.
Last updated