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"
 *     )
 *   )
 * )
 */
1
  • 1
    AFAIK no because it was requested long time ago to not to touch such annotations at all, e.g. youtrack.jetbrains.com/issue/WI-10053 . But then -- I'm not suing such annotations myself and therefore could be wrong here.
    – LazyOne
    Commented Jun 11, 2015 at 17:53

1 Answer 1

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

3
  • 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
    Commented Jun 9, 2020 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. Commented Jan 20, 2021 at 8:43
  • This doesn't work anymore, sad that Jetbrains can't implement these simple formatting features.
    – Denialos
    Commented Feb 26, 2021 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.