Repository: api-platform/admin
Pull request #514 (2023-11-07 15:58:25)

feat: export themes
| Q             | A
| ------------- | ---
| Branch?       | main <!-- see below -->
| Tickets       |  <!-- please link related issues if existing -->
| License       | MIT
| Doc PR        | <!-- required for new features -->
<!--
Replace this notice with a short description of your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Branch: 
- the stable/latest 3.x for bug fixes
- main for new features

For security issues please email contact@les-tilleuls.coop.

Additionally:
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the current stable version branch.
 - Features and deprecations must be submitted against the main branch.
 - Legacy code removals go to the main branch.
 - Update CHANGELOG.md file.
 - Follow the [Conventional Commits specification](https://www.conventionalcommits.org/).
-->
I like to use / override parts of the themes here and was wondering why it is not exported. Is there any reason not to do so?


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ad2d97..c41b16c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 3.4.5
+
+* Fix validation errors shown as "Server communication error" when creating an entity
+
 ## 3.4.4
 
 * Enum support in field guesser
diff --git a/jest.setup.ts b/jest.setup.ts
index 85e8030..663e582 100644
--- a/jest.setup.ts
+++ b/jest.setup.ts
@@ -1,8 +1,9 @@
 // eslint-disable-next-line import/no-extraneous-dependencies
 import '@testing-library/jest-dom';
-import { TextEncoder } from 'util';
+import { TextEncoder, TextDecoder } from 'util';
 // eslint-disable-next-line import/no-extraneous-dependencies
 import { Request } from 'node-fetch';
 
 global.TextEncoder = TextEncoder;
+global.TextDecoder = TextDecoder as any;
 global.Request = Request as any;
diff --git a/package.json b/package.json
index 2e3ed5a..e833b78 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@api-platform/admin",
-  "version": "3.4.4",
+  "version": "3.4.5",
   "description": "Automatic administration interface for Hydra-enabled APIs.",
   "files": [
     "*.md",
@@ -18,7 +18,7 @@
   "license": "MIT",
   "sideEffects": false,
   "dependencies": {
-    "@api-platform/api-doc-parser": "^0.16.1",
+    "@api-platform/api-doc-parser": "^0.16.2",
     "history": "^5.0.0",
     "jsonld": "^8.1.0",
     "lodash.isplainobject": "^4.0.6",
diff --git a/src/hydra/dataProvider.ts b/src/hydra/dataProvider.ts
index 017f545..bf1ff01 100644
--- a/src/hydra/dataProvider.ts
+++ b/src/hydra/dataProvider.ts
@@ -722,7 +722,7 @@ function dataProvider(
               page: 1,
             },
             filter: { id: params.ids },
-            sort: { field: '', order: '' },
+            sort: { field: '', order: 'ASC' },
           }).then(({ data }) => ({ data }));
         }
 
diff --git a/src/hydra/fetchHydra.ts b/src/hydra/fetchHydra.ts
index 99c8afa..dcc9f70 100644
--- a/src/hydra/fetchHydra.ts
+++ b/src/hydra/fetchHydra.ts
@@ -4,7 +4,7 @@ import {
   getDocumentationUrlFromHeaders,
 } from '@api-platform/api-doc-parser';
 import jsonld from 'jsonld';
-import type { NodeObject } from 'jsonld';
+import type { ContextDefinition, NodeObject } from 'jsonld';
 import type { JsonLdObj } from 'jsonld/jsonld-spec';
 import type { HttpClientOptions, HydraHttpClientResponse } from '../types.js';
 
@@ -40,8 +40,12 @@ function fetchHydra(
 
       delete (body as NodeObject).trace;
 
-      const documentLoader = (input: string) =>
-        fetchJsonLd(input, authOptions).then((response) => {
+      const documentLoader = (input: string) => {
+        const loaderOptions = authOptions;
+        loaderOptions.method = 'GET';
+        delete loaderOptions.body;
+
+        return fetchJsonLd(input, loaderOptions).then((response) => {
           if (!('body' in response)) {
             throw new Error(
               'An empty response was received when expanding JSON-LD error document.',
@@ -49,12 +53,15 @@ function fetchHydra(
           }
           return response;
         });
+      };
+
+      return documentLoader(getDocumentationUrlFromHeaders(headers))
+        .then((response) =>
+          jsonld.expand(body, {
+            expandContext: response.document as ContextDefinition,
+          }),
+        )
 
-      return jsonld
-        .expand(body, {
-          base: getDocumentationUrlFromHeaders(headers),
-          documentLoader,
-        })
         .then((json) =>
           Promise.reject(
             new HttpError(
diff --git a/src/index.ts b/src/index.ts
index 36dd447..973f5c7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -34,6 +34,7 @@ export {
   fetchHydra,
 } from './hydra/index.js';
 export type { HydraAdminProps } from './hydra/index.js';
+export { darkTheme, lightTheme } from './layout/index.js';
 export {
   OpenApiAdmin,
   dataProvider as openApiDataProvider,
diff --git a/src/types.ts b/src/types.ts
index f060ef1..30032f7 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -226,22 +226,22 @@ export type ApiPlatformAdminDataProviderTypeParams<T extends DataProviderType> =
   T extends typeof GET_LIST
     ? ApiPlatformAdminGetListParams
     : T extends typeof GET_ONE
-    ? ApiPlatformAdminGetOneParams
-    : T extends typeof GET_MANY
-    ? ApiPlatformAdminGetManyParams
-    : T extends typeof GET_MANY_REFERENCE
-    ? ApiPlatformAdminGetManyReferenceParams
-    : T extends typeof UPDATE
-    ? ApiPlatformAdminUpdateParams
-    : T extends typeof UPDATE_MANY
-    ? ApiPlatformAdminUpdateManyParams
-    : T extends typeof CREATE
-    ? ApiPlatformAdminCreateParams
-    : T extends typeof DELETE
-    ? ApiPlatformAdminDeleteParams
-    : T extends typeof DELETE_MANY
-    ? ApiPlatformAdminDeleteManyParams
-    : never;
+      ? ApiPlatformAdminGetOneParams
+      : T extends typeof GET_MANY
+        ? ApiPlatformAdminGetManyParams
+        : T extends typeof GET_MANY_REFERENCE
+          ? ApiPlatformAdminGetManyReferenceParams
+          : T extends typeof UPDATE
+            ? ApiPlatformAdminUpdateParams
+            : T extends typeof UPDATE_MANY
+              ? ApiPlatformAdminUpdateManyParams
+              : T extends typeof CREATE
+                ? ApiPlatformAdminCreateParams
+                : T extends typeof DELETE
+                  ? ApiPlatformAdminDeleteParams
+                  : T extends typeof DELETE_MANY
+                    ? ApiPlatformAdminDeleteManyParams
+                    : never;
 
 export interface ApiPlatformAdminDataProviderFactoryParams {
   entrypoint: string;


Test patch:
diff --git a/src/hydra/dataProvider.test.ts b/src/hydra/dataProvider.test.ts
index 44674b4..1d07e17 100644
--- a/src/hydra/dataProvider.test.ts
+++ b/src/hydra/dataProvider.test.ts
@@ -138,7 +138,7 @@ describe('Transform a React Admin request to an Hydra request', () => {
         perPage: 30,
       },
       sort: {
-        order: '',
+        order: 'ASC',
         field: '',
       },
       filter: {