Forum Discussion

Leandro's avatar
Leandro
New Contributor
5 years ago
Solved

Required parameter in function comments don't throw exception ?

/**
* @SWG\Get(
* path="/chargeability/{entity_type}/{id}/{weekStart}/{weekEnd}",
* summary="Get chargeability data for a team",
* tags={"Chargeability"},
* @SWG\Parameter(name="entity_type", type="string", required=true, in="path"),
* @SWG\Parameter(name="id", type="string", required=true, in="path"),
* @SWG\Parameter(name="weekStart", type="string", required=true, in="path"),
* @SWG\Parameter(name="weekEnd", type="string", required=true, in="path"),
* @SWG\Response(response=200,description="Chargeability detail"),
 * )
*/
public function run() {
...
foo($this->params['weekStart']);
}

I get the exception "weekStart is undefined", but in the comments I put a required=true to this param.
Should swagger throw an exception for this ? Or I have to check manually if parameters are set even if it is specified in the comment ?

  • Leandro's avatar
    Leandro
    5 years ago

    Hello

     

    Yes I am using php-swagger.
    One of my coleague explained to me that it was just to generate a documentation and it does no validation.

    So required parameter in function comments don't throw an exception

     

    Have a nice day

2 Replies

  • Hi there,

     

    It looks like you're using swagger-php, or possibly another php library. We don't manage any of the php libraries and don't know them well enough to provide support for them. It's best to file a ticket directly with the project.

     

    That said, keep in mind that many Swagger/OAS annotation libraries are meant to document behavior but not enforce it. The enforcement would be done either directly by you, or through the framework you're using.

    • Leandro's avatar
      Leandro
      New Contributor

      Hello

       

      Yes I am using php-swagger.
      One of my coleague explained to me that it was just to generate a documentation and it does no validation.

      So required parameter in function comments don't throw an exception

       

      Have a nice day