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中。请帮帮我怎么了