我正在为我的项目使用 asp dotnet core 3.1。目前,我正在按照建议的方式对我的1.0
操作进行版本控制。2.1
但是我想通过例如schooljob
或其他一些随机字符串值来对我的操作进行版本控制。我研究了很多,一些网站声称可以这样做1_0
,但1.0
没有说明如何做。另外,我不知道是否可以将版本控制更改为schooljob
.
对于我的 URL,我真正想做的是将它们从 更改为...someUrl/1.0/getTeachers
,...someUrl/schooljob/getTeachers
以便我最终可以在 Swagger 中更好地对它们进行分组。
// SchoolController.cs
[ApiVersion("1.0")] //I want to change it as [ApiVersion("schooljob")]
[ApiController]
[Route("{version:apiVersion}")]
public class SchoolController : AbstractController
{
...
[HttpPost("schooljob/getstudents")]
public JsonResult GetStudents([FromBody]Student student)
{ ... }
}
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
c.SwaggerDoc("schooljob", new OpenApiInfo
{
Version = "schooljob",
Title = "School Job"
});
// c.AddSecurityDefinition... and other swagger configurations
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
{
app.UseSwagger(c =>
{
c.RouteTemplate = "mainproject/swagger/{documentname}/swagger.json";
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/mainproject/swagger/schooljob/swagger.json", "School Job");
c.RoutePrefix = "mainproject/swagger";
});
}