Mailu / Mailu

Insular email distribution - mail server as Docker images
https://mailu.io
Other
5.75k stars 824 forks source link

Wrong schema for certain api endpoints in swagger docs #3113

Closed d-Rickyy-b closed 6 months ago

d-Rickyy-b commented 8 months ago

Environment & Version

Description

I am currently trying out the mailu rest API and I found that the generated swagger.json file doesn't seem to be correct. For the endpoint GET /alias/destination/{domain} the response type is of the type

"schema": {
    "$ref": "#/definitions/Alias"
}

For the endpoint GET /alias/ the response type is:

"schema": {
    "type": "array",
    "items": {
        "$ref": "#/definitions/Alias"
    }
}

Clearly both api endpoints can return multiple aliases. Still only GET /alias/ (per definition) returns an array and GET /alias/destination/{domain} should only return a single alias. This is of course not the case as both return arrays.

I assume the get function lacks the decorator @alias.doc('list_alias'):

https://github.com/Mailu/Mailu/blob/cc59be41e15c085270b52f49739398236c131827/core/admin/mailu/api/v1/alias.py#L112-L117

Replication Steps

  1. Open the swagger docs at yourMailuInstance/api/v1/swagger.json
  2. Check the return types of certain api endpoints

Observed behaviour

There are wrong types for different api endpoints in the swagger docs. Specifically the /alias/destination/{domain} endpoint defines a #/definitions/Alias instead of an array of said type.

Expected behaviour

The /alias/destination/{domain} endpoint should define an array return type. This is especially necessary for code generators that generate api clients based on the swagger documentation.

Logs

No logs needed

nextgens commented 6 months ago

Please review DNS records in domain.py too (TLSA, DKIM can also have multiple records)