mediacms-io / mediacms

MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API.
https://mediacms.io
GNU Affero General Public License v3.0
2.67k stars 495 forks source link

Swagger Doc/API Implementation is not correct. Response definition in API Doc is not the response the server produces. #342

Closed tschig closed 1 year ago

tschig commented 2 years ago

Describe the issue Example: Lists all media GET /media Response says it will respond with an array of medias, but in reality the server response with an object that includes meta data and a result key with the actual response array.

Why is this a problem? When we generate a java SDK with swagger codegen, the generated client expects an array, but an object is returned and therefore the deserialization process fails.

To Reproduce Steps to reproduce the issue:

  1. Upload Media im MediaCMS
  2. Generate OpenApi SDK from Swagger Doc( https://demo.mediacms.io/swagger/?format=openapi )
  3. Request API via SDK from own Code
  4. Failes to deserialize because object is root element and not an array as specified in swagger doc.

Expected behavior Either: Swagger Doc is adapted so that the correct response is specified. Or: Server returns Specified response (Array of media)

Additional context

Response from Server:

{ "count": 2, "next": null, "previous": null, "results": [{ "friendly_token": "YYaqvegif", "url": "http://localhost:8085/view?m=YYaqvegif", "api_url": "http://localhost:8085/api/v1/media/YYaqvegif", "user": "admin", "title": "sample-30s.mp4", "description": "", "add_date": "2021-12-08T22:10:38.366957Z", "views": 1, "media_type": "video", "state": "public", "duration": 30, "thumbnail_url": "http://localhost:8085/media/original/thumbnails/user/admin/edfa4573b6e44db6b09c3439cf350a5e.sample-30s.mp4_WMW6Ptk.jpg", "is_reviewed": true, "preview_url": "/media/encoded/1/admin/edfa4573b6e44db6b09c3439cf350a5e.tmp6t4vnujz.gif", "author_name": "", "author_profile": "http://localhost:8085/user/admin/", "author_thumbnail": "http://localhost:8085/media/userlogos/user.jpg", "encoding_status": "success", "likes": 1, "dislikes": 0, "reported_times": 0, "featured": false, "user_featured": false, "size": "21.7MB" }, { "friendly_token": "13X4LkkZz", "url": "http://localhost:8085/view?m=13X4LkkZz", "api_url": "http://localhost:8085/api/v1/media/13X4LkkZz", "user": "admin", "title": "video.mp4", "description": "", "add_date": "2021-11-06T11:31:09.163659Z", "views": 4, "media_type": "video", "state": "public", "duration": 30, "thumbnail_url": "http://localhost:8085/media/original/thumbnails/user/admin/79a2f20b25c04659af89b4a88543fdbd.video.mp4_TYueEHf.jpg", "is_reviewed": true, "preview_url": "/media/encoded/1/admin/79a2f20b25c04659af89b4a88543fdbd.tmpc9_4r66t.gif", "author_name": "", "author_profile": "http://localhost:8085/user/admin/", "author_thumbnail": "http://localhost:8085/media/userlogos/user.jpg", "encoding_status": "success", "likes": 2, "dislikes": 0, "reported_times": 0, "featured": false, "user_featured": false, "size": "17.8MB" } ] }

Example/spec in swagger:

[ { "friendly_token": "string", "url": "string", "api_url": "string", "user": "string", "title": "string", "description": "string", "add_date": "2021-12-09T09:09:01.266Z", "views": 0, "media_type": "video", "state": "private", "duration": 0, "thumbnail_url": "string", "is_reviewed": true, "preview_url": "string", "author_name": "string", "author_profile": "string", "author_thumbnail": "string", "encoding_status": "pending", "likes": 0, "dislikes": 0, "reported_times": 0, "featured": true, "user_featured": true, "size": "string" } ]

mgogoulos commented 2 years ago

Thanks for opening this, not sure I understand the issue (or have a solution in mind) but should be handled

tschig commented 2 years ago

The issue: API Specification (swagger) and API Implementation are different. Possible Solution: Generate API Specification automatically from the Implementation code.

mgogoulos commented 1 year ago

Closing as there is another ticket to fix the API Docs