浏览代码

Merge branch 'master' into v4

# Conflicts:
#	CHANGELOG.md
#	src/Tools/Globals.php
#	src/Writing/Writer.php
shalvah 3 年之前
父节点
当前提交
15efd6f5c4
共有 2 个文件被更改,包括 23 次插入8 次删除
  1. 7 0
      CHANGELOG.md
  2. 16 8
      src/Writing/Writer.php

+ 7 - 0
CHANGELOG.md

@@ -20,10 +20,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 - Nested response fields are now collapsed ([00b09bb](https://github.com/knuckleswtf/scribe/commit/00b09bbea8ec64006db864bf807004d48926c6d3))
 - Inlined routes (no more Scribe/Controller class)
 
+
+## 3.35.0 (27 July 2022)
+### Modified
+- Use correct folders when generating in multi-docs ([ac47c67](https://github.com/knuckleswtf/scribe/commit/ac47c67eeb5d47cd30db74302d1cdd97720dd695))
+
+
 ## 3.34.0 (16 July 2022)
 ### Modified
 - URL parameter inference bugfixes and refactor ([#497](https://github.com/knuckleswtf/scribe/pull/497))
 
+
 ## 3.33.2 (9 July 2022)
 ### Fixed
 - Infer URL parameter name correctly when an interface is used for binding ([#494](https://github.com/knuckleswtf/scribe/pull/494))

+ 16 - 8
src/Writing/Writer.php

@@ -11,6 +11,12 @@ use Symfony\Component\Yaml\Yaml;
 
 class Writer
 {
+    /**
+     * The "name" of this docs instance. By default, it is "scribe".
+     * Used for multi-docs.
+     */
+    public string $docsName;
+
     private DocumentationConfig $config;
 
     private bool $isStatic;
@@ -36,12 +42,14 @@ class Writer
 
     public function __construct(DocumentationConfig $config = null, $docsName = 'scribe')
     {
-        // If no config is injected, pull from global. Makes testing easier.
+        $this->docsName = $docsName;
+
+        // If no config is injected, pull from global, for easier testing.
         $this->config = $config ?: new DocumentationConfig(config($docsName));
 
         $this->isStatic = $this->config->get('type') === 'static';
         $this->markdownOutputPath = ".{$docsName}"; //.scribe by default
-        $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath($docsName);
+        $this->laravelTypeOutputPath = $this->getLaravelTypeOutputPath();
         $this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/');
 
         $this->laravelAssetsPath = $this->config->get('laravel.assets_directory')
@@ -78,8 +86,8 @@ class Writer
                 $collectionPath = "{$this->staticTypeOutputPath}/collection.json";
                 file_put_contents($collectionPath, $collection);
             } else {
-                Storage::disk('local')->put('scribe/collection.json', $collection);
-                $collectionPath = 'storage/app/scribe/collection.json';
+                Storage::disk('local')->put("{$this->docsName}/collection.json", $collection);
+                $collectionPath = "storage/app/{$this->docsName}/collection.json";
             }
 
             c::success("Wrote Postman collection to: {$collectionPath}");
@@ -98,8 +106,8 @@ class Writer
                 $specPath = "{$this->staticTypeOutputPath}/openapi.yaml";
                 file_put_contents($specPath, $spec);
             } else {
-                Storage::disk('local')->put('scribe/openapi.yaml', $spec);
-                $specPath = 'storage/app/scribe/openapi.yaml';
+                Storage::disk('local')->put("{$this->docsName}/openapi.yaml", $spec);
+                $specPath = "storage/app/{$this->docsName}/openapi.yaml";
             }
 
             c::success("Wrote OpenAPI specification to: {$specPath}");
@@ -218,11 +226,11 @@ class Writer
         }
     }
 
-    protected function getLaravelTypeOutputPath(string $docsName): ?string
+    protected function getLaravelTypeOutputPath(): ?string
     {
         if ($this->isStatic) return null;
 
-        return config('view.paths.0', "resources/views")."/$docsName";
+        return config('view.paths.0', "resources/views")."/$this->docsName";
     }
 
 }