From 5c507a8ce7b922255586a510311d12e966bde316 Mon Sep 17 00:00:00 2001 From: hsbmaulana Date: Tue, 29 Nov 2022 13:17:37 +0700 Subject: [PATCH] build(core): initial --- .github/workflows/cd.yml | 17 +++ LICENSE | 21 +++ README.md | 49 +++++++ bin/.gitkeep | 0 composer.json | 45 ++++++ config/swagger.php | 128 ++++++++++++++++++ resources/views/index.blade.php | 87 ++++++++++++ src/Console/Commands/GenerateDocsCommand.php | 18 +++ .../Commands/UnGenerateDocsCommand.php | 23 ++++ src/Providers/DocsServiceProvider.php | 99 ++++++++++++++ 10 files changed, 487 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 bin/.gitkeep create mode 100644 composer.json create mode 100644 config/swagger.php create mode 100644 resources/views/index.blade.php create mode 100644 src/Console/Commands/GenerateDocsCommand.php create mode 100644 src/Console/Commands/UnGenerateDocsCommand.php create mode 100644 src/Providers/DocsServiceProvider.php diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..0cedccb --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,17 @@ +name: Convention.php-docs + +on: push + +jobs: + cd: + runs-on: ubuntu-latest + steps: + - name: cd + uses: tripteki/cd-package@1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repotoken: ${{ secrets.REPOSITORY_TOKEN }} + repouser: tripteki + repository: https://packagist.org + language: php + artifact: composer.json \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..061b3a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Trip Teknologi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc722f3 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +

Convention

+ +Trip Teknologi's Codebase Convention. + +Getting Started +--- + +Installation : + +``` +$ composer require tripteki/laravelphp-docs +``` + +How to use : + +- Put `Tripteki\Docs\Providers\DocsServiceProvider::ignoreConfig()` into `register` provider, then publish config file into your project's directory with running (optionally) : + +``` +php artisan vendor:publish --tag=tripteki-laravelphp-docs-config +``` + +- Put the comment onto the `App\Http\Controllers\Controller` : + +``` +/** + * @OA\Info( + * title="Application Programming Interface", + * version="1.0" + * ), + * @OA\SecurityScheme( + * securityScheme="bearerAuth", + * in="header", + * type="http", + * scheme="bearer", + * bearerFormat="JWT" + * ) + */ +``` + +Usage +--- + +`php artisan swagger:generate` + +Author +--- + +- Trip Teknologi ([@tripteki](https://linkedin.com/company/tripteki)) +- Hasby Maulana ([@hsbmaulana](https://linkedin.com/in/hsbmaulana)) diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1ba6ecb --- /dev/null +++ b/composer.json @@ -0,0 +1,45 @@ +{ + "name": "tripteki/laravelphp-docs", + "version": "1.0.0", + "description": "Trip Teknologi's Codebase Convention", + + "readme": "README.md", + "license": "MIT", + "authors": [ { "name": "Trip Teknologi", "email": "tripteki.company@gmail.com" } ], + "homepage": "https://github.com/tripteki/convention-php-docs", + "support": { "issues": "https://github.com/tripteki/convention-php-docs/issues" }, + + "require": { + + "php": "^8.0.2", + + "darkaonline/l5-swagger": "^8.4.1" + }, + + "require-dev": {}, + + "autoload": { + + "psr-4": { + + "Tripteki\\Docs\\": "src/" + } + }, + + "autoload-dev": {}, + + "extra": { + + "laravel": { + + "dont-discover": [], + + "providers": [ + + "Tripteki\\Docs\\Providers\\DocsServiceProvider" + ], + + "aliases": [] + } + } +} diff --git a/config/swagger.php b/config/swagger.php new file mode 100644 index 0000000..c6942f8 --- /dev/null +++ b/config/swagger.php @@ -0,0 +1,128 @@ + env("SWAGGER", "default"), + + "documentations" => [ + + "default" => [ + + "api" => [ "title" => "Swagger", ], + + "routes" => [ + + "api" => "api/documentation", + ], + + "paths" => [ + + "use_absolute_path" => true, + + "docs_json" => "default.json", + "docs_yaml" => "default.yaml", + + "format_to_use_for_docs" => env("SWAGGER_DEFAULT_FORMAT", "json"), + + "annotations" => [ + + base_path("app"), + base_path("src"), + ], + ], + ], + ], + + + + "defaults" => [ + + "generate_always" => false, + "generate_yaml_copy" => false, + + "additional_config_url" => null, + + "operations_sort" => null, + + "validator_url" => null, + + "proxy" => false, + + "ui" => [ + + "display" => [ + + "filter" => true, + + "doc_expansion" => "none", + ], + + "authorization" => [ + + "persist_authorization" => false, + + "oauth2" => [ + + "use_pkce_with_authorization_code_grant" => false, + ], + ], + ], + + "routes" => [ + + "docs" => "/", + + "oauth2_callback" => "api/oauth2-callback", + + "middleware" => [ + + "asset" => [], + "api" => [], + "docs" => [], + "oauth2_callback" => [], + ], + + "group_options" => [], + ], + + "paths" => [ + + "docs" => storage_path("swagger"), + + "views" => resource_path("views/vendor/swagger"), + + "base" => "api", + + "swagger_ui_assets_path" => "vendor/swagger-api/swagger-ui/dist", + + "excludes" => [], + ], + + "scanOptions" => [ + + "analyser" => null, + "analysis" => null, + + "processors" => [], + + "pattern" => null, + + "exclude" => [], + + "open_api_spec_version" => \L5Swagger\Generator::OPEN_API_DEFAULT_SPEC_VERSION, + ], + + "securityDefinitions" => [ + + "securitySchemes" => [], + + "security" => [], + ], + + "constants" => [ + + "SWAGGER_PREFIX" => env("SWAGGER_PREFIX", "/api"), + ], + ], + +]; diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php new file mode 100644 index 0000000..79a3124 --- /dev/null +++ b/resources/views/index.blade.php @@ -0,0 +1,87 @@ + + + +{{ config('l5-swagger.documentations.'.$documentation.'.api.title') }} + + + + + + + + + +
+ + + + + + + diff --git a/src/Console/Commands/GenerateDocsCommand.php b/src/Console/Commands/GenerateDocsCommand.php new file mode 100644 index 0000000..2839537 --- /dev/null +++ b/src/Console/Commands/GenerateDocsCommand.php @@ -0,0 +1,18 @@ +app->isProduction()) { + + $this->app["config"]->set("l5-swagger.documentations", []); + } + } + + /** + * @return void + */ + public function boot() + { + $this->registerConfigs(); + $this->registerCommands(); + $this->registerPublishers(); + } + + /** + * @return void + */ + protected function registerConfigs() + { + if (static::shouldLoadConfig()) { + + $this->app["config"]->set("l5-swagger", []); + $this->mergeConfigFrom(__DIR__."/../../config/swagger.php", "l5-swagger"); + } + } + + /** + * @return void + */ + protected function registerCommands() + { + if ($this->app->runningInConsole()) { + + $this->commands( + [ + UnGenerateDocsCommand::class, + GenerateDocsCommand::class, + ]); + } + } + + /** + * @return void + */ + protected function registerPublishers() + { + $this->publishes( + [ + __DIR__."/../../config/swagger.php" => config_path("l5-swagger.php"), + ], + + "tripteki-laravelphp-docs-config"); + + $this->publishes( + [ + __DIR__."/../../resources/views" => config("l5-swagger.defaults.paths.views"), + ], + + "tripteki-laravelphp-docs-views"); + } +};