Skip to content

SwaggerUI fails when running on IIS/dev-server : Service Unavailable … #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions PxWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,28 @@ public static void Main(string[] args)
x.Filters.Add(new LangValidationFilter(langList))
)
.AddNewtonsoftJson(opts =>
{
//opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opts.SerializerSettings.ContractResolver = new BaseFirstContractResolver();
opts.SerializerSettings.Converters.Add(new StringEnumConverter
{
NamingStrategy = new CamelCaseNamingStrategy()
//opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opts.SerializerSettings.ContractResolver = new BaseFirstContractResolver();
opts.SerializerSettings.Converters.Add(new StringEnumConverter
{
NamingStrategy = new CamelCaseNamingStrategy()
});
opts.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
opts.SerializerSettings.DateFormatString = "yyyy-MM-ddTHH:mm:ssZ"; // UTC
});
opts.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
opts.SerializerSettings.DateFormatString = "yyyy-MM-ddTHH:mm:ssZ"; // UTC
});


// Handle CORS configuration from appsettings.json
bool corsEnbled = builder.Services.ConfigurePxCORS(builder);

// Bind the configuration to the PxApiConfigurationOptions class
var pxApiConfiguration = new PxApiConfigurationOptions();
builder.Configuration.Bind("PxApiConfiguration", pxApiConfiguration);

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
// builder.Services.AddEndpointsApiExplorer(); //only needed for minimal APIS according to
// https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs=visual-studio
builder.Services.AddSwaggerGen(c =>
{
// Sort endpoints
Expand All @@ -129,15 +138,14 @@ public static void Main(string[] args)
Version = "v2-beta"
}
);
});


// Handle CORS configuration from appsettings.json
bool corsEnbled = builder.Services.ConfigurePxCORS(builder);
c.AddServer(new OpenApiServer
{
Url = (new Uri(pxApiConfiguration.BaseURL)).PathAndQuery,
Description = "API Base URL"
});

// Bind the configuration to the PxApiConfigurationOptions class
var pxApiConfiguration = new PxApiConfigurationOptions();
builder.Configuration.Bind("PxApiConfiguration", pxApiConfiguration);
});

var app = builder.Build();

Expand All @@ -150,7 +158,7 @@ public static void Main(string[] args)
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v2/swagger.json", "PxWebApi 2.0-beta");
options.SwaggerEndpoint("v2/swagger.json", "PxWebApi 2.0-beta");
});
}

Expand Down