From 13f6cd2d14e6b1aca7c4e8ca3a23026569d36b5d Mon Sep 17 00:00:00 2001 From: riccardo Date: Sun, 5 Sep 2021 20:36:39 +0200 Subject: [PATCH] Swagger correction --- app/Http/Controllers/CouponController.php | 22 ++- config/swagger-lume.php | 8 +- storage/api-docs/api-docs.json | 160 +--------------------- 3 files changed, 21 insertions(+), 169 deletions(-) diff --git a/app/Http/Controllers/CouponController.php b/app/Http/Controllers/CouponController.php index 382bbcb..eb59af0 100644 --- a/app/Http/Controllers/CouponController.php +++ b/app/Http/Controllers/CouponController.php @@ -32,7 +32,7 @@ class CouponController extends Controller * path="/get-coupon", * operationId="/get-coupon", * tags={"getCoupon"}, - * security={ {"bearer": {} }}, + * security={ {"bearer_token": {} }}, * @OA\Parameter( * name="brand_id", * in="query", @@ -43,6 +43,16 @@ class CouponController extends Controller * @OA\Response( * response="200", * description="Returns the coupon code", + * content={ + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * example={ + * "data": {"code": "d4r6o9sd46i.5i4is57u3"} + * } + * ) + * ) + * } * ), * @OA\Response( * response="401", @@ -102,11 +112,11 @@ class CouponController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response * - * @OA\Get( + * @OA\Post( * path="/generate-coupons", * operationId="/generate-coupons", * tags={"generateCoupons"}, - * security={ {"bearer": {} }}, + * security={ {"bearer_token": {} }}, * @OA\Parameter( * name="quantity", * in="query", @@ -118,11 +128,11 @@ class CouponController extends Controller * name="prefix", * in="query", * description="Prefix to be used in the coupon codes.", - * required=true, + * required=false, * @OA\Schema(type="string") * ), * @OA\Response( - * response="200", + * response="201", * description="Success.", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Coupon code(s) generation job sent.") @@ -164,6 +174,6 @@ class CouponController extends Controller return response()->json([ 'message' => 'Coupon code(s) generation job sent.' - ], 200); + ], 201); } } diff --git a/config/swagger-lume.php b/config/swagger-lume.php index 387d42d..bf1be5c 100644 --- a/config/swagger-lume.php +++ b/config/swagger-lume.php @@ -107,13 +107,13 @@ return [ | Examples of Security definitions |-------------------------------------------------------------------------- */ - /* - 'api_key_security_example' => [ // Unique name of security + 'bearer_token' => [ // Unique name of security 'type' => 'apiKey', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2". - 'description' => 'A short description for security scheme', - 'name' => 'api_key', // The name of the header or query parameter to be used. + 'description' => 'Enter token in format (Bearer )', + '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". ], + /* 'oauth2_security_example' => [ // Unique name of security 'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2". 'description' => 'A short description for oauth2 security scheme.', diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index ff52dc6..4536d9a 100644 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -1,159 +1 @@ -{ - "openapi": "3.0.0", - "info": { - "title": "Example API", - "contact": { - "name": "Support Team", - "email": "support@example.com" - }, - "version": "1.0" - }, - "paths": { - "/get-coupon": { - "get": { - "tags": [ - "getCoupon" - ], - "summary": "Retrieve a coupon code for the user, based on the selected brand, if available.", - "operationId": "/get-coupon", - "parameters": [ - { - "name": "brand_id", - "in": "query", - "description": "ID of the brand for which the coupon is requested.", - "required": true, - "schema": { - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "Returns the coupon code" - }, - "401": { - "description": "Error: Not authenticated.", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string", - "example": "Token expired." - } - }, - "type": "object" - } - } - } - }, - "403": { - "description": "Error: Not authorized.", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string", - "example": "Not authorized." - } - }, - "type": "object" - } - } - } - } - }, - "security": [ - { - "bearer": [] - } - ] - } - }, - "/generate-coupons": { - "get": { - "tags": [ - "generateCoupons" - ], - "summary": "Generates coupon codes for a brand.", - "operationId": "/generate-coupons", - "parameters": [ - { - "name": "quantity", - "in": "query", - "description": "Quantity of coupons to be generated.", - "required": true, - "schema": { - "type": "integer" - } - }, - { - "name": "prefix", - "in": "query", - "description": "Prefix to be used in the coupon codes.", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "Success.", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string", - "example": "Coupon code(s) generation job sent." - } - }, - "type": "object" - } - } - } - }, - "401": { - "description": "Error: Not authenticated.", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string", - "example": "Token expired." - } - }, - "type": "object" - } - } - } - }, - "403": { - "description": "Error: Not authorized.", - "content": { - "application/json": { - "schema": { - "properties": { - "message": { - "type": "string", - "example": "Not authorized." - } - }, - "type": "object" - } - } - } - } - }, - "security": [ - { - "bearer": [] - } - ] - } - } - } -} \ No newline at end of file +{"openapi":"3.0.0","info":{"title":"Example API","contact":{"name":"Support Team","email":"support@example.com"},"version":"1.0"},"paths":{"\/get-coupon":{"get":{"tags":["getCoupon"],"summary":"Retrieve a coupon code for the user, based on the selected brand, if available.","operationId":"\/get-coupon","parameters":[{"name":"brand_id","in":"query","description":"ID of the brand for which the coupon is requested.","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Returns the coupon code","content":{"application\/json":{"schema":{"example":{"data":{"code":"d4r6o9sd46i.5i4is57u3"}}}}}},"401":{"description":"Error: Not authenticated.","content":{"application\/json":{"schema":{"properties":{"message":{"type":"string","example":"Token expired."}},"type":"object"}}}},"403":{"description":"Error: Not authorized.","content":{"application\/json":{"schema":{"properties":{"message":{"type":"string","example":"Not authorized."}},"type":"object"}}}}},"security":[{"bearer_token":[]}]}},"\/generate-coupons":{"post":{"tags":["generateCoupons"],"summary":"Generates coupon codes for a brand.","operationId":"\/generate-coupons","parameters":[{"name":"quantity","in":"query","description":"Quantity of coupons to be generated.","required":true,"schema":{"type":"integer"}},{"name":"prefix","in":"query","description":"Prefix to be used in the coupon codes.","required":false,"schema":{"type":"string"}}],"responses":{"201":{"description":"Success.","content":{"application\/json":{"schema":{"properties":{"message":{"type":"string","example":"Coupon code(s) generation job sent."}},"type":"object"}}}},"401":{"description":"Error: Not authenticated.","content":{"application\/json":{"schema":{"properties":{"message":{"type":"string","example":"Token expired."}},"type":"object"}}}},"403":{"description":"Error: Not authorized.","content":{"application\/json":{"schema":{"properties":{"message":{"type":"string","example":"Not authorized."}},"type":"object"}}}}},"security":[{"bearer_token":[]}]}}},"components":{"securitySchemes":{"bearer_token":{"type":"apiKey","description":"Enter token in format (Bearer )","name":"Authorization","in":"header"}}}} \ No newline at end of file