File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use Assert \Assertion ;
8
8
use Assert \AssertionFailedException ;
9
+ use Ramsey \Uuid \Uuid ;
9
10
use Symfony \Component \HttpFoundation \Request ;
10
11
use Symfony \Component \HttpFoundation \RequestStack ;
11
12
use Undabot \JsonApi \Definition \Encoding \PhpArrayToResourceEncoderInterface ;
@@ -63,6 +64,15 @@ public function createResourceRequest(): CreateResourceRequest
63
64
unset($ requestPrimaryData ['lid ' ]);
64
65
}
65
66
67
+ /**
68
+ * If no ID is already generated create new one so the write model
69
+ * can already have ID as a property. Consider having ID strategy
70
+ * set through configuration.
71
+ */
72
+ if (false === array_key_exists ('id ' , $ requestPrimaryData )) {
73
+ $ requestPrimaryData ['id ' ] = (string ) Uuid::uuid4 ();
74
+ }
75
+
66
76
$ resource = $ this ->resourceEncoder ->decode ($ requestPrimaryData );
67
77
68
78
return new CreateResourceRequest ($ resource );
You can’t perform that action at this time.
0 commit comments