Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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# Swashback.AspNetCore中未显示x代码样本_C#_Asp.net Core_Swashbuckle_Swashbuckle.aspnetcore_Redoc - Fatal编程技术网

C# Swashback.AspNetCore中未显示x代码样本

C# Swashback.AspNetCore中未显示x代码样本,c#,asp.net-core,swashbuckle,swashbuckle.aspnetcore,redoc,C#,Asp.net Core,Swashbuckle,Swashbuckle.aspnetcore,Redoc,我正在使用并添加x-codeSamples以下代码: public class XCodeSamplesFilter : IDocumentFilter { public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { string source = @"PetStore.v1.Pet pet = new PetStore.v1.Pet();

我正在使用并添加
x-codeSamples
以下代码:

public class XCodeSamplesFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        string source = @"PetStore.v1.Pet pet = new PetStore.v1.Pet();
                        pet.setApiKey(""your api key"");
                        pet.petType = PetStore.v1.Pet.TYPE_DOG;
                        pet.name = ""Rex"";
                        // set other fields
                        PetStoreResponse response = pet.create();
                        if (response.statusCode == HttpStatusCode.Created)
                        {
                            // Successfully created
                        }
                        else
                        {
                            // Something wrong -- check response for errors
                            Console.WriteLine(response.getRawResponse());
                        }";
        // need to check if extension already exists, otherwise swagger 
        // tries to re-add it and results in error  

        if (!swaggerDoc.Info.Extensions.ContainsKey("x-codeSamples"))
            swaggerDoc.Info.Extensions.Add("x-codeSamples", new OpenApiObject
            {
                {"lang", new OpenApiString("C#")},
                {"label", new OpenApiString("")},
                {"source", new OpenApiString(source)},                        
            });
    }

}
我可以在JSON文件中看到:

但是代码示例没有显示在UI中。请帮帮我怎么了