Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PavloPaitak opened this issue Dec 14, 2023 · 4 comments
Labels
help-wanted A change up for grabs for contributions from the community

Comments

@PavloPaitak
Copy link

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
Copy link

Havunen commented Feb 17, 2024

What is the expected behavior?

@martincostello
Copy link
Collaborator

Which media types are you expecting to be returned?

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

@PavloPaitak
Copy link
Author

PavloPaitak commented Apr 15, 2024

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

@PavloPaitak
Copy link
Author

PavloPaitak commented Apr 15, 2024

@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.

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

3 participants