Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

I have tried the swagger ui versioning by using the .net core 3.1 with API 2.0. i have completed this scenario up to controller level. but i dont know how to do this versioning for controller Action...anyone can you please help me on this i have struggled past 3 days on this. help me to solve this......

What I have tried:

public void ConfigureServices(IServiceCollection services)
        {

            services.AddMvc();           
            services.AddApiVersioning(o =>
            {
                o.AssumeDefaultVersionWhenUnspecified = true;
                o.DefaultApiVersion = new ApiVersion(3, 0);
            });
            // Add this
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1",
                    new OpenApiInfo
                    {
                        Version = "v1",
                        Title = "v1 API",
                        Description = "v1 API Description",
                    });

                // Add a SwaggerDoc for v2 
                options.SwaggerDoc("v2",
                    new OpenApiInfo
                    {
                        Version = "v2",
                        Title = "v2 API",
                        Description = "v2 API Description"                       
                    });
}


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
       {

           app.UseSwagger();
           app.UseSwaggerUI(c =>
           {
               c.SwaggerEndpoint($"/swagger/v1/swagger.json", $"v1");
               c.SwaggerEndpoint($"/swagger/v2/swagger.json", $"v2");
               c.DefaultModelExpandDepth(0); // Hide Models section in swagger UI
               c.DefaultModelsExpandDepth(-1);
           });

}



[Route("api/v{version:ApiVersion}/[controller]")]
    [ApiController]
    [ApiVersion("1.0")]
    [ApiVersion("2.0")]
    public partial class xxxController : ControllerBase
    {

        private readonly IxxxDomainService _xxxService;
        private readonly IMapper _mapper;


        public xxxController(IxxxService studprofService, IMapper mapper)
        {
            this._mapper = mapper;
            this._xxxService = xxxService;
        }
        
        [ActionName("GetAll")]
        
        [HttpGet("{InstitutionProgAssocId}/{ProgApSpAssocId}")]
        public async Task<List<XXXDTO>> GetAllXXX(int XXXProgAssocId, int ProgApSpAssocId)
        {
            return await _XXXService.GetAllXXX(XXXAssocId, ProgApSpAssocId);
        }
Posted
Updated 2-Feb-20 3:54am
Comments
[no name] 30-Jan-20 10:55am    
Life is hard enough on the leading edge without 3rd party products with pretentious names.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900