配置Swagger

发布于 2025-02-06 06:35:27 字数 1232 浏览 2 评论 0 原文

我在Net Core 3.1中有一个Web API,我正在尝试配置Swagger,但我会遇到此错误:

我当前有启动。CS配置如下:

public void ConfigureServices(IServiceCollection services)
        {
            ...
            AddSwagger(services);

        }

private void AddSwagger(IServiceCollection services)
        {
            services.AddSwaggerGen(options =>
            {
                var groupName = "v1";

                options.SwaggerDoc(groupName, new OpenApiInfo
                { Title = "Core Library", Version = "v1", });
            });
        }

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            ...

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Core Library");
                c.RoutePrefix = String.Empty;
                c.DocumentTitle = "";
            });

            app.UseRouting();
            app.UseEndpoints(endpoints =>
                endpoints.MapControllers());
        }

我还缺少什么?你能帮助我吗?

谢谢你!!

I have a web api in net core 3.1 and I am trying to configure swagger but I get this error:
enter image description here

I currently have the startup.cs configured as follows:

public void ConfigureServices(IServiceCollection services)
        {
            ...
            AddSwagger(services);

        }

private void AddSwagger(IServiceCollection services)
        {
            services.AddSwaggerGen(options =>
            {
                var groupName = "v1";

                options.SwaggerDoc(groupName, new OpenApiInfo
                { Title = "Core Library", Version = "v1", });
            });
        }

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            ...

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Core Library");
                c.RoutePrefix = String.Empty;
                c.DocumentTitle = "";
            });

            app.UseRouting();
            app.UseEndpoints(endpoints =>
                endpoints.MapControllers());
        }

What else will I be missing? Can you help me?

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪 2025-02-13 06:35:28

使用浏览器上的Inspect并打开 Console 选项卡,单击 v1/swagger/json:1 文件以获取有关错误消息的详细信息

Use inspect on the browser and open the Console tab, click on v1/swagger/json:1 file to get details about the error message

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文