swaggerのbasic structure
https://swagger.io/docs/specification/basic-structure/
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar require zircote/swagger-php
$ php composer.phar exec openapi -h
openapiファイルの作成
$ vendor/bin/openapi -o ${出力先} –format ${出力フォーマット} ${スキャン対象ディレクトリ}
$ vendor/bin/openapi -o openapi.json –format json app/Http/Controller/Api
<?php use OpenApi\Annotations as OA; class OpenApi {} class MyController { public funtion getResource(){ } }
https://zircote.github.io/swagger-php/guide/
The idea is to add swagger-php annotations or attributes next to the relevant PHP code in your application. These will contain the details about your API and swagger-php will convert those into machine-readable OpenAPI documentation.
require("vendor/autoload.php"); $openapi = \OpenApi\Generator::scan(["project"]); header('Content-Type: application/x-yaml'); echo $openapi->toYaml();
annotation:あるデータに対して関連する情報(メタデータ)を注釈として付与すること
/** * @OA\Get( * tags={"Common"}, * path="/api/user", * @OA\Response( * response="200". * description="success", * @OA\JsonContent(ref="#/components/schemas/user_responder") * ), * @OA\Response( * response="204", * description="there is no authorized user", * @OA\JsonContent(ref="#/components/schemas/204_no_content") * ) * ) */
schema:
/** * @OA\Schema( * schema="user_responder", * required={"id", "name", "email","created_at"}, * @OA\Property( * property="id", * type="integer", * description="userId", * example-"1" * ), * @OA\Property( * property="name", * type="string", * description="username", * example="sample taro" * ), * *) */
annotationはパスとレスポンスで、schemaは入力値を定義しとるんかな。
どちっかというと、swaggerがよくわかってない。