Skip to content

Fix AutoExpand Issues with Capitalized $Expand System Query Options - #1292

Merged
WanjohiSammy merged 16 commits into
release-8.xfrom
fix/1284-autoexpand-and-autoexpand-issue
Sep 6, 2024
Merged

Fix AutoExpand Issues with Capitalized $Expand System Query Options#1292
WanjohiSammy merged 16 commits into
release-8.xfrom
fix/1284-autoexpand-and-autoexpand-issue

Conversation

@WanjohiSammy

@WanjohiSammy WanjohiSammy commented Aug 5, 2024

Copy link
Copy Markdown
Member

Issues

This pull request fixes #1284.

Description

When using AutoExpand, and specifying a system query option that's not lower case (such as $Expand) an exception is thrown. The exception indicates that Expand is being added twice.

"message": "The query specified in the URI is not valid. Query option '$expand/expand' was specified more than once, but it must be specified at most once.",

This change is to resolve issues with the AutoExpand when using capitalized $Expand system query options

For example, given the following entities where Friends prop and Trip class are AutoExpand

public class Person
{
    public int Id { get; set; }

    public string? Name { get; set; }

    public IList<WeekDay>? WorkingDays { get; set; }

    [AutoExpand]
    public virtual ICollection<Person> Friends { get; set; }

    public virtual ICollection<Trip> Trips { get; set; }
}

[AutoExpand]
public class Trip
{
    public int Id { get; set; }

    public string? Name { get; set; }
}

With this change, we should be able to use $Expand(capitalized of $expand) with the AutoExpand navigation properties:

/People?$Expand=Friends
/People?$Expand=Trips
/People?$Expand=Friends,Trips
/People?$EXPAND=Friends

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

Comment thread src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs
Comment thread src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
@habbes

habbes commented Aug 14, 2024

Copy link
Copy Markdown
Contributor

@WanjohiSammy does this issue only affect AutoExpand? Also do we have tests for query options without a $ prefix?

@WanjohiSammy

Copy link
Copy Markdown
Member Author

@WanjohiSammy does this issue only affect AutoExpand? Also do we have tests for query options without a $ prefix?

@habbes This addresses the issue of Select or Expand AutoExpand navigation property using capitalized Select or Expand with or without $ prefix. I have added tests for query options without a $ prefix

Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Query/Query/ODataQueryOptionConstants.cs Outdated
@WanjohiSammy
WanjohiSammy requested review from habbes and xuzhg August 26, 2024 15:03
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
Comment thread test/Microsoft.AspNetCore.OData.E2E.Tests/AutoExpand/AutoExpandTests.cs Outdated
@WanjohiSammy
WanjohiSammy merged commit a77ed76 into release-8.x Sep 6, 2024
WanjohiSammy added a commit that referenced this pull request Sep 9, 2024
…1292)

* Fix AutoExpand Issues with Capitalized $Expand System Query Options (#1292)
WanjohiSammy added a commit that referenced this pull request Sep 9, 2024
…1292)

* Fix AutoExpand Issues with Capitalized $Expand System Query Options (#1292)
WanjohiSammy added a commit that referenced this pull request Oct 25, 2024
… System Query Options (#1309)

* Fix AutoExpand Issues with Capitalized $Expand System Query Options (#1292)
@WanjohiSammy
WanjohiSammy deleted the fix/1284-autoexpand-and-autoexpand-issue branch November 13, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoExpand not working correctly with $Expand uri query parameters

4 participants