Как я могу импортировать приложение Azure API в управление Azure API? - PullRequest
0 голосов
/ 02 мая 2019

Я не могу импортировать приложение Azure API в управление Azure API

Я развернул ниже API в приложении Azure API.Если я импортирую с использованием спецификации Open API, я могу выполнить Get API.

Но то же самое приложение, если я выбираю в импорте с помощью API, я вижу все действия API в формате GUID.Почему он не может импортировать сваггер из приложения API?

Я написал код веб-API в ядре asp.net 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" };
        }
    }

Я вижу примерно такой же apis в формате GUIDв управлении лазурного API.GET 5ccb34af14679e9e94ea1db1 PUT 5ccb34af41873df6cae4f1f8 POST 5ccb34af581994f71e95c2fb DEL 5ccb34af6c082ccd698d202f

1 Ответ

0 голосов
/ 06 мая 2019

APIM получает набор конфигурации OpenAPI в блейде API Definition в вашем приложении API.

API Definition Blade for API App

Здесь вам нужно будет указать URL-адрес вашего файла Swagger.

...