aspnetboilerplate: ApiVersioning + Swagger + ApplicationService not working
Hi I try to use ApiVersioning for dynamic web api But this doesn’t work reference:https://github.com/microsoft/aspnet-api-versioning/blob/master/samples/aspnetcore/SwaggerSample/Startup.cs
ApplicationService
[ApiVersion("1.0")]
public class TestAppService: ApplicationService, ITestAppService
{
public Task<string> Get()
{
return Task.FromResult("Test");
}
}
Startup.cs
services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.ApiVersionReader = new HeaderApiVersionReader("Api-Version");
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
});
services.AddVersionedApiExplorer(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.GroupNameFormat = "'v'VVV";
});
apiVersioning and swagger cannot find TestAppService on abp 5.5.0.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (6 by maintainers)
Hi @vcluopeng thanks for answering.
Hi @ismcagdas,
I managed to add API versioning to asp.net Zero. If you think there is more easier or better way to achieve this, I would happy to here. If you think it is ok, can we have this as part of documentation of asp.net zero (.netcore + angular)
File
ProjectName.Web.Host\startup\startup.cs
methodConfigureServices
changed related code to this:File
ProjectName.Web.Host\startup\startup.cs
inConfigure
method changed code to this:File
ProjectName.Web.Core.ProjectNameCoreModule.cs
InPreInitialize
method changed code to this:Comment or remove following lines
And add these line to be able adding apppservice as controller with version in url:
Change appsettingjson.json
Add version Info to AppService or methods:
Note: To get latest APı methods in nswag In file
ProjectName.Web.Host\nswag\service.config.nswag
change following:"url": "https://localhost:44301/swagger/v1/swagger.json",
-->"url": "https://localhost:44301/swagger/v1.0/swagger.json",
Or change to desired version"url": "https://localhost:44301/swagger/v3.0/swagger.json",
Now versioning works as expected.
V1
V2
V3