From d7cf031408296d966a7598342534ec251aeda82b Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Mon, 12 Feb 2024 16:33:19 +0900 Subject: [PATCH] added /request-docs/config --- composer.json | 2 +- config/request-docs.php | 3 +++ src/Controllers/LaravelRequestDocsController.php | 14 ++++++++++++++ src/LaravelRequestDocsServiceProvider.php | 4 ++++ ui/README.md | 4 ++-- ui/astro.config.mjs | 1 + ui/tsconfig.json | 7 +++++-- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 596a30f..ecc8fd7 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^7.4|^8.0|^8.1|^8.2", + "php": "^7.4|^8.0|^8.1|^8.2|^8.3", "illuminate/contracts": "^8.37|^9.0|^10.0", "kitloong/laravel-app-logger": "^1.0", "spatie/laravel-package-tools": "^1.4.3", diff --git a/config/request-docs.php b/config/request-docs.php index ef767a2..fb70730 100644 --- a/config/request-docs.php +++ b/config/request-docs.php @@ -40,6 +40,9 @@ ], // Can be overridden as // @LRDresponses 200|400|401 'default_responses' => [ "200", "400", "401", "403", "404", "405", "422", "429", "500", "503"], + 'default_headers' => [ + 'Content-Type' => 'application/json', + ], // By default, LRD group your routes by the first /path. // This is a set of regex to group your routes by prefix. diff --git a/src/Controllers/LaravelRequestDocsController.php b/src/Controllers/LaravelRequestDocsController.php index 07e3d45..1cbb722 100644 --- a/src/Controllers/LaravelRequestDocsController.php +++ b/src/Controllers/LaravelRequestDocsController.php @@ -121,4 +121,18 @@ public function assets(Request $request) } return response()->json(['error' => 'file not found'], 404); } + + /** + * @codeCoverageIgnore + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function config(Request $request) + { + $config = [ + 'default_responses' => config('request-docs.default_responses'), + 'default_headers' => config('request-docs.default_headers'), + ]; + return response()->json($config); + } } diff --git a/src/LaravelRequestDocsServiceProvider.php b/src/LaravelRequestDocsServiceProvider.php index 0125d7e..a174825 100644 --- a/src/LaravelRequestDocsServiceProvider.php +++ b/src/LaravelRequestDocsServiceProvider.php @@ -47,6 +47,10 @@ public function packageBooted() ->name('request-docs.api') ->middleware(config('request-docs.middlewares')); + Route::get("request-docs/config", [\Rakutentech\LaravelRequestDocs\Controllers\LaravelRequestDocsController::class, 'config']) + ->name('request-docs.config') + ->middleware(config('request-docs.middlewares')); + Route::get("request-docs/_astro/{slug}", [\Rakutentech\LaravelRequestDocs\Controllers\LaravelRequestDocsController::class, 'assets']) // where slug is either js or css ->where('slug', '.*js|.*css|.*png|.*jpg|.*jpeg|.*gif|.*svg|.*ico|.*woff|.*woff2|.*ttf|.*eot|.*otf|.*map') diff --git a/ui/README.md b/ui/README.md index ba1973e..9ec949a 100644 --- a/ui/README.md +++ b/ui/README.md @@ -12,9 +12,9 @@ npm run dev ## 1) Mode: Readonly -**Open in Browser** +**Open in Browser** -http://localhost:3000/request-docs?api=http://localhost:3000/request-docs/sample.json +http://localhost:3000/request-docs/?api=http://localhost:3000/request-docs/sample.json ## 2) Mode: Developing with Laravel via npm diff --git a/ui/astro.config.mjs b/ui/astro.config.mjs index 3c8913d..ddfb888 100644 --- a/ui/astro.config.mjs +++ b/ui/astro.config.mjs @@ -1,6 +1,7 @@ import { defineConfig } from 'astro/config' import compress from 'astro-compress' import react from '@astrojs/react' +import process from 'process' import git from 'git-rev-sync' const version = git.tag() diff --git a/ui/tsconfig.json b/ui/tsconfig.json index 77da9dd..cf0d7db 100644 --- a/ui/tsconfig.json +++ b/ui/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "astro/tsconfigs/strict" -} \ No newline at end of file + "extends": "astro/tsconfigs/strict", + "compilerOptions": { + "jsx": "react" + } +}