Browse Source

Configure OpenAPI for complex nested type schemas

Update Startup.cs OpenAPI configuration to handle deeply nested types:

- Add CreateSchemaReferenceId callback to use simple type names,
  reducing schema complexity and improving readability
- Increase JsonSerializerOptions.MaxDepth to 256 to accommodate
  complex nested ViewModels during schema generation
- Change OpenAPI endpoint path to /api/openapi/{documentName}.json
  to avoid conflicts with static files in wwwroot/openapi/

These changes allow runtime OpenAPI generation to complete successfully
for all 164 API endpoints without hitting depth limits or memory issues.

Note: Runtime generation requires ~4GB RAM due to complex schema
processing. Static files are still served for production use.
pull/2735/head
Adam Jacob Muller 7 months ago
parent
commit
95a4ec8de0
  1. 23
      ErsatzTV/Startup.cs

23
ErsatzTV/Startup.cs

@ -151,7 +151,17 @@ public class Startup @@ -151,7 +151,17 @@ public class Startup
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(FileSystemLayout.DataProtectionFolder));
services.AddOpenApi("v1", options => { options.ShouldInclude += a => a.GroupName == "general"; });
services.AddOpenApi("v1", options =>
{
options.ShouldInclude += a => a.GroupName == "general";
// Increase MaxDepth for complex nested types
options.CreateSchemaReferenceId = (type) =>
{
// Use simple type names to reduce schema complexity
return type.Type.Name;
};
});
services.AddOpenApi(
"scripted-schedule-tagged",
@ -178,7 +188,11 @@ public class Startup @@ -178,7 +188,11 @@ public class Startup
});
});
services.ConfigureHttpJsonOptions(o => o.SerializerOptions.NumberHandling = JsonNumberHandling.Strict);
services.ConfigureHttpJsonOptions(o =>
{
o.SerializerOptions.NumberHandling = JsonNumberHandling.Strict;
o.SerializerOptions.MaxDepth = 256; // Increased for OpenAPI schema generation with nested types
});
OidcHelper.Init(Configuration);
JwtHelper.Init(Configuration);
@ -657,10 +671,7 @@ public class Startup @@ -657,10 +671,7 @@ public class Startup
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
if (CurrentEnvironment.IsDevelopment())
{
endpoints.MapOpenApi();
}
endpoints.MapOpenApi("/api/openapi/{documentName}.json");
endpoints.MapScalarApiReference("/docs", options =>
{

Loading…
Cancel
Save