简体   繁体   中英

Swashbuckle OData Mapping with EnableUnqualifiedNameCall

I have the following Action

POST /odata/Individuals({individualId})/Default.SendEmail

Swagger documentation generation using Swashbuckle is setup and configured for OData and documents this correctly.

When I enable Unqualified Name Calls with

config.EnableUnqualifiedNameCall(true);

the route works correctly with

POST /odata/Individuals({individualId})/SendEmail

However Swagger still shows the original with the "Default." prefix, and the test no longer works from the Swagger UI.

How can I either allow both Default.SendEmail and SendEmail, or get Swagger to update correctly based on EnableUnqualifiedNameCall?

The same happen to me, the only way I found to solve it was removing the prefix with a regular expression in a documentFilter.

c.DocumentFilter(() => new SwaggerDocumentFilter());

class SwaggerDocumentFilter : IDocumentFilter
{
    public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
    {
    swaggerDoc.paths = swaggerDoc.paths.Select(entry=>
      new {
        key = new Regex(ODataNameSpace + @"\.",
                  RegexOptions.Compiled | RegexOptions.IgnoreCase)
            .Replace(entry.key, string.Empty),
        value = entry.Value
     })
    }
}

Getting the same namespace set in the property of the ODataConventionModelBuilder object (regretfuly, removing it is not a valid option)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM