1.文档阅读
Swagger UI
https://github.com/DarkaOnLine/SwaggerLume
https://github.com/zircote/swagger-php/tree/master/Examples/petstore.swagger.io
2021-09-29 - 接口文档 - 学习/实践_william_n的博客-CSDN博客_接口文档怎么整理
2.整理输出 Configuration
- Run
php artisan swagger-lume:publish-config to publish configs (config/swagger-lume.php ) - Run
php artisan swagger-lume:publish-views to publish views (resources/views/vendor/swagger-lume ) - Run
php artisan swagger-lume:publish to publish everything - Run
php artisan swagger-lume:generate to generate docs - Access this locally using localhost:81/api/documentation
 Usage Add annotations to your php files to generate swagger documentation. Swagger uses Open API specification.
-
Information Annotation for information.
/**
* @OA\\Info(title="My First API", version="0.1")
*/
-
Tag Annotation for arranging API together.
/**
* @OA\\Tag(
* name="user",
* description="Operations about user",
* @OA\\ExternalDocumentation(
* description="Find out more about our store",
* url="<http://swagger.io>"
* )
* )
*/
-
Schema Annotation for Models.
<?php
/**
* @OA\\Schema(
* @OA\\Xml(name="Category")
* )
*/
class Category
{
/**
* @OA\\Property(format="int64")
* @var int
*/
public $id;
/**
* @OA\\Property()
* @var string
*/
public $name;
}
-
Get Annotation for Get Endpoint
/**
* @OA\\Get(
* path="/demo",
* @OA\\Response(response="200", description="An example resource")
* )
*/
-
Post Annotation for Post Endpoint
/**
* Add a new pet to the store
*
* @OA\\Post(
* path="/pet",
* tags={"pet"},
* operationId="addPet",
* @OA\\Response(
* response=405,
* description="Invalid input"
* ),
* security={
* {"petstore_auth": {"write:pets", "read:pets"}}
* },
* requestBody={"$ref": "#/components/requestBodies/Pet"}
* )
*/
public function addPet()
{
}
- Put Annotation for Update Endpoint
/**
* Update an existing pet
*
* @OA\\Put(
* path="/pet",
* tags={"pet"},
* operationId="updatePet",
* @OA\\Response(
* response=400,
* description="Invalid ID supplied"
* ),
* @OA\\Response(
* response=404,
* description="Pet not found"
* ),
* @OA\\Response(
* response=405,
* description="Validation exception"
* ),
* security={
* {"petstore_auth": {"write:pets", "read:pets"}}
* },
* requestBody={"$ref": "#/components/requestBodies/Pet"}
* )
*/
public function updatePet()
{
}
- Delete Annotation for Delete Endpoint
/**
* @OA\\Delete(
* path="/pet/{petId}",
* tags={"pet"},
* summary="Deletes a pet",
* operationId="deletePet",
* @OA\\Parameter(
* name="api_key",
* in="header",
* required=false,
* @OA\\Schema(
* type="string"
* )
* ),
* @OA\\Parameter(
* name="petId",
* in="path",
* description="Pet id to delete",
* required=true,
* @OA\\Schema(
* type="integer",
* format="int64"
* ),
* ),
* @OA\\Response(
* response=400,
* description="Invalid ID supplied",
* ),
* @OA\\Response(
* response=404,
* description="Pet not found",
* ),
* security={
* {"petstore_auth": {"write:pets", "read:pets"}}
* },
* )
*/
public function deletePet()
{
For more examples visit: https://github.com/zircote/swagger-php/tree/master/Examples/petstore.swagger.io https://github.com/DarkaOnLine/SwaggerLume Sample Swagger Documentation: Swagger UI 后续补充 ... |