0

I am configuring my swagger ui like so:

builder.Services.AddSwaggerGen(c => {
    c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
    {
        Title = "Skillbased Middleware API Info",
        Version = "v1"
    });
});


var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Company API Testing v1");
});

but i cannot make a signel crud request to the server, because it always requires a certain header (zumo api version) to go through.

Where can I add this to my swagger config? This is form an asp.net core web application

I got as far as to put this:

 public class SwaggerHeader : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null)
                operation.Parameters = new List<OpenApiParameter>();

            operation.Parameters.Add(new OpenApiParameter
            {
                Name = "ZUMO-API-VERSION=",
                Description = "3.0.0",
                Required = true // set to false if this is optional
            });
        }
    }

But if I try to execute any command, it just loads and loads and never gets to a result...

inno
  • 376
  • 2
  • 15
  • Do these links answer your question? - [Web API - How to add a Header parameter for all API requests in Swagger UI](https://stackoverflow.com/q/41493130/113116), [Use client-side request and response interceptors in Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore#use-client-side-request-and-response-interceptors) – Helen Jun 14 '23 at 13:07

1 Answers1

0

I was close:

 public class SwaggerHeader : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null)
                operation.Parameters = new List<OpenApiParameter>();

            operation.Parameters.Add(new OpenApiParameter
            {
                Name = "ZUMO-API-VERSION",
                In = ParameterLocation.Query,
                Required = true // set to false if this is optional
            });
        }
    }

Now in the UI pick the calls that do not req. Id and as ZUMMO put: "3.0.0" and your good to go

inno
  • 376
  • 2
  • 15