From fead1351779e6a1420e12c13952c8443bf0a1e8c Mon Sep 17 00:00:00 2001 From: Chris Lloyd Date: Wed, 1 Feb 2023 19:14:23 +0000 Subject: [PATCH] WIP --- config.php | 5 ++ doc/.vuepress/config.js | 1 + doc/clients/devextreme.md | 55 +++++++++++++++++++ src/Transaction/Version.php | 2 +- tests/Protocol/VersionTest.php | 8 +++ ...nTest__test_config_default_version__1.json | 14 +++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 doc/clients/devextreme.md create mode 100644 tests/__snapshots__/Protocol/VersionTest__test_config_default_version__1.json diff --git a/config.php b/config.php index f989a69ba..1882a98d5 100644 --- a/config.php +++ b/config.php @@ -32,6 +32,11 @@ */ 'namespace' => env('LODATA_NAMESPACE', 'com.example.odata'), + /* + * The default version of the OData protocol to support for every request. + */ + 'version' => env('LODATA_VERSION', '4.01'), + /* * The name of the Laravel disk to use to store asynchronously processed requests. * In a multi-server shared hosting environment, all hosts should be able to access this disk diff --git a/doc/.vuepress/config.js b/doc/.vuepress/config.js index 29c42b856..32fdb88f5 100644 --- a/doc/.vuepress/config.js +++ b/doc/.vuepress/config.js @@ -204,6 +204,7 @@ module.exports = { 'clients/dataverse', 'clients/salesforce', 'clients/sap', + 'clients/devextreme', ], }, { diff --git a/doc/clients/devextreme.md b/doc/clients/devextreme.md new file mode 100644 index 000000000..e23517888 --- /dev/null +++ b/doc/clients/devextreme.md @@ -0,0 +1,55 @@ +# DevExtreme + +DevExtreme (by DevExpress) supports OData as a [data source](https://js.devexpress.com/Documentation/Guide/Data_Binding/Specify_a_Data_Source/OData/). +However, it supports only OData 4.0, not OData 4.01. To support Lodata you must send the "OData-Version" header with every request. + +Alternatively, you can configure Lodata to default to OData 4.0 if the client does not specify a version by modifying the +[configuration](/getting-started/configuration.md) + +This Vue example shows how to send the header, and load data into a DxDataGrid. + +```vue + + +``` \ No newline at end of file diff --git a/src/Transaction/Version.php b/src/Transaction/Version.php index af8bed84f..095bb7ef9 100644 --- a/src/Transaction/Version.php +++ b/src/Transaction/Version.php @@ -33,7 +33,7 @@ public function __construct($version, $maxVersion) ); } - $this->version = ($maxVersion ?: $version) ?: self::v4_01; + $this->version = ($maxVersion ?: $version) ?: config('lodata.version', self::v4_01); } /** diff --git a/tests/Protocol/VersionTest.php b/tests/Protocol/VersionTest.php index df1bdbb6d..23a855a89 100644 --- a/tests/Protocol/VersionTest.php +++ b/tests/Protocol/VersionTest.php @@ -5,6 +5,7 @@ use Flat3\Lodata\Helper\Constants; use Flat3\Lodata\Tests\Helpers\Request; use Flat3\Lodata\Tests\TestCase; +use Flat3\Lodata\Transaction\Version; class VersionTest extends TestCase { @@ -46,5 +47,12 @@ public function test_accepts_maxversion_header() ->header(Constants::odataMaxVersion, '4.0') ); } + + public function test_config_default_version() + { + config(['lodata.version' => Version::v4_0]); + + $this->assertResponseSnapshot((new Request)); + } } diff --git a/tests/__snapshots__/Protocol/VersionTest__test_config_default_version__1.json b/tests/__snapshots__/Protocol/VersionTest__test_config_default_version__1.json new file mode 100644 index 000000000..0f4ab6d69 --- /dev/null +++ b/tests/__snapshots__/Protocol/VersionTest__test_config_default_version__1.json @@ -0,0 +1,14 @@ +{ + "headers": { + "cache-control": [ + "no-cache, private" + ], + "content-type": [ + "application/json;odata.metadata=minimal" + ], + "odata-version": [ + "4.0" + ] + }, + "status": 200 +}