-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing api using docs functionality
- Loading branch information
1 parent
2b6a8f9
commit f2c18c7
Showing
5 changed files
with
136 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Containers\Vendor\Documentation\Tasks; | ||
|
||
use App\Ship\Parents\Tasks\Task; | ||
|
||
class RenderApidocJsonTask extends Task | ||
{ | ||
private string $templatePath; | ||
private string $outputPath; | ||
// ['templateKey' => value] | ||
private array $replaceArray; | ||
|
||
public function __construct(string $docType) | ||
{ | ||
$this->templatePath = 'Containers/' . config('vendor-documentation.section_name') . '/Documentation/ApiDocJs/' . $docType . '/apidoc.json'; | ||
$this->outputPath = 'Containers/' . config('vendor-documentation.section_name') . '/Documentation/ApiDocJs/' . $docType . '/apidoc.json'; | ||
$this->replaceArray = [ | ||
'name' => config('app.name'), | ||
'description' => config('app.name') . ' (' . ucfirst($docType) . ' API) Documentation', | ||
'title' => 'Welcome to ' . config('app.name'), | ||
'url' => config('apiato.api.url'), | ||
'sampleUrl' => config('vendor-documentation.enable-sending-sample-request') ? config('apiato.api.url') : null, | ||
]; | ||
} | ||
|
||
/** | ||
* Read the markdown header template and fill it with some real data from the .env file. | ||
*/ | ||
public function run(): string | ||
{ | ||
// read the template file | ||
$jsonContent = file_get_contents(app_path($this->templatePath)); | ||
|
||
//Decode the JSON data into a PHP array. | ||
$contentsDecoded = json_decode($jsonContent, true); | ||
|
||
//Modify the variables. | ||
foreach ($this->replaceArray as $key => $value) { | ||
$contentsDecoded[$key] = $value; | ||
} | ||
|
||
//Encode the array back into a JSON string. | ||
$jsonContent = json_encode($contentsDecoded); | ||
|
||
// this is what the apidoc.json file will point to to load the header.md | ||
// write the actual file | ||
$path = app_path($this->outputPath); | ||
file_put_contents($path, $jsonContent); | ||
|
||
return $path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters