Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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# 使用Swashbuckle向Swagger添加文本部分_C#_Asp.net Core_Swagger_Swashbuckle_Redoc - Fatal编程技术网

C# 使用Swashbuckle向Swagger添加文本部分

C# 使用Swashbuckle向Swagger添加文本部分,c#,asp.net-core,swagger,swashbuckle,redoc,C#,Asp.net Core,Swagger,Swashbuckle,Redoc,我正在使用Swashback与来记录我的ASP.NET Core 2.2 API。顶部有一组带有一些自定义html的部分(例如“简介”)。我想在API中生成类似的部分,但不知道如何实现 基本上,我有: services.AddSwaggerGen(c => { c.SwaggerDoc(...); c.IncludeXmlComments(...); c.AddSecurityDefinition("OAuth2", ...); }); 后来: app.UseRe

我正在使用Swashback与来记录我的ASP.NET Core 2.2 API。顶部有一组带有一些自定义html的部分(例如“简介”)。我想在API中生成类似的部分,但不知道如何实现

基本上,我有:

services.AddSwaggerGen(c => {
    c.SwaggerDoc(...);
    c.IncludeXmlComments(...);
    c.AddSecurityDefinition("OAuth2", ...);
});
后来:

app.UseReDoc(c => {
    c.SpecUrl = "/swagger/v1/swagger.json";
    c.RoutePrefix = "";
});
我已经浏览了intellisense选项以及Swashback和,但没有找到生成此类部分的方法


向基于Swashback.AspNetCore.ReDoc的文档开头添加HTML节的方法是什么?

您可以在传递给
SwaggerDoc(…)
信息的
说明中使用标记。您可以在ReDoc中包含最终作为侧栏导航项的标题。例如:

c.SwaggerDoc(Version, new Info
    {
        Title = "My API",
        Description = @"This is our API.

            ## Introduction

            We can use markdown (with [links](https://example.org)) to explain more about the API.

            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

            - Bullet item
            - And another bullet item

            Some more lorem ipsum.

            ## Logging

            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

            Here's a sample block:

            ```bash
            curl https://example.org/api/v1/some-method \
            -H 'X-Header: value' \
            -v
            ```

            Lorem ipsum **doler sit met something more** test text.
        ",
});

我建议将该标记放在一个文件中。

有没有一种方法不需要在Startup.cs中粘贴大量文本?是的,事实上我通常这样做。使用这种方法在我的答案底部添加了一个链接。当然,您也可以使用任何其他方法来封装和移动该字符串(最简单的方法是使用字符串的
SwaggerConstants.cs
文件)。这就是我们最终的做法。这比我们想象的要简单得多,因为需要处理一个自定义index.html文件和css。感谢您发布链接:)