Browse Source

Merge pull request #201 from jr3cermak/master

A little bugfix.
Maurits van der Schee 8 years ago
parent
commit
37f2e0d6a1
2 changed files with 9 additions and 3 deletions
  1. 8
    2
      api.php
  2. 1
    1
      tests/tests.php

+ 8
- 2
api.php View File

@@ -2429,7 +2429,10 @@ class PHP_CRUD_API {
2429 2429
 						echo '"required":true,';
2430 2430
 						echo '"schema":{';
2431 2431
 						echo '"type": "object",';
2432
-						echo '"required":'.json_encode(array_keys(array_filter($action['fields'],function($f){ return $f->required; }))).',';
2432
+                                                $required_fields = array_keys(array_filter($action['fields'],function($f){ return $f->required; }));
2433
+                                                if (count($required_fields) > 0) {
2434
+                                                        echo '"required":'.json_encode($required_fields).',';
2435
+                                                }
2433 2436
 						echo '"properties": {';
2434 2437
 						foreach (array_keys($action['fields']) as $k=>$field) {
2435 2438
 							if ($k>0) echo ',';
@@ -2497,7 +2500,10 @@ class PHP_CRUD_API {
2497 2500
 						echo '"required":true,';
2498 2501
 						echo '"schema":{';
2499 2502
 						echo '"type": "object",';
2500
-						echo '"required":'.json_encode(array_keys(array_filter($action['fields'],function($f){ return $f->required; }))).',';
2503
+                                                $required_fields = array_keys(array_filter($action['fields'],function($f){ return $f->required; }));
2504
+                                                if (count($required_fields) > 0) {
2505
+                                                        echo '"required":'.json_encode($required_fields).',';
2506
+                                                }
2501 2507
 						echo '"properties": {';
2502 2508
 						foreach (array_keys($action['fields']) as $k=>$field) {
2503 2509
 							if ($k>0) echo ',';

+ 1
- 1
tests/tests.php View File

@@ -450,7 +450,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
450 450
 	{
451 451
 		$test = new API($this);
452 452
 		$test->options('/posts/2');
453
-		$test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-Token","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
453
+		$test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
454 454
 	}
455 455
 
456 456
 	public function testHidingPasswordColumn()

Loading…
Cancel
Save