You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generated code for aspnetcore with swagger generation (Swashbuckle) enabled uses the GetEntryAssembly method to specify the path to the XML comments. This causes issues if you were to test this API from a different project (assembly) as the entry assembly will be the test project and not the main project.
There is an easy workaround to this and that is to use GetExecutingAssembly instead of GetEntryAssebly which is also what Microsoft recommends:
builder.Services.AddSwaggerGen(options =>{
options.SwaggerDoc("v1",new OpenApiInfo
{
...// using System.Reflection;
var xmlFilename =$"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));});
Bug Report Checklist
Description
The generated code for aspnetcore with swagger generation (Swashbuckle) enabled uses the
GetEntryAssembly
method to specify the path to the XML comments. This causes issues if you were to test this API from a different project (assembly) as the entry assembly will be the test project and not the main project.There is an easy workaround to this and that is to use
GetExecutingAssembly
instead ofGetEntryAssebly
which is also what Microsoft recommends:openapi-generator version
7.8.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Observe test failure:
Apply simple fix, using
GetExecutingAssembly
instead ofGetEntryAssembly
, and rerun test:Observe test passing:
Related issues/PRs
Suggest a fix
Use
GetExecutingAssembly
instead.Fixed by merging #19593
The text was updated successfully, but these errors were encountered: