openapi.json responses don't match the actual API — /api/Account/invite is an object, not a string (and every response advertises text/plain)
What happened?
I'm generating a Python client from the official openapi.json (v0.9.1.4) with openapi-python-client. Two spec issues surfaced:
- POST /api/Account/invite response type is wrong. The spec documents the 200 response as a plain string for all content types:
"responses": {
"200": {
"content": {
"text/plain": { "schema": { "type": "string" } },
"application/json": { "schema": { "type": "string" } },
"text/json": { "schema": { "type": "string" } }
}
}
}But the server actually returns an object:
{
"emailLink": "https://host/registration/confirm-email?token=...&email=test%40example.com",
"emailSent": false,
"invalidEmail": true
}The root cause is in Kavita.Server/Controllers/AccountController.cs — the controller declares a string return type but returns an InviteUserResponse:
public async Task<ActionResult<string>> InviteUser(InviteUserDto dto)
{
...
return Ok(new InviteUserResponse
{
EmailLink = emailLink,
EmailSent = false,
InvalidEmail = true
});
}Swashbuckle uses the declared type, so the generated spec says string. Interestingly, the InviteUserResponse schema already exists in openapi.json (#/components/schemas/InviteUserResponse) — it's just never referenced by the endpoint.
- Every response advertises text/plain, application/json, text/json — with text/plain first — but bodies are always JSON. This comes from the spec generation pipeline (.github/workflows/openapi-gen.yml, dotnet swagger tofile), which lists all registered output formatters rather than what an endpoint actually produces. Code generators that honor the first supported content type parse JSON bodies as plain text (e.g. generating UserDto.from_dict(response.text) where response.text is a JSON string), which crashes at runtime.
What did you expect?
openapi.json should match the actual wire format so that typed clients generated from the official spec work: the invite endpoint should reference InviteUserResponse, and responses should advertise application/json (or at least list it first).
Kavita Version Number - If you don't see your version number listed, please update Kavita and see if your issue still persists.
0.9.1 - Stable
Are you accessing kavita through a reverse proxy? If yes, confirm that the issue persists with a direct connection
Yes
What operating system is Kavita being hosted from?
Docker (Dockerhub Container)
If the issue is being seen on Desktop, what OS are you running where you see the issue?
None
If the issue is being seen in the UI, what browsers are you seeing the problem on?
No response
If the issue is being seen on Mobile, what OS are you running where you see the issue?
No response
If the issue is being seen on the Mobile UI, what browsers are you seeing the problem on?
No response
Relevant log output
# POST /api/Account/invite — actual response (200):
{"emailLink":"https://host/registration/confirm-email?token=…&email=test%40example.com","emailSent":false,"invalidEmail":true}Additional Notes
- Repro: generate any client from
openapi.json, callAccount/invitewith{"email":"[email protected]","roles":["Login"],"libraries":[],"ageRestriction":{"ageRating":0,"includeUnknowns":true}}— the response can't be parsed as a string. - Suggested fix for 1: change the controller signature to
Task<ActionResult<InviteUserResponse>>. - Suggested fix for 2: add
[Produces("application/json")]at the controller/assembly level (or equivalent Swashbuckle config) so the spec only advertises JSON. - Related minor observation:
InviteUserResponse.InvalidEmailis set totruewhenever email isn't configured on the server (!settings.IsEmailSetup()), even when the address is valid and a working setup link is returned — the invite itself succeeds. The DTO doc comment ("When a user has an invalid email and is attempting to perform a flow") makes this look like a failure. Worth clarifying/renaming. - Similar to the previously fixed #3630 (
/api/Series/v2response didn't match the schema) — thanks for fixing that one; this is the same class of issue.
Source: Kareadita/Kavita