Multiple routes with and without a path parameter?

I’m down to my last issue now trying to “fix” errors in the openapi.json generated for my service.

I have created some services with multiple routes:

[Route("/candidate", "GET", Summary = "get candidates")]
[Route("/candidate/{CandidateRef}", "GET", Summary = "get specified candidate")]

which are fine using ServiceStack and work correctly with the inbuilt Swagger-UI component but according to are not valid unless I make the {CandidateRef} a path ParameterType. Unfortunately doing this also makes it required (at least in Swagger-UI) which makes the /candidate route impossible to use.

Is there any way to have both work through Swagger-UI or do I need to split my DTO in some way even though other than the one parameter they are identical?



Yeah you’d need to split them in multiple Request DTOs so you can assert the route with the path info is required whilst the other is not.

FYI you can use Auto Mapping Utils to call a different Request DTO with the same shape in 1 LOC:

public object Any(GetCandidateWithPath request) => Any(request.ConvertTo<GetCandidate>());
1 Like

Thanks - the auto mapper is a life saver.


1 Like