domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.17k stars 1.28k forks source link

Using OData and standard REST APIs ends up having OData media types for all APIs #2749

Open PavloPaitak opened 6 months ago

PavloPaitak commented 6 months ago

After adding OData with example configurations, and having standard REST APIs, Swagger shows OData medi types for each API and NSwag generates OData media types for each standard REST API. And after I use it as a Client lib it throws an exception.

image image image

Code:

            .AddControllers()
            .AddOData(options =>
            {
                options
                    .Conventions
                    .Remove(options.Conventions.OfType<MetadataRoutingConvention>().First());
                options
                    .EnableQueryFeatures(100)
                    .AddRouteComponents(
                        Routes.SystemApiOdata.Prefix,
                        SystemEdmModelConfiguration.GetEdmModel(),
                        new DefaultODataBatchHandler());
            })
            .AddJsonOptions(jsonOptions =>
            {
                jsonOptions.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
                jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                jsonOptions.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            });

...

        app.MapControllers();

Used: ASP Net Core Web Api .Net6

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.2.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
Havunen commented 4 months ago

What is the expected behavior?

martincostello commented 2 months ago

Which media types are you expecting to be returned?

The [Produces] attribute can usually be used to customise the behaviour.

PavloPaitak commented 2 months ago

@Havunen Expected behavior: To not see the OData media types for all existing apis that do not use OData.

PavloPaitak commented 2 months ago

@martincostello Yes, the [Produces] attribute can be used to customize it manually, but I would like to see OData media types in swagger only for APIs that use OData not all existing already when I add OData.