Skip to content
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

Open
1 task done
sbwalker opened this issue Nov 5, 2024 · 2 comments
Open
1 task done

.NET 9 - OpenAPI Not Generating Output #58805

sbwalker opened this issue Nov 5, 2024 · 2 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi

Comments

@sbwalker
Copy link

sbwalker commented Nov 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

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:

    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-rc.2.24474.3" />

I modified the Startup.cs (yes this project has never migrated to the "new" Program.cs approach - but that should not affect the result):

        public void ConfigureServices(IServiceCollection services)
        {
            ...
            services.AddMvc();
            services.AddRazorPages();
            services.AddOpenApi();
            ...
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
        {
            ...
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapOpenApi();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
            });
            ...
        }

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:

Image

The Visual Studio console contains the following information:

Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executing endpoint 'HTTP: GET /openapi/{documentName}.json'
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint 'HTTP: GET /openapi/{documentName}.json'
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished HTTP/1.1 GET http://localhost:44357/openapi/v1.json - 200 - - 981.2280ms

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:

            services.AddSwaggerGen(options =>
            {
                options.CustomSchemaIds(type => type.ToString()); // Handle SchemaId already used for different type
            });
            services.TryAddSwagger(_useSwagger);

...

            if (_useSwagger)
            {
                app.UseSwagger();
                app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/" + Constants.Version + "/swagger.json", Constants.PackageId + " " + Constants.Version); });
            }

and the Swagger UI still works fine:

Image

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Nov 5, 2024
@sbwalker sbwalker changed the title .NET 9 - OpenAPI Not Generating OutPut .NET 9 - OpenAPI Not Generating Output Nov 5, 2024
@martincostello martincostello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Nov 5, 2024
@BrennanConroy
Copy link
Member

BrennanConroy commented Nov 5, 2024

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.

@sbwalker
Copy link
Author

sbwalker commented Nov 5, 2024

the actual exception is:

Unsupported parameter source: ModelBinding
Microsoft.AspNetCore.OpenApi
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<GetParametersAsync>d__28.MoveNext()
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<GetOperationAsync>d__21.MoveNext()
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<GetOperationsAsync>d__20.MoveNext()
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<GetOpenApiPathsAsync>d__19.MoveNext()
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<GetOpenApiDocumentAsync>d__12.MoveNext()
   at Microsoft.AspNetCore.Builder.OpenApiEndpointRouteBuilderExtensions.<>c__DisplayClass0_0.<<MapOpenApi>b__0>d.MoveNext()
   at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>F56B68D2B55B5B7B373BA2E4796D897848BC0F04A969B1AF6260183E8B9E0BAF2__GeneratedRouteBuilderExtensionsCore.<>c__DisplayClass2_0.<<MapGet0>g__RequestHandler|5>d.MoveNext()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<<Invoke>g__AwaitRequestTask|7_0>d.MoveNext()
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.<Invoke>d__5.MoveNext()
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__6.MoveNext()
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.<Invoke>d__11.MoveNext()
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
   at Oqtane.Infrastructure.JwtMiddleware.<Invoke>d__2.MoveNext() 
   in C:\Source\Projects\oqtane.framework\Oqtane.Server\Infrastructure\Middleware\JwtMiddleware.cs:line 88

Line 88 in Jwtmiddleware is simply:

if (_next != null) await _next(context);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi
Projects
None yet
Development

No branches or pull requests

3 participants