Browse Source

Improve OAS generation for array body and files

shalvah 4 năm trước cách đây
mục cha
commit
05145cb3bd

+ 2 - 2
camel/Output/OutputEndpointData.php

@@ -96,11 +96,11 @@ class OutputEndpointData extends BaseDTO
 
         parent::__construct($parameters);
 
-        $this->nestedBodyParameters = Extractor::nestArrayAndObjectFields($this->bodyParameters);
-
         $this->cleanBodyParameters = Extractor::cleanParams($this->bodyParameters);
         $this->cleanQueryParameters = Extractor::cleanParams($this->queryParameters);
         $this->cleanUrlParameters = Extractor::cleanParams($this->urlParameters);
+        $this->nestedBodyParameters = Extractor::nestArrayAndObjectFields($this->bodyParameters, $this->cleanBodyParameters);
+
         $this->boundUri = u::getUrlWithBoundParameters($this->uri, $this->cleanUrlParameters);
 
         [$files, $regularParameters] = collect($this->cleanBodyParameters)

+ 6 - 1
src/Extracting/Extractor.php

@@ -429,7 +429,7 @@ class Extractor
      *
      * @return array
      */
-    public static function nestArrayAndObjectFields(array $parameters): array
+    public static function nestArrayAndObjectFields(array $parameters, array $cleanParameters = []): array
     {
         // First, we'll make sure all object fields have parent fields properly set
         $normalisedParameters = [];
@@ -496,6 +496,11 @@ class Extractor
         // Finally, if the body is an array, remove any other items.
         if (isset($finalParameters['[]'])) {
             $finalParameters = ["[]" => $finalParameters['[]']];
+            // At this point, the examples are likely [[], []],
+            // but have been correctly set in clean parameters, so let's update them
+            if ($finalParameters["[]"]["example"][0] == [] && !empty($cleanParameters)) {
+                $finalParameters["[]"]["example"] = $cleanParameters;
+            }
         }
 
         return $finalParameters;

+ 5 - 9
src/ScribeServiceProvider.php

@@ -13,15 +13,6 @@ use Knuckles\Scribe\Tools\Utils;
 
 class ScribeServiceProvider extends ServiceProvider
 {
-    public function register()
-    {
-        // Register custom Markdown Blade compiler so we can automatically have MD views converted to HTML
-        $app = $this->app;
-        $app->view->getEngineResolver()
-            ->register('blademd', fn() => new BladeMarkdownEngine($app['blade.compiler']));
-        $app->view->addExtension('md.blade.php', 'blademd');
-    }
-
     /**
      * Bootstrap the application events.
      *
@@ -29,6 +20,11 @@ class ScribeServiceProvider extends ServiceProvider
      */
     public function boot()
     {
+        // Register custom Markdown Blade compiler so we can automatically have MD views converted to HTML
+        $this->app->view->getEngineResolver()
+            ->register('blademd', fn() => new BladeMarkdownEngine($this->app['blade.compiler']));
+        $this->app->view->addExtension('md.blade.php', 'blademd');
+
         $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'scribe');
 
         // Publish views in separate, smaller groups for ease of end-user modifications