Skip to content

Commit 73821e1

Browse files
author
jessevz
committed
Fixed return format in swagger API for POST and PATCH
1 parent 890ef34 commit 73821e1

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/inc/apiv2/common/openAPISchema.routes.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ function makeProperties($features, $skipPK=false): array {
194194
return $propertyVal;
195195
};
196196

197-
function buildPatchPost($properties, $id=null): array {
197+
function buildPatchPost($properties, $name, $id=null): array {
198198
$result = ["data" => [
199199
"type" => "object",
200200
"properties" => [
201201
"type" => [
202-
"type" => "string"
202+
"type" => "string",
203+
"default" => $name
203204
],
204205
"attributes" => [
205206
"type" => "object",
@@ -387,18 +388,23 @@ function makeDescription($isRelation, $method, $singleObject): string {
387388
*/
388389
if (array_key_exists($name, $components) == false) {
389390
$properties_return_post_patch = [
390-
"id" => [
391-
"type" => "integer",
392-
],
393-
"type" => [
394-
"type" => "string",
395-
"default" => $name
396-
],
397391
"data" => [
398392
"type" => "object",
399-
"properties" => makeProperties($class->getFeaturesWithoutFormfields(), true)
393+
"properties" => [
394+
"id" => [
395+
"type" => "integer",
396+
],
397+
"type" => [
398+
"type" => "string",
399+
"default" => $name
400+
],
401+
"attributes" => [
402+
"type" => "object",
403+
"properties" => makeProperties($class->getFeaturesWithoutFormfields(), true)
404+
],
405+
],
400406
]
401-
];
407+
];
402408

403409
$relationships = ["relationships" =>[
404410
"type" => "object",
@@ -419,9 +425,9 @@ function makeDescription($isRelation, $method, $singleObject): string {
419425
$json_api_header = makeJsonApiHeader();
420426
$links = makeLinks($uri);
421427
$properties_return_post_patch = array_merge($json_api_header, $properties_return_post_patch);
422-
$properties_create = buildPatchPost(makeProperties($class->getAllPostParameters($class->getCreateValidFeatures(), true)));
428+
$properties_create = buildPatchPost(makeProperties($class->getAllPostParameters($class->getCreateValidFeatures(), true)), $name);
423429
$properties_get = array_merge($json_api_header, $links, $properties_get_single, $included);
424-
$properties_patch = buildPatchPost(makeProperties($class->getPatchValidFeatures(), true));
430+
$properties_patch = buildPatchPost(makeProperties($class->getPatchValidFeatures(), true), $name);
425431

426432
$components[$name . "Create"] =
427433
[

0 commit comments

Comments
 (0)