๋ฐ์ํ
๊ธฐ๋ณธ ์ธํ
1. ํ๋ก์ ํธ์ swagger ์ค์นํ๊ธฐ
composer require "darkaonline/l5-swagger"
2. config ํ์ผ ์์ฑ
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
3. provider ์ค์
config/app.php ํ์ผ ์์
'providers' => [
/*
* Laravel Framework Service Providers...*/
L5Swagger\L5SwaggerServiceProvider::class,
]
4. config ์ค์
config/I5-swagger.php ํ์ผ ์์
'api' => [
'title' => {์ํ๋ ์ ๋ชฉ}
],
'routes' => [
/*
* Route for accessing api documentation interface
*/
'api' => 'api/documentation',
],
'defaults' => [
'routes' => [
/*
* Route for accessing parsed swagger annotations.
*/
'docs' => 'docs',
5. ์ปจํธ๋กค๋ฌ ํ์ผ์ค ํ๋์ Annotation์ผ๋ก ๊ธฐ์
/**
* @OA\Info(
* title="TEST API",
* version="1.0",
* description="TEST API Document"
* )
**/
6. ์ ์ฉ (ํฐ๋ฏธ๋)
php artisan l5-swagger:generate
7. http://127.0.0.1:8000/api/documentation# ์ผ๋ก ์ ์
๋ด์ฉ ์์ฑํ๊ธฐ
- ์ปจํธ๋กค๋ฌ ์์ public function ์์ ์์ฑํด์ผ ํ๋ค.
@OA\{Get | Post | Put | Delete}
* @OA\Get (
* path="/api/v1/test/{id}",
* operationId="testAPI",
* tags={"ํ
์คํธ"},
* summary="ํ
์คํธ api",
* description="ํ
์คํธ์ฉ ์์ฑ",
* security={{"bearer_token":{}}},
* @OA\Parameter(
* name="id",
* description="ํ๋ผ๋ฏธํฐ",
* in="path",
* required=true,
* example="test"
* @OA\Schema(type="string")
* ),
* @OA\Response(
* response="200",
* description= "์ฑ๊ณต"
* ),
* @OA\Response(
* response="400",
* description= "์คํจ"
* ),
* security={{"api_key_security":{}}}
* )
@OA\Parameter
- Get ๋ฐฉ์ ์ ์ก
* @OA\Parameter(
* name="test_parameter",
* description="ํ๋ผ๋ฏธํฐ",
* in="path",
* required=true,
* example="test"
* @OA\Schema(type="string")
* )
- Header๋ก ์ ์ก
* @OA\Parameter(
* name="test_parameter",
* description="ํ๋ผ๋ฏธํฐ",
* in="header",
* required=true,
* example="test"
* @OA\Schema(type="string")
* )
@OA\RequestBody
- jsonํ์
* @OA\RequestBody(
* @OA\MediaType(e
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="image_file", type="int", description="ํ์ ๋ฒํธ", example=1),
* @OA\Property(property="name", type="string", description="ํ์ ์ด๋ฆ", example="๊น๊น๊น")
* )
* )
* )
- form-data ํ์
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(property="image_file", type="file", description="์ด๋ฏธ์ง ํ์ผ", format="file")
* )
* )
* )
@OA\Response
- ๋ฌธ์ ์ถ๋ ฅ
* @OA\Response(
* response="400",
* description= "์คํจ"
* )
- ๋ฐฐ์ด ์ถ๋ ฅ
* @OA\Response(
* response="200",
* description= "์ฑ๊ณต",
* @OA\JsonContent(
* @OA\Property(property="result", type="array",
* @OA\Items(
* @OA\Property(property="state", type="string", description="์ํ", example=true),
* @OA\Property(property="code", type="int", description="์ฝ๋", example=2000),
* @OA\Property(property="descMsg", type="string", description="๋ฉ์ธ์ง", example="SUCCESS"),
* ),
* ),
* @OA\Property(property="data", type="string", description="๋ฐ์ดํฐ", example="์ด๋ฏธ์ง url"),
* )
* )
- ๊ฐ์ฒด ์ถ๋ ฅ
* @OA\Response(
* response="200",
* description= "์ฑ๊ณต",
* @OA\JsonContent(
* @OA\Property(property="result", type="object",
* @OA\Property(property="state", type="string", description="์ํ", example=true),
* @OA\Property(property="code", type="int", description="์ฝ๋", example=2000),
* @OA\Property(property="descMsg", type="string", description="๋ฉ์ธ์ง", example="SUCCESS"),
* ),
* @OA\Property(property="data", type="string", description="๋ฐ์ดํฐ", example="์ด๋ฏธ์ง url"),
* )
* )
laravel bearer_token ์ธ์ฆ
comfig/I5-swagger.php ์์
'securityDefinitions' => [
'securitySchemes' => [
'bearer_token' => [ // Unique name of security
'type' => 'apiKey', // Valid values are "basic", "apiKey" or "oauth2".
'description' => 'Enter token in format (Bearer <token>)',
'name' => 'Authorization', // The name of the header or query parameter to be used.
'in' => 'header', // The location of the API key. Valid values are "query" or "header".
]
]
]
@OA\Info ์์ฑํ ๊ณณ์ ์ถ๊ฐ
* @OAS\SecurityScheme(
* securityScheme="bearer_token",
* type="http",
* scheme="bearer"
* )
@OA\{Get | Post | Put | Delete} ์์ ์ถ๊ฐ
* security={{"bearer_token":{}}},
- Beareer ์ฐ๊ณ ํ ํฐ ์ ๋ ฅ
๋ฐ์ํ
'๐Framework > ๐ต Laravel' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Laravel] ๋ผ๋ผ๋ฒจ์์ ์์ ๋ค๋ฃจ๊ธฐ (0) | 2023.04.06 |
---|---|
[Laravel] Serialization of 'Illuminate\\Http\\UploadedFile' is not allowed ์๋ฌ (0) | 2023.03.08 |
[Laravel] Maximum execution time of 60 seconds exceeded ์๋ฌ (0) | 2022.05.24 |
[Laravel] layout (0) | 2021.11.17 |
[Laravel] routes (0) | 2021.11.17 |