fix: add ProducesResponseType to controllers, regenerate openapi.json

This commit is contained in:
Martin 2026-03-20 01:10:22 +01:00
parent 3c7db7092c
commit 40b256b870
4 changed files with 236 additions and 24 deletions

View File

@ -16,6 +16,8 @@ public class AuthController : ControllerBase
=> _credentials = credentials; => _credentials = credentials;
[HttpPost("login")] [HttpPost("login")]
[ProducesResponseType(typeof(LoginResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public IActionResult Login([FromBody] LoginRequest request) public IActionResult Login([FromBody] LoginRequest request)
{ {
if (request.Username != _credentials.Username if (request.Username != _credentials.Username

View File

@ -1,3 +1,4 @@
using AccountTracking.Api.Models.Dtos;
using AccountTracking.Api.Services; using AccountTracking.Api.Services;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -13,18 +14,22 @@ public class DashboardController : ControllerBase
public DashboardController(DashboardService svc) => _svc = svc; public DashboardController(DashboardService svc) => _svc = svc;
[HttpGet("summary")] [HttpGet("summary")]
[ProducesResponseType(typeof(SummaryDto), StatusCodes.Status200OK)]
public async Task<IActionResult> Summary([FromQuery] int year, [FromQuery] int? month) public async Task<IActionResult> Summary([FromQuery] int year, [FromQuery] int? month)
=> Ok(await _svc.GetSummaryAsync(year, month)); => Ok(await _svc.GetSummaryAsync(year, month));
[HttpGet("spending-by-category")] [HttpGet("spending-by-category")]
[ProducesResponseType(typeof(List<CategorySpendingDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> SpendingByCategory([FromQuery] int year, [FromQuery] int? month) public async Task<IActionResult> SpendingByCategory([FromQuery] int year, [FromQuery] int? month)
=> Ok(await _svc.GetSpendingByCategoryAsync(year, month)); => Ok(await _svc.GetSpendingByCategoryAsync(year, month));
[HttpGet("monthly-balances")] [HttpGet("monthly-balances")]
[ProducesResponseType(typeof(List<MonthlyBalanceDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> MonthlyBalances([FromQuery] int year) public async Task<IActionResult> MonthlyBalances([FromQuery] int year)
=> Ok(await _svc.GetMonthlyBalancesAsync(year)); => Ok(await _svc.GetMonthlyBalancesAsync(year));
[HttpGet("cumulative-spending")] [HttpGet("cumulative-spending")]
[ProducesResponseType(typeof(List<CumulativeSpendingDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> CumulativeSpending([FromQuery] int year, [FromQuery] int month) public async Task<IActionResult> CumulativeSpending([FromQuery] int year, [FromQuery] int month)
=> Ok(await _svc.GetCumulativeSpendingAsync(year, month)); => Ok(await _svc.GetCumulativeSpendingAsync(year, month));
} }

View File

@ -22,6 +22,8 @@ public class TransactionsController : ControllerBase
} }
[HttpPost("import")] [HttpPost("import")]
[ProducesResponseType(typeof(ImportResult), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResult), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Import(IFormFile file) public async Task<IActionResult> Import(IFormFile file)
{ {
if (file == null || file.Length == 0) if (file == null || file.Length == 0)
@ -40,6 +42,7 @@ public class TransactionsController : ControllerBase
} }
[HttpGet] [HttpGet]
[ProducesResponseType(typeof(TransactionListResponse), StatusCodes.Status200OK)]
public async Task<IActionResult> List( public async Task<IActionResult> List(
[FromQuery] int year, [FromQuery] int year,
[FromQuery] int? month, [FromQuery] int? month,
@ -78,6 +81,7 @@ public class TransactionsController : ControllerBase
} }
[HttpGet("categories")] [HttpGet("categories")]
[ProducesResponseType(typeof(string[]), StatusCodes.Status200OK)]
public async Task<IActionResult> Categories() public async Task<IActionResult> Categories()
{ {
var cats = await _db.Transactions var cats = await _db.Transactions

View File

@ -33,10 +33,19 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "$ref": "#/components/schemas/LoginResponse"
"format": "binary" }
}
}
},
"401": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
} }
} }
} }
@ -75,10 +84,9 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "$ref": "#/components/schemas/SummaryDto"
"format": "binary"
} }
} }
} }
@ -117,10 +125,12 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "type": "array",
"format": "binary" "items": {
"$ref": "#/components/schemas/CategorySpendingDto"
}
} }
} }
} }
@ -149,10 +159,12 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "type": "array",
"format": "binary" "items": {
"$ref": "#/components/schemas/MonthlyBalanceDto"
}
} }
} }
} }
@ -190,10 +202,12 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "type": "array",
"format": "binary" "items": {
"$ref": "#/components/schemas/CumulativeSpendingDto"
}
} }
} }
} }
@ -227,10 +241,19 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "$ref": "#/components/schemas/ImportResult"
"format": "binary" }
}
}
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResult"
} }
} }
} }
@ -307,10 +330,9 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "$ref": "#/components/schemas/TransactionListResponse"
"format": "binary"
} }
} }
} }
@ -328,10 +350,12 @@
"200": { "200": {
"description": "", "description": "",
"content": { "content": {
"application/octet-stream": { "application/json": {
"schema": { "schema": {
"type": "string", "type": "array",
"format": "binary" "items": {
"type": "string"
}
} }
} }
} }
@ -342,6 +366,47 @@
}, },
"components": { "components": {
"schemas": { "schemas": {
"LoginResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"token": {
"type": "string"
},
"expiresAt": {
"type": "string"
}
}
},
"ProblemDetails": {
"type": "object",
"additionalProperties": {
"nullable": true
},
"properties": {
"type": {
"type": "string",
"nullable": true
},
"title": {
"type": "string",
"nullable": true
},
"status": {
"type": "integer",
"format": "int32",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"instance": {
"type": "string",
"nullable": true
}
}
},
"LoginRequest": { "LoginRequest": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
@ -353,6 +418,142 @@
"type": "string" "type": "string"
} }
} }
},
"SummaryDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"totalSpent": {
"type": "number",
"format": "decimal"
},
"totalIncome": {
"type": "number",
"format": "decimal"
}
}
},
"CategorySpendingDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"category": {
"type": "string"
},
"total": {
"type": "number",
"format": "decimal"
}
}
},
"MonthlyBalanceDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"month": {
"type": "integer",
"format": "int32"
},
"closingBalance": {
"type": "number",
"format": "decimal"
}
}
},
"CumulativeSpendingDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"day": {
"type": "integer",
"format": "int32"
},
"cumulativeSpent": {
"type": "number",
"format": "decimal"
}
}
},
"ImportResult": {
"type": "object",
"additionalProperties": false,
"properties": {
"recordsImported": {
"type": "integer",
"format": "int32"
},
"recordsSkipped": {
"type": "integer",
"format": "int32"
}
}
},
"ErrorResult": {
"type": "object",
"additionalProperties": false,
"properties": {
"error": {
"type": "string"
}
}
},
"TransactionListResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TransactionDto"
}
},
"totalCount": {
"type": "integer",
"format": "int32"
},
"page": {
"type": "integer",
"format": "int32"
},
"pageSize": {
"type": "integer",
"format": "int32"
}
}
},
"TransactionDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"bookingDate": {
"type": "string",
"format": "date"
},
"counterPartyName": {
"type": "string",
"nullable": true
},
"category": {
"type": "string",
"nullable": true
},
"amount": {
"type": "number",
"format": "decimal"
},
"balance": {
"type": "number",
"format": "decimal"
},
"message": {
"type": "string",
"nullable": true
}
}
} }
}, },
"securitySchemes": { "securitySchemes": {