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. 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

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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.
This doesn't work anymore, sad that Jetbrains can't implement these simple formatting features.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.