Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from GueroSF/#79747
Browse files Browse the repository at this point in the history
#79747
  • Loading branch information
arrilot authored Aug 24, 2021
2 parents 9fd5462 + 1772d65 commit 5af39cd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
## Установка:
1. `composer require --dev greensight/laravel-openapi-client-generator`
2. `php artisan vendor:publish --provider="Greensight\LaravelOpenapiClientGenerator\OpenapiClientGeneratorServiceProvider"` - копирует конфиг генератора в конфиги приложения
3. измените, если требуется, настройки по умолчанию в конфигурационном файле


## Запуск:
1. Перед запуском убедиться, что структура описания апи соответствует [этим требованиям](https://github.com/greensight/laravel-openapi-client-generator/blob/master/docs/api_schema_requirements.md).
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MIT",
"require": {
"php": "^7.2 || ^8.0",
"ext-json": "*",
"nette/php-generator": "^3.5"
},
"autoload": {
Expand Down
5 changes: 5 additions & 0 deletions config/openapi-client-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@
* Files that will be ignored during repository cleanup
*/
'files_to_ignore_during_cleanup' => ['.git', '.gitignore'],

/**
* Options for disable patch section "require" composer.json
*/
'composer_disable_patch_require' => false,
]
];
11 changes: 9 additions & 2 deletions src/Commands/GeneratePhpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ class GeneratePhpClient extends GenerateClient {
*/
protected $laravelPackageConfigKey;

/** @var bool */
private $disableComposerPatchRequire;

public function __construct()
{
parent::__construct();
$this->composerName = config('openapi-client-generator.php_args.composer_name');
$this->laravelPackageConfigKey = config("openapi-client-generator.{$this->client}_args.laravel_package_config_key", '');

$this->disableComposerPatchRequire = (bool) config('openapi-client-generator.php_args.composer_disable_patch_require', false);
}

protected function patchClientPackage(): void
Expand Down Expand Up @@ -80,7 +85,9 @@ private function patchEnums(): void
private function patchComposerPackage(): void
{
$patcher = new ComposerPackagePatcher($this->outputDir, $this->composerName);
$patcher->patch();
$patcher
->setDisableRequirePatching($this->disableComposerPatchRequire)
->patch();
}

private function generateProvider(): void {
Expand All @@ -89,7 +96,7 @@ private function generateProvider(): void {
$this->params['invokerPackage'],
$this->params['packageName'],
$this->params['apiPackage'],
$this->params['modelPackage'],
$this->params['modelPackage']
);

$generator->generate();
Expand Down
28 changes: 18 additions & 10 deletions src/Core/Patchers/ComposerPackagePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,41 @@

class ComposerPackagePatcher extends PackageManifestPatcher {

/**
* @var string
*/
/** @var string */
protected $manifestName = 'composer.json';

/**
* @var string
*/
/** @var string */
protected $packageName;
/** @var bool */
private $disableRequirePatching = false;

public function __construct(string $packageRootDir, string $packageName)
{
parent::__construct($packageRootDir);
$this->packageName = $packageName;
}

protected function applyPatchers($manifest)
public function setDisableRequirePatching(bool $disableRequirePatching): self
{
$this->disableRequirePatching = $disableRequirePatching;

return $this;
}

protected function applyPatchers($manifest): array
{
$manifest = $this->patchPackageName($manifest);
$manifest = $this->patchLicense($manifest);
$manifest = $this->patchRequire($manifest);

if (false === $this->disableRequirePatching) {
$manifest = $this->patchRequire($manifest);
}

return $manifest;
}

protected function patchPackageName($manifest)
{
$manifest['name'] = $this->packageName;

return $manifest;
}

Expand All @@ -40,6 +47,7 @@ protected function patchRequire($manifest)
$manifest['require']['php'] = '^7.1 || ^8.0';
$manifest['require']['guzzlehttp/guzzle'] = '^6.2 || ^7.0';
$manifest['require']['guzzlehttp/psr7'] = '^1.6.1';

return $manifest;
}
}
7 changes: 7 additions & 0 deletions src/Core/Patchers/NpmPackagePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ private function addDependenciesForNestJS($packageJson) {
$packageJson['devDependencies']['reflect-metadata'] = '0.1.13';
return $packageJson;
}

private function patchLicense(array $manifest): array
{
$manifest['license'] = 'MIT';

return $manifest;
}
}
5 changes: 0 additions & 5 deletions src/Core/Patchers/PackageManifestPatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,4 @@ private function getPackageManifestPath(): string
return $this->packageRootDir . DIRECTORY_SEPARATOR . $this->manifestName;
}

protected function patchLicense($manifest)
{
$manifest['license'] = 'MIT';
return $manifest;
}
}

0 comments on commit 5af39cd

Please sign in to comment.