From 3767fb3b43f67bf009655d0eccf9fd35e60e851a Mon Sep 17 00:00:00 2001 From: Matt Blacker Date: Thu, 21 Mar 2024 15:27:47 +1100 Subject: [PATCH 1/2] Feat: Add in configuration for the OData include-annotations header. --- src/WebAPI/OData/Client.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/WebAPI/OData/Client.php b/src/WebAPI/OData/Client.php index e62ff876..549be629 100644 --- a/src/WebAPI/OData/Client.php +++ b/src/WebAPI/OData/Client.php @@ -329,16 +329,26 @@ private function buildQueryURL( string $uri, array $queryOptions = null ): strin */ private function buildQueryHeaders( array $queryOptions = null ): array { $headers = []; - $prefer = []; + $prefer = [ + 'IncludeAnnotations' => 'odata.include-annotations="*"' + ]; if ( $queryOptions != null ) { if ( isset( $queryOptions['MaxPageSize'] ) ) { $prefer[] = 'odata.maxpagesize=' . $queryOptions['MaxPageSize']; } + + if ( isset( $queryOptions['IncludeAnnotations'] ) ) { + if( $queryOptions['IncludeAnnotations'] === false ) { + unset( $prefer['IncludeAnnotations'] ); + } + else { + $prefer['IncludeAnnotations'] = 'odata.include-annotations="' . $queryOptions['IncludeAnnotations'] . '"'; + } + } } - $prefer[] = 'odata.include-annotations="*"'; - $headers['Prefer'] = implode( ',', $prefer ); + $headers['Prefer'] = implode( ',', array_values($prefer) ); return $headers; } From 1eb62620abcb358a26b4e97742a5971cd1d2ae07 Mon Sep 17 00:00:00 2001 From: Matt Blacker Date: Thu, 21 Mar 2024 16:07:14 +1100 Subject: [PATCH 2/2] Fix: when setting IncludeAnnotations "false" will set an exclusion of -* instead of previously not setting the header --- src/WebAPI/OData/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebAPI/OData/Client.php b/src/WebAPI/OData/Client.php index 549be629..7718fb1f 100644 --- a/src/WebAPI/OData/Client.php +++ b/src/WebAPI/OData/Client.php @@ -340,7 +340,7 @@ private function buildQueryHeaders( array $queryOptions = null ): array { if ( isset( $queryOptions['IncludeAnnotations'] ) ) { if( $queryOptions['IncludeAnnotations'] === false ) { - unset( $prefer['IncludeAnnotations'] ); + $prefer['IncludeAnnotations'] = 'odata.include-annotations="-*"'; } else { $prefer['IncludeAnnotations'] = 'odata.include-annotations="' . $queryOptions['IncludeAnnotations'] . '"';