Skip to content

Custom parameters ($count=true) are not rendered for $expand #1180

@eugene-andreev

Description

@eugene-andreev

Issue descritpion

Given the following code snippets:

StructuredQuery s = StructuredQuery.onEntity("A", V4)
            .select(StructuredQuery.onEntity("B", V4) // isRoot = true
                    .withInlineCount());

s.getQueryString();

Output: $expand=B($count=true) 👍

StructuredQuery s2 = StructuredQuery.onEntity("A", V4)
            .select(StructuredQuery.asNestedQueryOnProperty("B", V4) // isRoot = false
                    .withInlineCount());

s2.getQueryString();

Output: $expand=B unexpected 👎


Root cause

The issue is that the QuerySerializer checks the query.isRoot() and renders custom parameters only if statement is true. However for the inlineCount option of an expanded subquery this fails and produces the wrong result.

As CAP Java relies on the Cloud SDK impl and translates the CDS queries generically this causes the issues for our stakeholders.
I see here 2 options:

  1. either add a whitelist of custom parameters to be always rendered (disregarding whether it's root or not), like inlineCount;
  2. simply render all custom params that the user specified.

Steps to Reproduce

    StructuredQuery s = StructuredQuery.onEntity("A", V4)
            .select(StructuredQuery.onEntity("B", V4) // root
                    .withInlineCount());

Output: $expand=B($count=true) as expected

    StructuredQuery s2 = StructuredQuery.onEntity("A", V4)
            .select(StructuredQuery.asNestedQueryOnProperty("B", V4) // nested
                    .withInlineCount());

Output: $expand=B unexpected

Expected Behavior

Output: $expand=B($count=true)

Used Versions

Apache Maven 3.9.12
Java version: 25.0.3, vendor: SAP SE
CAP Java: 5.0.0-SNAPSHOT

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions