2017 © Pedro Peláez
 

library phalswag

phalswag is a swagger toolkit for php using cphalcon framework

image

tomi20v/phalswag

phalswag is a swagger toolkit for php using cphalcon framework

  • Friday, January 22, 2016
  • by tomi20v
  • Repository
  • 1 Watchers
  • 2 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

phalswag is a component for the Phalcon framework, to validate incoming HTTP request against a swagger.json schema and also build the corresponding response the goal is to automate writing REST APIs as much as possible based on swagger definitions, (*1)

simplest example using the supplied Phalcon Mvc Controller extension:, (*2)

class UsersController extends Controller
{
    // by defining these,
    protected static $_swaggerPath = '../app/config/swagger';
    protected static $_swaggerFname = 'users.json';

    public function getAction() {

        try {

            $Response = $this->_process(
                // swagger operation ID
                'usersGet',
                // callback which receives input and shall return result data
                function($RequestModel) {
                    $User = UserModel::findById($RequestModel->id);
                    return $User;
                }
            );

        }
        catch (\Exception $e) {

            $Response = $this->ResponseBuilder->buildError(500);

        }

        return $Response;

    }
}

a more complete example would include:, (*3)

// get the operation object
$Operation = $this->SwaggerService->getOperationById(
    $operationId,
    $this->_Swagger
);

// bind to request model
$this->SwaggerService->bindRequest(
    $RequestModel,
    $Operation,
    $this->dispatcher->getParams(),
    $this->request
);

// get response schema and build from data object
$ResponseSchema = $this->SwaggerService->getResponseSchema(
    200,
    $Operation,
    $this->_Swagger
);
$Result = $this->SwaggerService->buildBySchema(
    $Object,
    $ResponseSchema
);

current status: traversable models for most of swagger definition elements can populate a request model (class of your choice) with data from the HTTP input. can do basic validation of this data but eg cannot validate structures in body. it can build responses from models containing result data. it cannot resolve $ref 's., (*4)

The Versions

22/01 2016

dev-master

9999999-dev

phalswag is a swagger toolkit for php using cphalcon framework

  Sources   Download

WTFPL

by t

01/12 2015

dev-dev-master

dev-dev-master

phalswag is a swagger toolkit for php using cphalcon framework

  Sources   Download

WTFPL

by t

30/03 2015

0.1.0

0.1.0.0

description_text

  Sources   Download

WTFPL

by t