https scheme issue with Swashbuckle using Proxied OWIN self-hosted Web API

Viewed 22

I have been working on a web api in C# using the self-hosted owin web api which is proxied.

I have setup the Swashbuckle.Core package, It all works fine. I am just having one slight issue with the base url.

When I go to my swagger ui docs page, it loads fine, But it tries to get https://api.domain.com:80/ instead of https://api.domain.com/ and the site says "Can't read from server. It may not have the appropriate access-control-origin settings.".

Here is my code that enables SwaggerUI:

configSwag.EnableSwagger("docs/{apiVersion}/swagger", c =>
{
    var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
    var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
    var commentsFile = Path.Combine(baseDirectory, commentsFileName);

    c.Schemes(new string[]
    {
        "https"
    });

    c.SingleApiVersion("v1", "MechaChat v1 Docs");
    c.IncludeXmlComments(commentsFile);
    c.PrettyPrint();
}).EnableSwaggerUi("v1/docs/{*assetPath}", c =>
{
    c.DocExpansion(DocExpansion.List);
    c.SupportedSubmitMethods("GET", "POST");
});

What would I need to do for the docs to get https://api.domain.com/ instead of https://api.domain.com:80/?

1 Answers

I ended up using NSwag, Seems to be working perfectly fine now!

Related