How to specify parameter before path?

Let’s say I have the following routes set up:

[Route("/records", “GET”)]
[Route("/users", “GET”)]

I need to specify an “environment” on each request that the user must pass in. I would like the format to be:


for the above routes.

What’s the best way to do this and still have it be Swagger and AutoQuery friendly?

I don’t understand, if it needs an environment prefix you need to specify that in your route:

[Route("/{environment}/records", "GET")]
[Route("/{environment}/users", "GET")]

Can I require this parameter at the service or class level so I don’t have to repeat everywhere it’s needed?

I wouldn’t, Routes are an explicit part of your Service Contract which serves as explicit public documentation for what’s required to call Services that I wouldn’t be trying to hide/DRY behind magic configuration that intentionally changes the meaning for each route, unknowingly to anyone relying on the call-site routing declaration - leading to an unnecessary source of confusion.

But you can programmatically modify each Route by overriding GetRouteAttributes() in your AppHost:

This doesn’t seem to work well with Swagger or AutoQuery. With AutoQuery, I get the following error when I click on the GetUsers:

ArgumentNullException: Value cannot be null. Parameter name: Environment

With Swagger, the Users functions no longer appear.

Is there something I need to do in order to get Swagger and AutoQuery to work with these routes?

Disregard the AutoQuery complaint. I have to set it in the filter. This works now, thanks.

But Swagger still doesn’t seem to like this.

We don’t maintain Swagger UI, it may not like wildcard path prefixes, can you provide a sample of the json from the /openapi endpoint and a screenshot or a description of the issue. Is the issue only when overriding GetRouteAttributes() or for all Routes with wildcard prefixes? e.g. [Route("/{environment}/records")].