Context
Several controller actions return a bare string/String (or bool) instead of IActionResult/ActionResult<T>. These actions hand-serialize their payload with JsonSerializer.Serialize(...) and then return the resulting string.
Returning a bare string has two concrete consequences (both verified against a running instance):
- Wrong content type. A
string return goes through ASP.NET Core's StringOutputFormatter, so the response is served as Content-Type: text/plain; charset=utf-8 — even though the body is JSON. Compare with ProblemProvider.*, which uses Content(..., "application/json") and correctly returns application/json.
- No error results. With a
string return type the action cannot return BadRequest(...)/NotFound(...). Endpoints that take a problem name currently return an empty [] on unknown/invalid input instead of a proper 4xx.
Proposed change
Convert the affected actions to ActionResult<T> and return theObject; rather than JsonSerializer.Serialize(...), letting the framework serialize to application/json. Add BadRequest(...)/NotFound(...) on invalid input where a problem/reduction name is accepted.
Guideline going forward:
| Use |
When |
ActionResult<T> |
One well-defined success payload T, possibly plus error results. Swagger infers the 200 body; framework serializes as application/json. |
IActionResult / non-generic ActionResult |
No single success type, or returning a raw ContentResult/FileResult. |
bare string/bool/POCO |
Avoid. |
Endpoints that need attention
| Controller |
Route |
Method |
ALL_ProblemsRefactorController |
GET Navigation/ALL_ProblemsRefactorController |
getDefault() |
NPC_ProblemsRefactorController |
GET Navigation/NPC_ProblemsRefactorController |
getDefault() |
P_ProblemsRefactorController |
GET Navigation/P_ProblemsRefactorController |
getDefault() |
NPHard_ProblemsRefactorController |
GET Navigation/NPHard_ProblemsRefactorController |
getDefault() |
NPC_NavGraph |
GET Navigation/NPC_NavGraph/availableReductions |
getConnectedProblems(chosenProblem) — takes a problem name; can't 400/404 |
NPC_NavGraph |
GET Navigation/NPC_NavGraph/reductionPath |
getPaths(reducingFrom, reducingTo) — takes problem names |
Nav_Visualizations controller |
GET Navigation/{controller} |
getDefault(chosenProblem, problemType?) |
Nav_Reductions controller |
GET Navigation/{controller} |
getDefault(source?, target?) |
Nav_Verifiers controller |
GET Navigation/{controller} |
getDefault(chosenProblem, problemType?) |
Nav_Solvers controller |
GET Navigation/{controller} |
getDefault(chosenProblem, problemType?) |
ProblemGeneratorController |
GET ProblemGenerator/UndirectedGraph |
getUndirectedGraph(n, density, k) |
ProblemGeneratorController |
GET ProblemGenerator/DirectedGraph |
getDirectedGraph(n, density, k) |
ProblemGeneratorController |
GET ProblemGenerator/Sat3 |
getSat3(n, c) |
Also worth fixing while here: the ProblemGeneratorController actions are annotated [ProducesResponseType(typeof(string[]), 200)] but return a single instance string, not an array.
Already correct (no change needed)
ProblemProvider.* — IActionResult; mixes Content(..., "application/json") with BadRequest(...), no single T.
ContributerProfile.* — IActionResult with Ok/NotFound.
ProblemTemplate.* — ActionResult returning file downloads (no T).
Context
Several controller actions return a bare
string/String(orbool) instead ofIActionResult/ActionResult<T>. These actions hand-serialize their payload withJsonSerializer.Serialize(...)and then return the resultingstring.Returning a bare
stringhas two concrete consequences (both verified against a running instance):stringreturn goes through ASP.NET Core'sStringOutputFormatter, so the response is served asContent-Type: text/plain; charset=utf-8— even though the body is JSON. Compare withProblemProvider.*, which usesContent(..., "application/json")and correctly returnsapplication/json.stringreturn type the action cannot returnBadRequest(...)/NotFound(...). Endpoints that take a problem name currently return an empty[]on unknown/invalid input instead of a proper 4xx.Proposed change
Convert the affected actions to
ActionResult<T>andreturn theObject;rather thanJsonSerializer.Serialize(...), letting the framework serialize toapplication/json. AddBadRequest(...)/NotFound(...)on invalid input where a problem/reduction name is accepted.Guideline going forward:
ActionResult<T>T, possibly plus error results. Swagger infers the 200 body; framework serializes asapplication/json.IActionResult/ non-genericActionResultContentResult/FileResult.string/bool/POCOEndpoints that need attention
ALL_ProblemsRefactorControllerGET Navigation/ALL_ProblemsRefactorControllergetDefault()NPC_ProblemsRefactorControllerGET Navigation/NPC_ProblemsRefactorControllergetDefault()P_ProblemsRefactorControllerGET Navigation/P_ProblemsRefactorControllergetDefault()NPHard_ProblemsRefactorControllerGET Navigation/NPHard_ProblemsRefactorControllergetDefault()NPC_NavGraphGET Navigation/NPC_NavGraph/availableReductionsgetConnectedProblems(chosenProblem)— takes a problem name; can't 400/404NPC_NavGraphGET Navigation/NPC_NavGraph/reductionPathgetPaths(reducingFrom, reducingTo)— takes problem namesNav_VisualizationscontrollerGET Navigation/{controller}getDefault(chosenProblem, problemType?)Nav_ReductionscontrollerGET Navigation/{controller}getDefault(source?, target?)Nav_VerifierscontrollerGET Navigation/{controller}getDefault(chosenProblem, problemType?)Nav_SolverscontrollerGET Navigation/{controller}getDefault(chosenProblem, problemType?)ProblemGeneratorControllerGET ProblemGenerator/UndirectedGraphgetUndirectedGraph(n, density, k)ProblemGeneratorControllerGET ProblemGenerator/DirectedGraphgetDirectedGraph(n, density, k)ProblemGeneratorControllerGET ProblemGenerator/Sat3getSat3(n, c)Also worth fixing while here: the
ProblemGeneratorControlleractions are annotated[ProducesResponseType(typeof(string[]), 200)]but return a single instance string, not an array.Already correct (no change needed)
ProblemProvider.*—IActionResult; mixesContent(..., "application/json")withBadRequest(...), no singleT.ContributerProfile.*—IActionResultwithOk/NotFound.ProblemTemplate.*—ActionResultreturning file downloads (noT).