-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
.NET 9 - OpenAPI Not Generating Output #58805
Comments
Please turn on more logging (debug/trace) so you can see the exception details, or set a breakpoint on InvalidOperationException in VS so you can see where the exception is coming from. |
the actual exception is:
Line 88 in Jwtmiddleware is simply:
|
@sbwalker Are there any controller actions in your application that take advantage of custom model binding from the route and/or query parameter as opposed to the body? |
Yes there are controller methods that rely on query parameters ie.
|
I too am not getting any output, just ERR_EMPTY_RESPONSE. I don't see any exceptions in the output log though. services
.AddControllers(options =>
{
options.Conventions.Add(new ContentNegotiationActionModelConvention());
options.InputFormatters.Insert(0, JsonPatchExtensions.GetJsonPatchInputFormatter());
options.ReturnHttpNotAcceptable = false;
})
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new TypeDiscriminatingConverter());
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
options.JsonSerializerOptions.Converters.Add(new NonPublicConstructorJsonConverterFactory());
options.JsonSerializerOptions.Converters.Add(new JTokenConverterFactory());
options.JsonSerializerOptions.Converters.Add(new JsonPatchDocumentConverterFactory());
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.MakeReadOnly();
});
services.AddOpenApi(); app.UseEndpoints(endpoints =>
{
endpoints.MapOpenApi("/openapi/api.json");
endpoints.MapControllers();
endpoints.MapHealthChecks(
"/healthz/live",
new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
Predicate = (_) => false,
})
.ShortCircuit();
endpoints.MapHealthChecks(
"/healthz/ready",
new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
Predicate = healthCheck => healthCheck.Tags.Contains("ready"),
},
TimeSpan.FromSeconds(30));
endpoints.MapHealthChecks(
"/health",
new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});
}); |
After disabling Just My Code I am now seeing the exception
|
I add this just to test and I still receive the "Cannot resolve scoped service 'Microsoft.Extensions.Options.IOptionsSnapshot`1[Microsoft.AspNetCore.OpenApi.OpenApiOptions]" error services.AddOpenApi();
services.AddScoped<IOptionsSnapshot<OpenApiOptions>>(sp =>
{
OpenApiOptions options = new();
return new StaticOptions<OpenApiOptions>(options);
}); |
I am facing the same issue as @trevonmckay . I eventually found out that when I set the ASPNETCORE_ENVIRONMENT to I'm using the latest 9.0.0 versie that was released (as of today) 20 days ago. |
I tried recreating this problem and was unsuccessful. What I did:
Running this project produces a (rather empty) OpenAPI document at /openapi/v1.json. Is there something I can do in this project to recreate the problem or do I need to take a completely different path? |
@trevonmckay @BoerG-RDW Can you provide a simplified GitHub repo that reproduces the problem you're seeing? |
Really strange. I'm still not sure what is causing it, but I threw out everything that I didn't need, made a copy of only the source code + project/solution file. The copy worked fine. Finally had a look at the hidden directories and when I threw out the .vs directory, it started working suddenly. It's mostly binary stuff inside that directory, so I can't really see what the actual problem is, but throwing out that directory fixed the issue for me. Visual Studio will recreate it automatically, so I don't think you'll loose anything if you throw it out. The config directory inside the |
@danroth27 I have provided some repro steps:
Choose SQLite as the Database option
You will see a blank screen with no output: |
I've managed to get this working now with two changes public class StaticOptions<TOptions> : IOptionsSnapshot<TOptions>
where TOptions : class
{
private readonly TOptions _options;
public StaticOptions(TOptions options)
{
_options = options;
}
public TOptions Value
{
get
{
return _options;
}
}
public TOptions Get(string name)
{
return _options;
}
} Manually adding the IOptionsSnapshot as a singleton services.AddSingleton<IOptionsSnapshot<OpenApiOptions>>(sp =>
{
OpenApiOptions options = new();
return new StaticOptions<OpenApiOptions>(options);
});
services.AddOpenApi(); which resolved the "Cannot resolve scoped service 'Microsoft.Extensions.Options.IOptionsSnapshot`1[Microsoft.AspNetCore.OpenApi.OpenApiOptions]" error. That revealed another error, the JSON MaxDepth was exceeded during the document generation. Increasing the max depth to 256 seemed to do the trick for that. services.Configure<JsonOptions>(jsonOptions =>
{
jsonOptions.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
jsonOptions.SerializerOptions.MaxDepth = 256;
jsonOptions.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
jsonOptions.SerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
}); |
I was able to repro with these steps. It looks like what you're seeing is indeed the same issue as #59013 which was resolved in #59035. I can open a backport for this issue to .NET 9. @BoerG-RDW @trevonmckay The issue you are seeing are distinct from the Oqtane issue that is reported here. I'd recommend filing another issue for that. In the meantime, I'll close this as a dupe of #59013 and track a backport for that. |
Hello everyone,
I’m not sure where this should be posted or where it belongs. I’ll write it here for now, but please let me know if I should post it somewhere else. I’m also having issues with OpenAPI generation. I’m using a minimal API and just experimenting with the .NET framework. I’ve followed the approach described in the documentation here and moved my route handlers into separate files.
However, OpenAPI does not recognize these routes and only generates the JSON file with the routes registered in program.cs. Could this be related to the bug mentioned here? That's how the generated JSON File looks like:
|
@wolfgang-hartl Your best bet is to file an new issue with a pointer to your sample code (https://github.com/dotnet/aspnetcore/issues/new). In particular, the implementation for |
@captainsafia that was fast! :-) Thanks for your response - i will do that. The Implementation is just a copy/paste from the docs mentioned, but i will write that all together and create a new issue 👍 |
Is there an existing issue for this?
Describe the bug
I am trying to integrate OpenAPI into an existing Blazor project which was recently upgraded to .NET 9.
I added the following project reference to the Server project:
I modified the Startup.cs (yes this project has never migrated to the "new" Program.cs approach - but that should not affect the result):
Note that this application is using traditional Controllers and Razor Pages - not minimal APIs.
When I run the application and browse to /openapi/v1.json I get a blank screen with no output:
The Visual Studio console contains the following information:
Expected Behavior
Browsing to /openapi/v1.json should display the Open API document
Steps To Reproduce
No response
Exceptions (if any)
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
.NET Version
9.0.0-rc.2.24473.5
Anything else?
Note that this application already had Swagger integrated previously:
and the Swagger UI still works fine:
The text was updated successfully, but these errors were encountered: