1

So I'm using NelmioApiDocBundle to document my API in swagger format.

When i go to mydomain.com/api/doc I can see the documentation and it's fine. But for example I'm setting the query parameter (test_query1) as required, and when I call the API without this query it ignores this parameter and responds with 200. How can I force the API to respond with an error if test_query1 is not passed, without coding in the API?

/**
 * Test Controller to check OpenAPI specification
 *
 * This call prints ID provided in path
 *
 * @Route("/api/{id}/print", methods={"GET"})
 * @SWG\Response(
 *     response=200,
 *     description="ID found",
 *     @SWG\Schema(
 *         type="integer"
 *     )
 * )
 * @SWG\Parameter(
 *     name="test_query1",
 *     in="query",
 *     required=true,
 *     type="string",
 *     description="Test Query"
 * )
 * @SWG\Parameter(
 *     name="id",
 *     in="path",
 *     type="integer",
 *     description="id"
 * )
 */
Osama Aref
  • 13
  • 2
  • AFAIK, UI of Nelmio does now allow to make request when you define `required=true` to a paramater. – Mert Öksüz Jan 08 '19 at 14:03
  • @MertÖksüz when I test the API on /api/docs, it doesnt allow the request if the parameter is missing. But when I test the API itself, it doesn't care about any parameter. – Osama Aref Jan 08 '19 at 14:09
  • Please show your controller code for this action. – Zorpen Jan 08 '19 at 15:17
  • Yes, that is only for documentation. You should check that page for route requirements. https://symfony.com/doc/current/routing/requirements.html – Mert Öksüz Jan 09 '19 at 10:16

0 Answers0