This is a great tutorial. Thanks.
I did get stuck at some point.
With .NET Core 3.1, Swashbuckle has changed a number of things. The "Apply" method in the class that implements the IDocumentFilter should be updated to this:
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var toReplaceWith = new OpenApiPaths(); foreach (var (key, value) in swaggerDoc.Paths) { toReplaceWith.Add(key.Replace("v{version}", swaggerDoc.Info.Version, StringComparison.InvariantCulture), value); } swaggerDoc.Paths = toReplaceWith; }
Also, the predicate that ensures endpoints are displayed in their appropriate swagger doc should be updated:
setup.DocInclusionPredicate((version, desc) => { if (!desc.TryGetMethodInfo(out MethodInfo methodInfo)) return false; var versions = methodInfo.DeclaringType .GetCustomAttributes(true) .OfType<ApiVersionAttribute>() .SelectMany(attr => attr.Versions); var maps = methodInfo .GetCustomAttributes(true) .OfType<MapToApiVersionAttribute>() .SelectMany(attr => attr.Versions) .ToArray(); return versions.Any(v => $"v{v.ToString()}" == version) && (!maps.Any() || maps.Any(v => $"v{v.ToString()}" == version)); });
Saved my day.
Thank you ... this is exactly what I needed!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a great tutorial. Thanks.
I did get stuck at some point.
With .NET Core 3.1, Swashbuckle has changed a number of things. The "Apply" method in the class that implements the IDocumentFilter should be updated to this:
Also, the predicate that ensures endpoints are displayed in their appropriate swagger doc should be updated:
Saved my day.
Thank you ... this is exactly what I needed!