Здесь это мой фрагмент в моей функции ConfigureServices():
Код: Выделить всё
services.AddOpenApiDocument(document =>
{
...
// this works fine
document.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
document.DocumentProcessors.Add(new SecurityDefinitionAppender("Bearer", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "Authorization",
In = SwaggerSecurityApiKeyLocation.Header
})
);
// this is the header i want to show up for all endpoints that is breaking
document.OperationProcessors.Add(new SampleHeaderOperationProcessor());
});
Код: Выделить всё
public class SampleHeaderOperationProcessor : IOperationProcessor
{
public Task ProcessAsync(OperationProcessorContext context)
{
context.OperationDescription.Operation.Parameters.Add(
new SwaggerParameter {
Name = "Sample",
Kind = SwaggerParameterKind.Header,
Type = NJsonSchema.JsonObjectType.String,
IsRequired = false,
Description = "This is a test header",
Default = "{{\"field1\": \"value1\", \"field2\": \"value2\"}}"
});
return Task.FromResult(true);
}
}
Код: Выделить всё
app.UseSwagger();
app.UseSwaggerUi3();
Моя ошибка и журнал консоли
Если это так помогает. Я использую ASP .NET CORE 2.2 и NSwag.AspNetCore v12.1.0
Подробнее здесь: https://stackoverflow.com/questions/557 ... p-net-core
Мобильная версия