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

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

问题描述

我正在开发一个 .netcore 网络应用程序.我正在使用 swagger 并进行了所有必要的调整.不幸的是它不起作用,我只是在 swagger 输出页面中看到 No operations defined in spec! .

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": {}
}

我想在 swagger 输出页面中查看我的控制器及其操作.

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

推荐答案

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

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天全站免登陆