-
Notifications
You must be signed in to change notification settings - Fork 711
Asp Net Core + OData + Swagger + Url Segment Versioning #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This looks correct. I'll give your setup a whirl to see if I can repro the bad or correct behavior. It's quite possible that there is a bug. |
Thanks @commonsensesoftware public const string VersionPattern = "v{v:apiVersion}";
//operation filter
public void Apply(Operation operation, OperationFilterContext context)
{
context.ApiDescription.RelativePath = context.ApiDescription.RelativePath.Replace(VersionPattern, context.ApiDescription.GroupName);
}
//document filter
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
var pathItems = new Dictionary<string, PathItem>();
var toRemove = new List<string>();
foreach (var swaggerDocPath in swaggerDoc.Paths)
{
foreach (var apiDescription in _apiVersionDescriptionProvider.ApiVersionDescriptions)
{
if (swaggerDocPath.Key.Contains(VersionPattern))
{
pathItems.Add(
swaggerDocPath.Key.Replace(VersionPattern, apiDescription.GroupName),
swaggerDocPath.Value);
toRemove.Add(swaggerDocPath.Key);
}
}
}
foreach (var key in toRemove.Distinct())
{
swaggerDoc.Paths.Remove(key);
}
foreach (var pathItem in pathItems.Reverse())
{
swaggerDoc.Paths.Add(pathItem);
}
} I did not test with multiple versions yet though and I'd love to hear your feedback. |
I've been able to confirm that this is actually a bug. Special template parsing and replacement is required for the OData route prefix. I thought this would be a really, really quick fix, but it's turning out to be a little more complex than I thought. I should have the fix out for beta 2 in the next couple of days. In the meantime, your workaround should be suitable. This is more or less what was required before the built-in substitution option was available. |
Great. I'll give beta 2 a try when it's out and post my results. Thanks |
…d URL segment substitution. Fixes #365
…d URL segment substitution. Fixes #365
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I'm having trouble setting up versioning by URL segment. After figuring out how to add the version to the route template, I'm faced with these situations:
api/v1/values
it is showing like thisapi/v{version:apiVersion}/values
which, as expected, causes a lot of troubles;Here is how I've setup the application:
Startup.cs
SwaggerDefaultValues.cs
So, am I doing something wrong? Is this scenario supported?
Thanks in advance.
The text was updated successfully, but these errors were encountered: