Skip to content

Commit

Permalink
Merge pull request #28 from JoBinsJP/fixes
Browse files Browse the repository at this point in the history
Enum added.
  • Loading branch information
bedus-creation authored Oct 19, 2022
2 parents da57c07 + 7c44e6c commit b20b4b3
Show file tree
Hide file tree
Showing 46 changed files with 457 additions and 530 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .php_cs

This file was deleted.

107 changes: 53 additions & 54 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
{
"name": "jobins/api-generator",
"description": "Generate api docs while writing test case (Laravel).",
"keywords": [
"JoBins",
"documentation",
"api",
"swagger",
"openapi",
"phpunit"
],
"homepage": "https://github.com/JoBinsJP/api-genereator",
"license": "MIT",
"authors": [
{
"name": "Bedram Tamang",
"email": "[email protected]"
}
],
"require": {
"php": "^7.4|^8.0|^8.1",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"JoBins\\APIGenerator\\": "src"
"name": "jobins/api-generator",
"description": "Generate api docs while writing test case (Laravel).",
"keywords": [
"JoBins",
"documentation",
"api",
"swagger",
"openapi",
"phpunit"
],
"homepage": "https://github.com/JoBinsJP/api-genereator",
"license": "MIT",
"authors": [
{
"name": "Bedram Tamang",
"email": "[email protected]"
}
],
"require": {
"php": "^7.4|^8.0|^8.1",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"JoBins\\APIGenerator\\": "src"
},
"files": [
"src/helper.php"
]
},
"scripts": {
"test": "vendor/bin/phpunit",
"psalm": "vendor/bin/psalm",
"pint": "vendor/bin/pint",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"autoload-dev": {
"psr-4": {
"JoBins\\APIGenerator\\Tests\\": "tests"
},
"files": [
"tests/helper.php"
]
},
"files": [
"src/helper.php"
]
},
"scripts": {
"test": "vendor/bin/phpunit",
"psalm": "vendor/bin/psalm",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"autoload-dev": {
"psr-4": {
"JoBins\\APIGenerator\\Tests\\": "tests"
"require-dev": {
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "^4.7"
},
"files": [
"tests/helper.php"
]
},
"require-dev": {
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.0",
"friendsofphp/php-cs-fixer": "^2.18",
"vimeo/psalm": "^4.7"
},
"extra": {
"laravel": {
"providers": [
"JoBins\\APIGenerator\\APIGeneratorServiceProvider"
]
"extra": {
"laravel": {
"providers": [
"JoBins\\APIGenerator\\APIGeneratorServiceProvider"
]
}
}
}
}
30 changes: 17 additions & 13 deletions config/api-generator.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<?php

return [
"servers" => [
"url" => "https://{environment}.localhost.test",
"variables" => [
"environment" => [
"default" => "api",
"enum" => [
"api",
"api.dev",
"api.staging",
'servers' => [
'url' => 'https://{environment}.localhost.test',

'variables' => [
'environment' => [

'default' => 'api',

'enum' => [
'api',
'api.dev',
'api.staging',
],
],
],
],

"openapi" => "3.0.0",
"title" => "Reaching APP API",
"version" => "1.0.0",
'openapi' => '3.0.0',
'title' => 'Reaching APP API',
'version' => '1.0.0',

"file-path" => storage_path("api-docs/api-docs.json"),
'file-path' => public_path('api-docs/api-docs.json'),
];
1 change: 0 additions & 1 deletion src/APIGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

/**
* Class APIGeneratorFactory
* @package JoBins\APIGenerator
*/
class APIGeneratorFactory
{
Expand Down
4 changes: 2 additions & 2 deletions src/APIGeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function boot()
__DIR__.'/../config/api-generator.php' => config_path('api-generator.php'),
]);

TestResponse::macro("generate", function ($testCase, bool $generate = true) {
TestResponse::macro('generate', function ($testCase, bool $generate = true) {
if (! $generate) {
return;
}

/** @var JsonResponse $response */
$response = $this;

(new Generator())->setRequest($testCase->getParams())->setResponse($response)->generate();
(new Generator)->setRequest($testCase->getParams())->setResponse($response)->generate();
});
}
}
2 changes: 0 additions & 2 deletions src/Contract/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* Interface Description
*
* @package JoBins\APIGenerator\Contract
*/
interface Description
{
Expand Down
37 changes: 22 additions & 15 deletions src/Parser/HasPropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use Illuminate\Support\Arr;
use JoBins\APIGenerator\Rules\ArrayRule;
use JoBins\APIGenerator\Rules\EnumRule;
use JoBins\APIGenerator\Rules\FileRule;
use JoBins\APIGenerator\Rules\IntegerRule;

/**
* Trait HasPropertyType
*
* @package JoBins\APIGenerator\Security
*/
trait HasPropertyType
{
Expand All @@ -22,27 +21,27 @@ trait HasPropertyType
protected array $rulesArray = [];

/**
* @param array $rules
* @param string $name
* @param array $rules
* @param string $name
*
* @return array|string[]
*/
public function getPropertyType(array $rules, string $name): array
{
if (ArrayRule::check($rules)) {
if ( ArrayRule::check($rules) ) {
$rules = Arr::get($this->rulesArray, "{$name}.*");

return [
"type" => "array",
"items" => $this->getPropertyItemType($rules),
'type' => 'array',
'items' => $this->getPropertyItemType($rules),
];
}

return $this->getPropertyItemType($rules);
}

/**
* @param array $rulesArray
* @param array $rulesArray
*/
public function setRulesArray(array $rulesArray): void
{
Expand All @@ -51,23 +50,31 @@ public function setRulesArray(array $rulesArray): void

private function getPropertyItemType(array $rules): array
{
if (FileRule::check($rules)) {
$this->contentType = "multipart/form-data";
if ( FileRule::check($rules) ) {
$this->contentType = 'multipart/form-data';

return [
"type" => "string",
"format" => "binary",
'type' => 'string',
'format' => 'binary',
];
}

if (IntegerRule::check($rules)) {
if ( IntegerRule::check($rules) ) {
return [
"type" => "integer",
'type' => 'integer',
];
}

$enums = EnumRule::data($rules);
if ( count($enums) > 0 ) {
return [
'type' => 'string',
'enum' => $enums,
];
}

return [
"type" => "string",
'type' => 'string',
];
}
}
Loading

0 comments on commit b20b4b3

Please sign in to comment.