4 Commits c5e567728e ... f96342bf9b

Autore SHA1 Messaggio Data
  Shalvah f96342bf9b 5.0.1 2 mesi fa
  Shalvah 1839eb7890 Update deps 2 mesi fa
  Shalvah 020b50d7e4 Add test 2 mesi fa
  Eser DENIZ eb08910a27 fix: Undefined array key "properties" (#951) 2 mesi fa

+ 5 - 1
CHANGELOG.md

@@ -12,5 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Removed
 
-# 5.0.0 (19 February 2024)
+## 5.0.1 (20 February 2025)
+### Fixed
+- Fix bug in wrongly trying to determine required fields for array of strings [#951](https://github.com/knuckleswtf/scribe/pull/951)
+
+## 5.0.0 (19 February 2025)
 See the [migration guide](https://scribe.knuckles.wtf/migrating).

+ 4 - 4
composer.json

@@ -37,12 +37,12 @@
         "laravel/legacy-factories": "^1.3.0",
         "league/fractal": "^0.20",
         "nikic/fast-route": "^1.3",
-        "orchestra/testbench": "^7.0|^8.0|^v9.10.0",
+        "orchestra/testbench": "^7.0|^8.0|^v9.10.0|^10.0",
         "pestphp/pest": "^1.21|^2.0|^3.0",
         "phpstan/phpstan": "^2.1.5",
-        "phpunit/phpunit": "^9.0|^10.0",
-        "symfony/css-selector": "^6.0",
-        "symfony/dom-crawler": "^6.0",
+        "phpunit/phpunit": "^9.0|^10.0|^11.0",
+        "symfony/css-selector": "^6.0|^7.0",
+        "symfony/dom-crawler": "^6.0|^7.0",
         "spatie/ray": "^1.41"
     },
     "autoload": {

+ 1 - 1
src/Scribe.php

@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Request;
 
 class Scribe
 {
-    public const VERSION = '5.0.0';
+    public const VERSION = '5.0.1';
 
     /**
      * Specify a callback that will be executed just before a response call is made

+ 6 - 5
src/Writing/OpenApiSpecGenerators/BaseGenerator.php

@@ -549,11 +549,12 @@ class BaseGenerator extends OpenApiGenerator
                 $schema['items']['properties'] = collect($sample)->mapWithKeys(function ($v, $k) use ($endpoint, $path) {
                     return [$k => $this->generateSchemaForResponseValue($v, $endpoint, "$path.$k")];
                 })->toArray();
-            }
-
-            $required = $this->filterRequiredResponseFields($endpoint, array_keys($schema['items']['properties']), $path);
-            if ($required) {
-                $schema['required'] = $required;
+                
+                $required = $this->filterRequiredResponseFields($endpoint, array_keys($schema['items']['properties']),
+                    $path);
+                if ($required) {
+                    $schema['required'] = $required;
+                }
             }
         }
 

+ 50 - 1
tests/Unit/OpenAPISpecWriterTest.php

@@ -601,7 +601,7 @@ class OpenAPISpecWriterTest extends BaseUnitTest
     }
 
     /** @test */
-    public function adds_required_fields_on_objects_wrapped_in_array()
+    public function adds_required_fields_on_array_of_objects()
     {
         $endpointData = $this->createMockEndpointData([
             'httpMethods' => ['GEt'],
@@ -686,6 +686,55 @@ class OpenAPISpecWriterTest extends BaseUnitTest
         ], $results['paths']['/path1']['get']['responses']);
     }
 
+    /** @test */
+    public function generates_correctly_for_array_of_strings()
+    {
+        $endpointData = $this->createMockEndpointData([
+            'httpMethods' => ['GET'],
+            'uri' => '/path1',
+            'responses' => [
+                [
+                    'status' => 200,
+                    'description' => 'List of entities',
+                    'content' => '{"data":["Resource name"]}',
+                ],
+            ],
+            'responseFields' => [
+                'data' => [
+                    'name' => 'data',
+                    'type' => 'string[]',
+                    'description' => 'Data wrapper',
+                ],
+            ],
+        ]);
+
+        $groups = [$this->createGroup([$endpointData])];
+
+        $results = $this->generate($groups);
+
+        $this->assertArraySubset([
+            '200' => [
+                'description' => 'List of entities',
+                'content' => [
+                    'application/json' => [
+                        'schema' => [
+                            'type' => 'object',
+                            'properties' => [
+                                'data' => [
+                                    'type' => 'array',
+                                    'description' => 'Data wrapper',
+                                    'items' => [
+                                        'type' => 'string',
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ], $results['paths']['/path1']['get']['responses']);
+    }
+
     /** @test */
     public function adds_multiple_responses_correctly_using_oneOf()
     {