PHP code example of psx / openapi

1. Go to this page and download the library: Download psx/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/ */

    

psx / openapi example snippets


$info = new Info();
$info->setVersion('1.0.0');
$info->setTitle('Swagger Petstore');

$parameter = new Parameter();
$parameter->setName('limit');
$parameter->setIn('query');
$parameter->setDescription('How many items to return at one time (max 100)');
$parameter->setRequired(false);
$parameter->setSchema(Record::fromArray(['type' => 'integer', 'format' => 'int32']));

$mediaType = new MediaType();
$mediaType->setSchema(Record::fromArray(['$ref' => '#/components/schemas/Pets']));

$content = new MediaTypes();
$content->put('application/json', $mediaType);

$response = new Response();
$response->setDescription('An paged array of pets');
$response->setContent($content);

$responses = new Responses();
$responses->put('200', $response);

$operation = new Operation();
$operation->setSummary('List all pets');
$operation->setOperationId('listPets');
$operation->setTags(['pets']);
$operation->setParameters([$parameter]);
$operation->setResponses($responses);

$pathItem = new PathItem();
$pathItem->setGet($operation);

$paths = new Paths();
$paths->put('/pets', $pathItem);

$schemas = new Schemas();
$schemas->put('Pet', [
    '