brianseitel/oasis-mson-parser

An MSON parser for PHP

dev-master 2016-05-23 05:04 UTC

This package is not auto-updated.

Last update: 2024-11-04 13:45:09 UTC


README

API Blueprint Parser for PHP

Oasis MSON Parser is a PHP wrapper for the Drafter library.

API Blueprint is Web API documentation language. You can find API Blueprint documentation on the API Blueprint site.

Install

The best way to install this is via Composer.

$ composer require brianseitel/oasis-mson-parser

NOTE: Oasis MSON Parser depends on the Drafter library. Please see that repo for build instructions.

Getting started

Signature

function parse(string $data, $format = 'json')

Quickstart Example

<?php

require 'vendor/autoload.php';

$results = Oasis\Parser::parse('# My API', 'json');

Parsing Result

Parsing this blueprint:

# GET /1
+ response

will produce the following object (result variable):

{
  "element": "parseResult",
  "content": [
    {
      "element": "category",
      "meta": {
        "classes": [
          "api"
        ],
        "title": ""
      },
      "content": [
        {
          "element": "category",
          "meta": {
            "classes": [
              "resourceGroup"
            ],
            "title": ""
          },
          "content": [
            {
              "element": "resource",
              "meta": {
                "title": ""
              },
              "attributes": {
                "href": "/1"
              },
              "content": [
                {
                  "element": "transition",
                  "meta": {
                    "title": ""
                  },
                  "content": [
                    {
                      "element": "httpTransaction",
                      "content": [
                        {
                          "element": "httpRequest",
                          "attributes": {
                            "method": "GET"
                          },
                          "content": []
                        },
                        {
                          "element": "httpResponse",
                          "attributes": {
                            "statusCode": "200"
                          },
                          "content": []
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Contribute

Fork & Pull Request.

License

MIT License. See the LICENSE file.