首页 文章

我正在使用带有ASP.Net Core API的NSwag,并且正在显示Swagger UI客户端

提问于
浏览
0

我正在使用NSwag和ASP.Net Core API,当我执行Web API并导航到Swagger UI时,它显示以下错误:

获取资源列表:未定义 . 请耐心等待 . 它给出了一个404并告诉我无法读取undefined的属性'substring',当我试图跟踪错误时指向self.url.substring中的Swagger客户端 . 虽然swagger.json中显示的json是完全正确的 .

这是我的Startup.cs类,右侧的Explorer Solution显示了我的nuget依赖项:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    // 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();
        }

        app.UseStaticFiles();

        // Enable the Swagger UI middleware and the Swagger generator
        app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly, settings =>
        {
            settings.SwaggerUiRoute = "/swagger";
            settings.PostProcess = document =>
            {
                document.Info.Version = "v1";
                document.Info.Title = "Analisis API";
                document.Info.Description = "A simple ASP.NET Core web API";
                document.Info.TermsOfService = "None";
                document.Info.Contact = new NSwag.SwaggerContact
                {
                    Name = "Example",
                    Email = "example@gmail.com",
                    Url = "http://google.es"
                };
                document.Info.License = new NSwag.SwaggerLicense
                {
                    Name = "Use under LICX",
                    Url = "https://example.com/license"
                };
            };

            app.UseMvc();
        });
    }

这是我的控制器:

[Route("api/[controller]")]
[ApiController]
public class ValuesController : Controller
{
    public IDatosAnalisis datosManager = new DatosAnalisis();
    public IResultado resultadoManager = new Resultado();

    [HttpGet]
    public ActionResult<String> GetDefault()
    {
        return "Bienvenido a AnalisisApi";
    }

    [HttpGet("getResultado/{patologiaId}")]
    [ProducesResponseType(typeof(ResultadoDTO), 200)]
    public ActionResult<ResultadoDTO> GetResultadoByPatologiaId(int patologiaId)
    {
        ResultadoDTO result = resultadoManager.getResultadoByPatologia(patologiaId);

        return result;
    }

    /// <summary>
    /// Receives the analisis data and evaluates them.
    /// </summary>
    [HttpPost]
    public ActionResult<List<ShortResultDTO>> TestValoresAnalisis(DatosSujetoDTO datosSujeto)
    {
        List<ShortResultDTO> results = datosManager.postDatosAnalisisAndGetPatologias(datosSujeto);

        return results;
    }




}

在此先感谢您提供的任何帮助!

1 回答

  • 1

    同样的问题,我的解决方法:使用自定义网址访问Swagger

    https:// localhost:44336 / swagger / index.html?url = / swagger / v1 / swagger.json

相关问题