OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
446 stars 155 forks source link

Optional parameters is required (path) after bumping #1132

Open cfauchere opened 6 months ago

cfauchere commented 6 months ago

Assemblies affected

    <PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.11" />
    <PackageReference Include="Asp.Versioning.OData" Version="7.1.0" />
    <PackageReference Include="Asp.Versioning.OData.ApiExplorer" Version="7.1.0" />

Describe the bug Before bumping version optional function parameter was passed as query but is not in path.

Data Model

var subscription = builder.EntityType<CloudServiceSubscriptionDto>().HasKey(x => x.Key);
subscription.Abstract();
subscription.Function("Networks").ReturnsCollection<Network>().Parameter<string>("location").Optional();

EDM (CSDL) Model

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="UIPath.Hypervisor">
<EntityType Name="CloudServiceSubscription" Abstract="true">
<Key>
<PropertyRef Name="key"/>
</Key>
<Property Name="key" Type="Edm.Guid" Nullable="false"/>
<Property Name="name" Type="Edm.String" Nullable="false"/>
<Property Name="description" Type="Edm.String"/>
<Property Name="insertedDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
<Property Name="updatedDateTime" Type="Edm.DateTimeOffset" Nullable="false"/>
</EntityType>
<ComplexType Name="Network">
<Property Name="subnets" Type="Collection(UIPath.Hypervisor.Subnet)" Nullable="false"/>
<Property Name="id" Type="Edm.String"/>
<Property Name="name" Type="Edm.String"/>
<Property Name="location" Type="Edm.String"/>
</ComplexType>
<EntityType Name="AzureSubscription" BaseType="UIPath.Hypervisor.CloudServiceSubscription">
<Property Name="subscriptionId" Type="Edm.String" Nullable="false"/>
<Property Name="clientId" Type="Edm.String" Nullable="false"/>
<Property Name="tenantId" Type="Edm.String" Nullable="false"/>
</EntityType>
<EntityType Name="AWSSubscription" BaseType="UIPath.Hypervisor.CloudServiceSubscription">
<Property Name="accessKey" Type="Edm.String" Nullable="false"/>
</EntityType>
<EntityType Name="GCPSubscription" BaseType="UIPath.Hypervisor.CloudServiceSubscription">
<Property Name="projectId" Type="Edm.String" Nullable="false"/>
</EntityType>
<ComplexType Name="AzureSubscriptionEditOrAddRequest">
<Property Name="subscriptionId" Type="Edm.String"/>
<Property Name="tenantId" Type="Edm.String"/>
<Property Name="clientId" Type="Edm.String"/>
<Property Name="clientSecret" Type="Edm.String"/>
<Property Name="name" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="AWSSubscriptionEditOrAddRequest">
<Property Name="accessKey" Type="Edm.String"/>
<Property Name="secretKey" Type="Edm.String"/>
<Property Name="name" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
</ComplexType>
<ComplexType Name="GCPSubscriptionEditOrAddRequest">
<Property Name="projectId" Type="Edm.String"/>
<Property Name="privateKey" Type="Edm.String"/>
<Property Name="name" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
</ComplexType>
<Function Name="Networks" IsBound="true">
<Parameter Name="bindingParameter" Type="UIPath.Hypervisor.CloudServiceSubscription"/>
<Parameter Name="location" Type="Edm.String">
<Annotation Term="Org.OData.Core.V1.OptionalParameter"/>
</Parameter>
<ReturnType Type="Collection(UIPath.Hypervisor.Network)"/>
</Function>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

Expected behavior Function parameters can be passed as query

Screenshots Before bumping image After bumping image

See that location was in query before

Bonus question

why $select is now select?

aboryczko commented 6 months ago

Hi, /odata/Subscriptions/{key}/Networks(location=location) is the proper function invocation. /odata/Subscriptions/{key}/Networks?location=location is an implicit parameter alias. You can check it here in the specification.

Both should work fine when making requests. I think that the team that works on the Open API integration decided that it's not good to clutter the spec with all possible invocation variants and they chose this one to be displayed.

As for the select without $, it should work because it's allowed but I would imagine that it should display $select which is the "offical" variant.

xuzhg commented 6 months ago

@cfauchere what do you mean bumping?

habbes commented 6 months ago

Hello @cfauchere I have the same question as @xuzhg. When you say "before bumping version", it's not clear what you're referring. Which version of which library did you bump to which other version?

You've also listed multiple libraries as dependencies. The Asp.Versioning.OData libraries are a separate project maintained here: https://github.com/dotnet/aspnet-api-versioning.

According to the README of the project, it appears that the version of Asp.Versioning.OData.* used with ASP.NET Core and OData is 8.x, not 7.x. Since you're presumably using ASP.NET Core OData 8.x, you may try updating to Asp.Versioning.OData.* 8.x and see whether that helps.