5

(Please bear with me, I've never set up something like this so I'm feeling my way in the dark)

I've watched some videos and read the documentation on installing swagger-php that I found here, and am trying to set up a basic bit of documentation.

I've created api.php in /application/modules/apiv1/documentation:

<?php
require("library/vendor/autoload.php");
$openapi = \OpenApi\Generator::scan($_SERVER['DOCUMENT_ROOT'] . '/modules/apiv1/controllers');
header('Content-Type: application/json');
echo $openapi->toJson();

and have a controller (LocationController) inside /application/modules/apiv1/controllers. One of the controller actions, that I'm using as my test dummy, is

/**
 * @OA\Get(
 *     path="/modules/apiv1/controllers/location/get",
 *     @OA\Response(response="200", description="An example resource")
 * )
 */
public function getAction()
{...}

What I'm trying to do next is to actually view the generated documentation on my local environment, but I have no idea how to view it, so the question is: Is there more setup for me to do to be able to view it? I've done the composer install shown on the zircote github: composer global require zircote/swagger-php but am not sure what my next step is, and I can't seem to find any "How to set up swagger for dummies" stuff, etc

2 Answers 2

4

swagger-php generates a JSON file that you can either convert to YAML or keep in JSON. This file is an OpenAPI description document that you can use with any compliant viewer. More about the OpenAPI standard/format can be read here.

The most common one is swagger-ui which can be used locally or in the cloud (by uploading your definition document). There are others such as stoplight which is cloud-based.

The link provided in the answer below (here) actually provides a good explaination on how to get swagger-ui running if you are not at ease with the JavaScript ecosystem.

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

Comments

1
  • Download Swagger-Php Using Composer
  • Add Annotations to Generate Documentation
  • Generate Swagger JSON File
  • Download Swagger-UI Package to your Project
  • Connect Swagger-UI To Your Code

More info in this link.

1 Comment

Thanks, I followed the link and attempted to follow the steps set out in it. However, I am having issues currently with use OpenApi\Annotations as OA; - The OpenApi namespace isn't defined. Once I get that issue sorted out I'll continue with that guide.

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.