Giter Site home page Giter Site logo

phrity-slim-openapi's Introduction

Build Status Coverage Status

OpenApi for Slim v4

Adapter that reads OpenApi schema and add included routes to Slim. By defining operationId in OpenApi schema, the adapter will automatically instanciate and call referenced controller class.

Some features

  • Automatic mapping of routes to controllers
  • OpenApi specification in JSON or YAML source
  • Optional validation of requests and responses

Installation

Install with Composer;

composer require phrity/slim-openapi

How to use

use Phrity\Slim\OpenApi;
use Slim\Factory\AppFactory;

// Create Slim App as you normally would
$slim = AppFactory::create();

// Create OpenApi adapter with OpenApi source
$openapi = new OpenApi('openapi.json');

// Push all routes from OpenApi to Slim
$openapi->route($slim);

// Run Slim
$slim->run();

How to define controllers

In order for automatic mapping to work, the operationId must be set on all defined routes in OpenApi source. If no method is specified, class method __invoke() will be called on class.

With invoke With method
 Classname Classname:method
 Namespace/Classname Namespace/Classname:method
 Namespace\\Classname Namespace\\Classname:method

Example

{
    "openapi": "3.0.0",
    "paths": {
        "/test": {
            "get": {
                "operationId": "Test/MyController",
                "description": "Will invoke on class Test\\MyController"
            },
            "put": {
                "operationId": "Test\\MyController:put",
                "description": "Will call method put() on class Test\\MyController"
            }
        }
    }
}

Documentation

Versions

Version PHP
1.2 ^7.4|^8.0 Request/Response validation, YAML support
1.1 ^7.4|^8.0 Settings & helpers
1.0 ^7.4|^8.0 Route registry

phrity-slim-openapi's People

Contributors

sirn-se avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.