PHP code example of wilkques / openapi

1. Go to this page and download the library: Download wilkques/openapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wilkques / openapi example snippets


/**
 * @Servers([
 *      {
 *          "url": "{schema}://example.com",
 *          "description": "local server",
 *          "variables": {
 *              "schema": {
 *                  "enum": ["https", "http"],
 *                  "default": "http"
 *              }
 *          }
 *      }
 * ])
 */
class TestController extends Controller
{
    /**
     * test controller
     * 
     * @Path({
     *      "id": {
     *          "description": "id",
     *          "example": "123456789"
     *      }
     * })
     * @Request({
     *      "summary": "test get /api/test index",
     *      "description": "Test route description",
     *      "tags": ["User"],
     *      "security": [{"bearerAuth": []}]
     * })
     * @Response({
     *     "code": 302
     * })
     * @Response({
     *     "code": 400
     * })
     * @Response({
     *     "code": 500
     * })
     * @Response({
     *      "code": 200,
     *      "body": {
     *          "data": {
     *              "type": "array",
     *              "items": {
     *                  "type": "object",
     *                  "properties": {
     *                      "id": {
     *                          "type": "integer",
     *                          "description": "file id",
     *                          "example": 1
     *                      },
     *                      "name": {
     *                          "type": "string",
     *                          "description": "file name",
     *                          "example": "name"
     *                      }
     *                  }
     *              }
     *          }
     *      }
     * })
     */
    public function update(UserUpdateRequest $request)

    // or

    /**
     * test yaml controller
     * 
     * @Path(
     *      id:
     *          description: "id"
     *          example: 123456789
     * 
     * )
     * @Request(
     *      summary: "test get /api/test index"
     *      description: "Test route descriptioncd"
     *      tags:
     *      - "User"
     *      security: 
     *      - bearerAuth: []
     * )
     * @Response(
     *     code: 302
     * )
     * @Response(
     *     code: 400
     * )
     * @Response(
     *     code: 500
     * )
     * @Response(
     *      code: 200
     *      body:
     *          data:
     *              type: "array"
     *              items:
     *                  type: "object"
     *                  properties:
     *                      id:
     *                          type: "integer"
     *                          description: "file id"
     *                          example: 1
     *                      name: 
     *                          type: "string"
     *                          description: "file name"
     *                          example: "name"
     * )
     */
    public function yaml()

/**
 * @Request({
 *      "summary": "test get /api/test index",
 *      "description": "Test route description",
 *      "tags": ["Test"],
 *      "security": [{"bearerAuth": []}],
 *      "parameters": [
 *          {
 *              "in": "query",
 *              "name": "test",
 *              "ue of the custom parameter is "only", then display only the custom parameters. If the value is "merge", then merge the custom parameters with the results of the FormRequest. The default value is "merge".
 *          "content": {
 *              "multipart/form-data": {
 *                  "schema": {
 *                      "type": "object",
 *                      "


/**
 * @exclude
 */ 
public function destroy($id)


'only' => [
    'namespace' => [
        // 'App\Http\Controllers',
    ],
],

'exclude' => [
    'routes' => [
        'uri'   => [
            // route uri
        ],
        'name'  => [
            // route name or as
        ]
    ],
],

class UserUpdateRequest extends FormRequest
{
    /**
     * @Fields({
     *      "test": {
     *          "description": "Test description",
     *          "example": 1
     *      }
     * })
     */
    public function rules()
    {
        return [
            'test'          => 'in:1,2',
            'file.*.name'   => '