如何在Azure API管理中导入Azure API应用程序?

时间:2019-05-02 18:41:25

标签: azure-api-management azure-api-apps

我无法在Azure API管理中导入Azure API应用

我已经在azure api应用中的api下方部署了。 如果我使用开放式api规范导入,则可以执行Get api。

但是如果我选择使用api应用导入,则为同一个应用, 我可以看到GUID格式的所有api操作。为什么它不能从api应用程序导入招摇?

我已经在asp.net core 2.1中编写了Web api的代码

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" };
        }
    }

我可以在Azure api管理中以GUID格式看到类似api的内容。  GET 5ccb34af14679e9e94ea1db1  放置5ccb34af41873df6cae4f1f8  开机自检5ccb34af581994f71e95c2fb  DEL 5ccb34af6c082ccd698d202f

1 个答案:

答案 0 :(得分:0)

APIM获取API应用程序的API Definition刀片中设置的OpenAPI配置。

API Definition Blade for API App

您将必须在此处将Swagger文件的URL设置为