0
votes

I am not able to import the azure api app in azure api management

I have deployed below api in azure api app. If I import using open api specification,I am able to execute the Get api.

But same app if I choose in import using api app, I can see all api actions in GUID format. Why is it not able to import swagger from api app?

I have written code of web api in asp.net core 2.1

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.Collections.Generic;
using System.IO;

namespace WebApplication1
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonOptions(options =>
            {
                options.SerializerSettings.Formatting = Formatting.Indented;
            });
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
                var xmlFile = $"api.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
                c.EnableAnnotations();
            });

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseCors(options => options.AllowAnyOrigin());
            app.UseSwagger(c =>
             c.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
             {
                 swaggerDoc.Host =  httpReq.Host.Value;
                 swaggerDoc.BasePath = "/";
                 swaggerDoc.Schemes = new List<string>() { httpReq.Scheme };
             }));
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                c.DisplayOperationId();
                c.RoutePrefix = string.Empty;
            });

            app.UseHttpsRedirection();
            app.UseMvc();
        }
    }

ValuesController class

    [Route("api/[controller]")]
    [ApiController]
    [Produces("application/json")]
    public class ValuesController : ControllerBase
    {
        /// <summary>
        /// Get all values
        /// </summary>
        /// <returns></returns>
        // GET api/values
        [HttpGet]
        //[SwaggerOperation(summary:"hello",description:"hdjshdj")]
        [SwaggerResponse(200,Type=typeof(List<string>))]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }
    }

I can see apis something like this in GUID format in azure api management. GET 5ccb34af14679e9e94ea1db1 PUT 5ccb34af41873df6cae4f1f8 POST 5ccb34af581994f71e95c2fb DEL 5ccb34af6c082ccd698d202f

1

1 Answers

0
votes

APIM fetches the OpenAPI configuration set in the API Definition blade in your API App.

API Definition Blade for API App

You will have to set the URL to your Swagger file here.