9

I'm working with a large number of files that have PHP block docs with Swagger PHP annotations on them, however they are not indented. Is there anyway to automatically format them with spaces?

Turning

/**
 * @SWG\Api(
 * path="/building/{buildingId}",
 * @SWG\Operation(
 * method="GET",
 * type="Building",
 * summary="Returns a Building object by ID",
 * nickname="building/getBuilding",
 * @SWG\Parameter(
 * name="buildingId",
 * description="ID of the building that needs to be fetched",
 * paramType="path",
 * required=false,
 * type="string",
 * defaultValue="1"
 * )
 * )
 * )
 */

Into

/**
 * @SWG\Api(
 *   path="/building/{buildingId}",
 *   @SWG\Operation(
 *     method="GET",
 *     type="Building",
 *     summary="Returns a Building object by ID",
 *     nickname="building/getBuilding",
 *     @SWG\Parameter(
 *       name="buildingId",
 *       description="ID of the building that needs to be fetched",
 *       paramType="path",
 *       required=false,
 *       type="string",
 *       defaultValue="1"
 *     )
 *   )
 * )
 */
Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Ed Knowles
  • 1,925
  • 1
  • 16
  • 24
  • 1
    AFAIK no because it was requested long time ago to not to touch such annotations at all, e.g. https://youtrack.jetbrains.com/issue/WI-10053 . But then -- I'm not suing such annotations myself and therefore could be wrong here. – LazyOne Jun 11 '15 at 17:53

1 Answers1

6

Looking into this unfortunately there isn't anything built into PHPStorm to do this. I fixed this issue with a bit of node and have open sourced my work if anyone else needs it.

:)

https://github.com/eknowles/grunt-tidy-annotations

Ed Knowles
  • 1,925
  • 1
  • 16
  • 24
  • 1
    Is this solution still working? I've tried it but it doesn't format the Swagger annotations. Is there some native support in PHPStorm for formatting Swagger annotations by now? – chrisch Jun 09 '20 at 15:33
  • Unfortunately wasn't working anymore, not for new versions of swagger and PHPStorm doesn't have a native support do Swagger annotations as far I know. – Fabio William Conceição Jan 20 '21 at 08:43
  • This doesn't work anymore, sad that Jetbrains can't implement these simple formatting features. – Denialos Feb 26 '21 at 13:02