Closed
Description
This is a question, do not know if it is a issue.
I am doing MediaTypeApiVersioning and when I enable swagger. When doing Put/Post with jason body I get a 415 for all except the "application/x-www-form-urlencoded" Content-Type. If I comment out the EnableSwagger part, everything works as it should.
I am using versioning v2.0.1 & apiExplorer v1.0.1.
This is the config for versioning and swagger that i am using.
// we only need to change the default constraint resolver for services that want urls with versioning like: ~/v{version}/{controller}
var constraintResolver = new DefaultInlineConstraintResolver() { ConstraintMap = { ["apiVersion"] = typeof(ApiVersionRouteConstraint) } };
// reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
configuration.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.ApiVersionReader = new MediaTypeApiVersionReader();
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionSelector = new CurrentImplementationApiVersionSelector(options);
});
configuration.MapHttpAttributeRoutes(constraintResolver);
// add the versioned IApiExplorer and capture the strongly-typed implementation (e.g. VersionedApiExplorer vs IApiExplorer)
// note: the specified format code will format the version as "'v'major[.minor][-status]"
var apiExplorer = configuration.AddVersionedApiExplorer(o => o.GroupNameFormat = "'v'VVV");
configuration.EnableSwagger(
"{apiVersion}/swagger",
swagger =>
{
// build a swagger document and endpoint for each discovered API version
swagger.MultipleApiVersions(
(apiDescription, version) => apiDescription.GetGroupName() == version,
info =>
{
foreach (var group in apiExplorer.ApiDescriptions)
{
var description = "This is Project, configurator proxy service api.";
if (group.IsDeprecated)
{
description += " This API version has been deprecated.";
}
info.Version(group.Name, $"Project Services {group.ApiVersion}")
//.Contact(c => c.UserName("Contact UserName").UserEmail("somename@company.com"))
.Description(description);
//.License(l => l.UserName("MIT").Url("https://opensource.org/licenses/MIT"))
//.TermsOfService("Shareware");
}
});
// add a custom operation...
swagger.OperationFilter<SwaggerDefaultValues>();
// integrate xml comments
swagger.IncludeXmlComments(XmlCommentsFilePath);
})
.EnableSwaggerUi(swagger => swagger.EnableDiscoveryUrlSelector());
BR
Thomas Cronholm