Skip to content

Commit

Permalink
build(core): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana committed Nov 2, 2023
0 parents commit a89a975
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Convention.php-docs

on: push

jobs:
cd:
runs-on: ubuntu-latest
steps:
- name: cd
uses: tripteki/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
repotoken: ${{ secrets.REPOSITORY_TOKEN }}
repouser: tripteki
repository: https://packagist.org
language: php
artifact: composer.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<h1 align="center">Convention</h1>

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))
Empty file added bin/.gitkeep
Empty file.
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]" } ],
"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": []
}
}
}
128 changes: 128 additions & 0 deletions config/swagger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

return [

"default" => 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"),
],
],

];
87 changes: 87 additions & 0 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ config('l5-swagger.documentations.'.$documentation.'.api.title') }}</title>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="{{ l5_swagger_asset($documentation, 'favicon-32x32.png') }}" sizes="32x32" />
<link rel="icon" type="image/png" href="{{ l5_swagger_asset($documentation, 'favicon-16x16.png') }}" sizes="16x16" />
<link rel="stylesheet" type="text/css" href="{{ l5_swagger_asset($documentation, 'swagger-ui.css') }}" />
<style type="text/css">
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*, *:before, *:after
{
box-sizing: inherit;
}
body
{
margin: 0;
background: #fafafa;
}
</style>
</head>

<body>

<div id="swagger"></div>

<script type="text/javascript" src="{{ l5_swagger_asset($documentation, 'swagger-ui-bundle.js') }}"></script>
<script type="text/javascript" src="{{ l5_swagger_asset($documentation, 'swagger-ui-standalone-preset.js') }}"></script>
<script type="text/javascript">
window.onload = function ()
{
const swagger = SwaggerUIBundle(
{
dom_id: "#swagger",
url: "{!! $urlToDocs !!}",
operationsSorter: {!! isset($operationsSorter) ? '"'.$operationsSorter.'"' : 'null' !!},
configUrl: {!! isset($configUrl) ? '"'.$configUrl.'"' : 'null' !!},
validatorUrl: {!! isset($validatorUrl) ? '"'.$validatorUrl.'"' : 'null' !!},
oauth2RedirectUrl: "{{ route('l5-swagger.'.$documentation.'.oauth2_callback', [], $useAbsolutePath) }}",
layout: "StandaloneLayout",
docExpansion : "{!! config('l5-swagger.defaults.ui.display.doc_expansion', 'none') !!}",
deepLinking: true,
filter: {!! config('l5-swagger.defaults.ui.display.filter') ? 'true' : 'false' !!},
persistAuthorization: "{!! config('l5-swagger.defaults.ui.authorization.persist_authorization') ? 'true' : 'false' !!}",
requestInterceptor: function (request) {
request.headers['X-CSRF-TOKEN'] = '{{ csrf_token() }}';
return request;
},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset,
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
],
});
window.swagger = swagger;
@if(in_array("oauth2", array_column(config("l5-swagger.defaults.securityDefinitions.securitySchemes"), "type")))
swagger.initOAuth(
{
usePkceWithAuthorizationCodeGrant: "{!! (bool) config('l5-swagger.defaults.ui.authorization.oauth2.use_pkce_with_authorization_code_grant') !!}",
});
@endif
};
</script>

</body>
</html>
18 changes: 18 additions & 0 deletions src/Console/Commands/GenerateDocsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tripteki\Docs\Console\Commands;

use L5Swagger\Console\GenerateDocsCommand as Command;

class GenerateDocsCommand extends Command
{
/**
* @var string
*/
protected $signature = "swagger:generate {documentation?} {--all}";

/**
* @var string
*/
protected $description = "Regenerate swagger docs";
};
23 changes: 23 additions & 0 deletions src/Console/Commands/UnGenerateDocsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tripteki\Docs\Console\Commands;

use Illuminate\Console\Command;

class UnGenerateDocsCommand extends Command
{
/**
* @var bool
*/
protected $hidden = true;

/**
* @var string
*/
protected $signature = "l5-swagger:generate {documentation?} {--all}";

/**
* @var string
*/
protected $description = "Regenerate swagger docs";
};
Loading

0 comments on commit a89a975

Please sign in to comment.