swagger.json路径和定义为空。规范中未定义任何操作 [英] swagger.json paths and definitions are empty. No operations defined in spec

查看:868
本文介绍了swagger.json路径和定义为空。规范中未定义任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发.netcore Web应用程序。我正在用招摇工具,并已进行所有必要的调整。不幸的是,它不起作用,我只是在招摇输出页面中看到规范中未定义任何操作!

I am developing a .netcore web application. I am using of swagger and I've made all the necessary adjustments. Unfortunately it does not work and I just see No operations defined in spec! in the swagger output page.

带有 /swagger/v1/swagger.json 的swagger文件具有以下内容:

The swagger file with /swagger/v1/swagger.json has the following content:

{
  "swagger": "2.0",
  "info": {
    "version": "v1",
    "title": "Something"
  },
  "paths": {},
  "definitions": {}
}

我想在摇摇欲坠的输出页面中看到我的控制器及其动作。

I want to see my controllers and their actions in swagger output page.

推荐答案

经过一些研究,我发现我的问题是关于在.NetCore2.1中将swagger和OData一起使用。
i找到了解决该问题的方法。

after some research i was found that my problem was about using swagger along with OData in .NetCore2.1. i found a solution for this problem.

首先,我添加了以下两个Nuget软件包:

first i added two following Nuget packages:

Swashbuckle.AspNetCore
Swashbuckle.AspNetCore.Annotations

然后,我在Startup.cs

then, i added following codes in Startup.cs

services.AddMvc(options => {
                foreach (var outputFormatter in 
options.OutputFormatters.OfType<ODataOutputFormatter>().Where(_ => 
_.SupportedMediaTypes.Count == 0))
                {
                    outputFormatter.SupportedMediaTypes.Add(new 
MediaTypeHeaderValue("application/prs.odatatestxx-odata"));
                }
                foreach (var inputFormatter in 
options.InputFormatters.OfType<ODataInputFormatter>().Where(_ => 
_.SupportedMediaTypes.Count == 0))
                {
                    inputFormatter.SupportedMediaTypes.Add(new 
MediaTypeHeaderValue("application/prs.odatatestxx-odata"));
                }
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

我在控制器中添加了以下代码行:

the, i added following code line in controllers:

[ApiExplorerSettings(IgnoreApi = false)] 

请注意,它对我有用,但可能需要更多研究以最终发现副作用

please note that it was worked for me but it may be need more research for eventually side effects

这篇关于swagger.json路径和定义为空。规范中未定义任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆