L5-Swagger icon indicating copy to clipboard operation
L5-Swagger copied to clipboard

Issue with optional parameter

Open yungts97 opened this issue 3 years ago • 1 comments

  • L5-Swagger Version: 8.0.7
  • PHP Version: 8.0.12
  • OS: Ubuntu

I would like to add an optional parameter to my GET API and I'm able to disable the required field, but when I passed an empty value to {item_per_page}, the URL is didn't remove {item_per_page} from the URL. image This is my CURL and request URL. image This is my Swagger Annotation

     /**
     * @OA\Get(
     *  path="/api/product-categories/{id}/products/{item_per_page}",
     *  summary="Retrieve products based on product category",
     *  description="Retrieve products",
     *  tags={"Product Categories [Public]"},
     *  @OA\Parameter(
     *      name="id",
     *      description="Product Category ID",
     *      example=1,
     *      required=true,
     *      in="path",
     *      @OA\Schema(
     *          type="integer"
     *      )
     *  ),
     *  @OA\Parameter(
     *      name="item_per_page",
     *      description="Number of item per page",
     *      example=15,
     *      in="path",
     *           @OA\Schema(
     *          type="integer"
     *      )
     *  ),
     *  @OA\Response(
     *      response=200,
     *      description="Success response",
     *      @OA\JsonContent(
     *          @OA\Property(
     *              property="status",
     *              type="string",
     *              example="success"
     *          ),
     *          @OA\Property(
     *              property="message",
     *              type="string",
     *              example=""
     *          ),
     *          @OA\Property(
     *              property="data",
     *              type="string",
     *              ref="#/components/schemas/ProductCategory"
     *          )
     *      )
     *  ),
     * )
     */

Do you guys have to meet this problem before? I need some helps with it.

yungts97 avatar Dec 22 '21 15:12 yungts97

Wouldn't that be a question for swagger-ui?

DerManoMann avatar Feb 28 '22 02:02 DerManoMann

hi you should use location in query for your optional parameters.

  • @OA\Parameter(
    •  name="id",
      
    •  description="Product Category ID",
      
    •  example=1,
      
    •  required=true,
      
    •  in="path",    =>>>>>>>>>>>>>>>>>>>>>> in="query"
      
    •  @OA\Schema(
      
    •      type="integer"
      
    •  )
      
    • ),

shahdix avatar Nov 16 '22 06:11 shahdix