Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 端点和类文档的Web Api中的Swagger UI设置_C#_Asp.net Web Api_Visual Studio 2013_Json.net_Swagger Ui - Fatal编程技术网

C# 端点和类文档的Web Api中的Swagger UI设置

C# 端点和类文档的Web Api中的Swagger UI设置,c#,asp.net-web-api,visual-studio-2013,json.net,swagger-ui,C#,Asp.net Web Api,Visual Studio 2013,Json.net,Swagger Ui,我在VS2013中有一个解决方案,其中包含几个类库和一个Web API项目。我在设置Swagger UI时遇到了一些问题。首先,当我为我的WebAPI项目设置Swashback时,我只能指向一个文档XML文件。有没有一种方法可以指向包含多个XML文件,这样Swagger不仅可以在controller中获取我的路由文档,还可以从我的其他项目中获取域对象?这是我来自SwaggerConfig.cs的代码 SwaggerSpecConfig.Customize ( c =>

我在VS2013中有一个解决方案,其中包含几个类库和一个Web API项目。我在设置Swagger UI时遇到了一些问题。首先,当我为我的WebAPI项目设置Swashback时,我只能指向一个文档XML文件。有没有一种方法可以指向包含多个XML文件,这样Swagger不仅可以在controller中获取我的路由文档,还可以从我的其他项目中获取域对象?这是我来自SwaggerConfig.cs的代码

SwaggerSpecConfig.Customize
    (
        c =>
        {
            c.IncludeXmlComments(Path.Combine(dirPath, projName + ".xml"));
        }
    );
如果我添加多个XML文件,它只从IncludeXmlComments中选取最后一个文件

第二,当以JSON返回时,我对DTO使用camel-case

formats.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

但是,当我在Swagger UI中查看response类中的响应模型和模型模式时,我看到的是确切的类属性名称,而不是在命中端点时返回的JSON模式。有没有办法在Swagger UI文档页面中显示确切的JSON模式?

要添加多个XML文件,请像这样配置Swagger

       SwaggerSpecConfig.Customize(c =>
        {
            // single XML Comment Files
            //c.IncludeXmlComments(GetXmlCommentsPath());

            // Multiple XML Comment Files
            string[] paths = GetXmlCommentsPaths();
            foreach (string xmlCommentsPath in paths)
            {
                c.OperationFilter(new ApplyActionXmlComments(xmlCommentsPath))
                    .ModelFilter(new ApplyTypeXmlComments(xmlCommentsPath));
            }
        });

在版本4.1之后,您可以编写以下内容:

c.IncludeXmlComments("File1_Path");
c.IncludeXmlComments("File2_Path"));

另请参见。

我使用的是5.6.0版,多个XML文档适合我:

var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));
foreach (var fi in dir.EnumerateFiles("*.xml"))
{
    c.IncludeXmlComments(fi.FullName);
}

我一直在修补代码,我不知道我是如何让它工作的。当我使用上面的代码时,它可以工作,但当我使用你的代码时,我只得到部分文档。我将尝试还原我的代码并使用您的解决方案。仅供参考,在ApplyActionXmlComments和ApplyTypeXmlComments中,构造函数需要一个XPathDocument。它对我有用。我不知道您使用的是什么版本,但我使用的是4.1.0-rc2预发行版。。它将文件的路径作为字符串。