Using odata 8 with AddVersionedApiExplorer braking the swagger page.
Open
@xuzhg is already working on this.
Since Feb 15, 2022.
investigating
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
In my configure services if i add these services.AddVersionedApiExplorer(); it will break the swagger and saw us swagger with
'No operations defined in spec!'
if i comment out this code it works as expected i am not sure why. any ideas
My configure services
public void ConfigureServices(IServiceCollection services)
{
services.AddVersionedApiExplorer();
services.AddControllers()
.AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(100)
.AddRouteComponents("api/management/v2", EdmModelBuilder.GetEdmModelV2())
.Conventions.Add(new CustomConvention())
//.Conventions.Remove(opt.Conventions.First(convention => convention is MetadataRoutingConvention))
);
services.AddSwaggerGen(swaggerOptions =>
{
swaggerOptions.SwaggerDoc("v2",
new OpenApiInfo
{
Title = "test Management",
Description = "This is the Swagger documentation for the test Management API.",
Version = Assembly.GetEntryAssembly().GetName().Version.ToString()
});
swaggerOptions.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "Bearer"
});
swaggerOptions.AddSecurityRequirement(new OpenApiSecurityRequirement()
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
},
Scheme = "oauth2",
Name = "Bearer",
In = ParameterLocation.Header
},
new List<string>()
}
});
swaggerOptions.DocumentFilter<SwaggerDocumentFilter>();
swaggerOptions.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"));
});
services.AddControllers(options =>
{
IEnumerable<ODataOutputFormatter> outputFormatters =
options.OutputFormatters.OfType<ODataOutputFormatter>()
.Where(formatter => !formatter.SupportedMediaTypes.Any());
foreach (var outputFormatter in outputFormatters)
{
outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/odata"));
}
IEnumerable<ODataInputFormatter> inputFormatters =
options.InputFormatters.OfType<ODataInputFormatter>()
.Where(formatter => !formatter.SupportedMediaTypes.Any());
foreach (var inputFormatter in inputFormatters)
{
inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/odata"));
}
});
AddFormatters(services);
}
Configure
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger(swaggerOptions =>
{
swaggerOptions.PreSerializeFilters.Add
(
(swagger, httpReq) =>
{
swagger.Servers = new List<OpenApiServer>
{
new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}" }
};
}
);
});
app.UseSwaggerUI(swaggerUIOptions =>
{
swaggerUIOptions.SwaggerEndpoint($"/swagger/v2/swagger.json", $"CM v2");
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}```
Controller
[ApiVersion("2.0")]
public class FoldersController : BaseController
{}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.