defectdojo_api icon indicating copy to clipboard operation
defectdojo_api copied to clipboard

[Proposal] Use swagger-codegen to generate wrapper api

Open edersonbrilhante opened this issue 5 years ago • 6 comments

Description

I am using [swagger-codegen] (https://github.com/swagger-api/swagger-codegen) to generate a better mirror of defectdojo API.

This way it is not needed to add manually new paths, actions, payload, etc It is needed just to run swagger-codegen using the latest version of swagger file provided by defectdojo in /api/v2/doc/?format=openapi

Example

Here is my project running with this purpose https://github.com/William-Hill-Online/defectdojo-api-swagger

edersonbrilhante avatar Jun 03 '20 16:06 edersonbrilhante

I think it's a great idea, but haven't looked yet into the details if it supports all operations. Not sure if everything is in the swagger spec. I remember when browsing the swagger docs on defect dojo some api features are not there.

valentijnscholten avatar Jun 03 '20 17:06 valentijnscholten

Indeed, but I downloaded with curl using token in headers, so I got details that was not available with the browser

curl -X GET  '<endpoint>/api/v2/doc/?format=openapi'  -H 'Authorization: Token<token>' 

edersonbrilhante avatar Jun 03 '20 19:06 edersonbrilhante

If the swagger is well configured in django-DefectDojo/dojo/api_v2/views.py I think it will not be a problem.

I saw some methods(@action) in ViewSet without swagger_auto_schema, so there are responses and request_bodys wrong. Example: api/v2/finding/ = are ok api/v2/finding//notes/ = are wrong We fixing that, I think all operations will work

edersonbrilhante avatar Jun 03 '20 20:06 edersonbrilhante

Hi @valentijnscholten I fixed here https://github.com/DefectDojo/django-DefectDojo/pull/2488

edersonbrilhante avatar Jun 05 '20 13:06 edersonbrilhante

I created a similar project a while ago: https://github.com/alles-klar/defectdojo-api-v2-client. Generally it works fine but there are some bugs in the defectdojo swagger documentation. So for a stable api client we need to write a lot of tests. @edersonbrilhante do you have an idea how to automatically generate tests?

alles-klar avatar Jun 06 '20 16:06 alles-klar

@alles-klar My PR fixing some bugs defectdojo swagger documentation was merged to dev. I am not sure about these tests.

edersonbrilhante avatar Jun 10 '20 12:06 edersonbrilhante