@@ -110,6 +110,15 @@ final protected function getFeatures(): array
110110 );
111111 }
112112
113+ /**
114+ * Seperate get features function to get features without the formfields. This is needed to generate the openAPI documentation
115+ * TODO: This function could probably be used in the patch endpoints aswell, since formfields are not relevant there.
116+ */
117+ public function getFeaturesWithoutFormfields (): array {
118+ $ features = call_user_func ($ this ->getDBAclass () . '::getFeatures ' );
119+ return $ this ->mapFeatures ($ features );
120+ }
121+
113122 /**
114123 * Get features based on DBA model features
115124 *
@@ -343,7 +352,7 @@ protected function getFilterACL(): array
343352
344353 /**
345354 * Helper function to determine if $resourceRecord is a valid resource record
346- * returns true if it is a valid resource record and false if it is an invallid resource record
355+ * returns true if it is a valid resource record and false if it is an invalid resource record
347356 */
348357 final protected function validateResourceRecord (mixed $ resourceRecord ): bool
349358 {
@@ -356,7 +365,7 @@ final protected function ResourceRecordArrayToUpdateArray($data, $parentId)
356365 foreach ($ data as $ item ) {
357366 if (!$ this ->validateResourceRecord ($ item )) {
358367 $ encoded_item = json_encode ($ item );
359- throw new HttpErrorException ('Invallid resource record given in list! invalid resource record: ' . $ encoded_item );
368+ throw new HttpErrorException ('Invalid resource record given in list! invalid resource record: ' . $ encoded_item );
360369 }
361370 $ updates [] = new MassUpdateSet ($ item ["id " ], $ parentId );
362371 }
@@ -380,7 +389,7 @@ public static function getManyResources(object $apiClass, Request $request, Resp
380389 $ pageAfter = $ apiClass ->getQueryParameterFamilyMember ($ request , 'page ' , 'after ' ) ?? 0 ;
381390 $ pageSize = $ apiClass ->getQueryParameterFamilyMember ($ request , 'page ' , 'size ' ) ?? $ defaultPageSize ;
382391 if ($ pageSize < 0 ) {
383- throw new HttpErrorException ("Invallid parameter, page[size] must be a positive integer " , 400 );
392+ throw new HttpErrorException ("Invalid parameter, page[size] must be a positive integer " , 400 );
384393 } elseif ($ pageSize > $ maxPageSize ) {
385394 throw new HttpErrorException (sprintf ("You requested a size of %d, but %d is the maximum. " , $ pageSize , $ maxPageSize ), 400 );
386395 }
@@ -714,7 +723,7 @@ public function patchOne(Request $request, Response $response, array $args): Res
714723
715724 // Return updated object
716725 $ newObject = $ this ->getFactory ()->get ($ object ->getId ());
717- return self ::getOneResource ($ this , $ newObject , $ request , $ response , 201 );
726+ return self ::getOneResource ($ this , $ newObject , $ request , $ response , 200 );
718727 }
719728
720729
@@ -1003,8 +1012,18 @@ public function patchToManyRelationshipLink(Request $request, Response $response
10031012 if ($ jsonBody === null || !array_key_exists ('data ' , $ jsonBody ) || !is_array ($ jsonBody ['data ' ])) {
10041013 throw new HttpErrorException ('No data was sent! Send the json data in the following format: {"data":[{"type": "foo", "id": 1}}] ' );
10051014 }
1015+
10061016 $ data = $ jsonBody ['data ' ];
1017+ $ this ->updateToManyRelationship ($ request , $ data , $ args );
10071018
1019+ return $ response ->withStatus (204 )
1020+ ->withHeader ("Content-Type " , "application/vnd.api+json " );
1021+ }
1022+
1023+ /**
1024+ * Overidable function to update the to many relationship
1025+ */
1026+ protected function updateToManyRelationship (Request $ request , array $ data , array $ args ): void {
10081027 $ relation = $ this ->getToManyRelationships ()[$ args ['relation ' ]];
10091028 $ primaryKey = $ this ->getPrimaryKeyOther ($ relation ['relationType ' ]);
10101029 $ relationKey = $ relation ['relationKey ' ];
@@ -1030,7 +1049,7 @@ public function patchToManyRelationshipLink(Request $request, Response $response
10301049 foreach ($ data as $ item ) {
10311050 if (!$ this ->validateResourceRecord ($ item )) {
10321051 $ encoded_item = json_encode ($ item );
1033- throw new HttpErrorException ('Invallid resource record given in list! invalid resource record: ' . $ encoded_item );
1052+ throw new HttpErrorException ('Invalid resource record given in list! invalid resource record: ' . $ encoded_item );
10341053 }
10351054 $ updates [] = new MassUpdateSet ($ item ["id " ], $ args ["id " ]);
10361055 unset($ modelsDict [$ item ["id " ]]);
@@ -1050,9 +1069,6 @@ public function patchToManyRelationshipLink(Request $request, Response $response
10501069 if (!$ factory ->getDB ()->commit ()) {
10511070 throw new HttpErrorException ("Was not able to update to many relationship " );
10521071 }
1053-
1054- return $ response ->withStatus (204 )
1055- ->withHeader ("Content-Type " , "application/vnd.api+json " );
10561072 }
10571073
10581074 /**
@@ -1158,7 +1174,7 @@ protected function updateObject(object $object, array $data, array $processed =
11581174 */
11591175 final public function getPatchValidFeatures (): array
11601176 {
1161- $ aliasedfeatures = $ this ->getAliasedFeatures ();
1177+ $ aliasedfeatures = $ this ->getFeaturesWithoutFormfields ();
11621178 $ validFeatures = [];
11631179
11641180 // Generate listing of validFeatures
0 commit comments