I am working with Swashbuckle.AspNetCore and add x-codeSamples
with the bellow code:
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)},
});
}
}
And I can see this in JSON file:
But the code sample not showing in the UI. Please help me whats going wrong?