GithubHelp home page GithubHelp logo

rahulyhg / psx-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apioo/psx-api

0.0 1.0 0.0 351 KB

Parse and generate API specification formats

License: Apache License 2.0

PHP 87.35% HTML 11.40% TypeScript 0.54% RAML 0.72%

psx-api's Introduction

PSX Api

About

Currently there are several API specification formats (OpenAPI, RAML, Swagger, etc.) which describe the functionality of an API endpoint. This project provides a data model which contains the common information of an API endpoint. There are parser classes which create such models based on a specification and it is also possible to generate a specification from a model object. We have also created an online tool to test those conversions.

Parser

Generator

  • HTML (Generates a HTML representation of the resource)
  • JsonSchema (Generates a JsonSchema which contains all schemas of the specification)
  • Markdown (Generates a Markdown representation of the resource)
  • OpenAPI (Generates a OpenAPI 3.0 specification)
  • PHP (Generates PHP source code which represents a controller consuming the API resource)
  • RAML (Generates a RAML 1.0 specification)
  • Swagger (Generates a Swagger 2.0 specification)
  • Typescript (Generates a Typescript based client stub)
  • Template (Generates a representation based on a Twig template)

Usage

The root model object is called resource which represents a specific API endpoint. The following is a simple showcase of the resource API so you get a basic understanding how it is designed.

<?php

// reads the OpenAPI specification and generates a resource object which was
// defined under the path /foo
$resource = \PSX\Api\Parser\OpenAPI::fromFile('openapi.json', '/foo');

// returns the title
$resource->getTitle();

// returns available path parameters as PSX\Schema\PropertyInterface
$resource->getPathParameters();

// checks whether a specific request method is supported
$resource->hasMethod('POST');

// returns all allowed methods
$resource->getAllowedMethods();

// returns the available query parameters per method as PSX\Schema\PropertyInterface
$resource->getMethod('POST')->getQueryParameters();

// checks whether the method has a request specification
$resource->getMethod('POST')->hasRequest();

// returns the request body specification as PSX\Schema\SchemaInterface
$resource->getMethod('POST')->getRequest();

// checks whether the method has a response with the status code 201
$resource->getMethod('POST')->hasResponse(201);

// returns the response body specification as PSX\Schema\SchemaInterface
$resource->getMethod('POST')->getResponse(201);

// creates a PHP controller which consumes the defined /foo resource
$generator = new \PSX\Api\Generator\Php();

$source = $generator->generate($resource);

psx-api's People

Contributors

chriskapp avatar

Watchers

 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.