GithubHelp home page GithubHelp logo

bmorelax / drafter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apiaryio/drafter

0.0 0.0 0.0 15.62 MB

Snow Crash parser harness

License: MIT License

CMake 0.15% Dockerfile 0.01% Ruby 0.01% Makefile 0.02% Python 9.99% C++ 83.36% C 1.62% API Blueprint 4.63% Gherkin 0.03% Shell 0.04% Batchfile 0.06% Emacs Lisp 0.11%

drafter's Introduction

logo

Drafter Circle CI Build status

Snowcrash parser harness

API Blueprint Parser

Drafter is complex builder of API Blueprint. Internally it uses Snowcrash library, reference API Blueprint parser.

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

Additionally Drafter provide set of Wrappers for serialization, of parsing result, via SOS library into JSON and YAML format.

Drafter also provides the user ability to select the type of the output. There are two possible values:

  • API Elements Parse Result: Parse Result is defined in API Elements according to Parse Result Namespace.
  • Normal AST Parse Result: Parse Result defined by the API Blueprint AST Parse Result. The AST is deprecated and only available in the Drafter command line tool.

By default, Drafter assumes the Refract Parse Result.

Both the types of Parse Results are available in two different serialization formats, YAML and JSON. YAML is the default for the CLI.

Status

Install

OS X using Homebrew:

$ brew install drafter

AUR package for Arch Linux.

Other systems refer to build notes.

Usage

Drafter is both a library and a command line tool.

Command line tool

The command line tool allows you to parse a blueprint and/or check the validity of a blueprint.

$ cat << 'EOF' > blueprint.apib
# My API
## GET /message
+ Response 200 (text/plain)

        Hello World!
EOF

$ drafter blueprint.apib
element: "parseResult"
content:
  -
    element: "category"
    meta:
      classes:
        - "api"
      title: "My API"
...

See parse feature for the details on using the drafter command line tool.

C/C++ API

Please refer to drafter.h for the full API documentation. See Drafter bindings for using the library in other languages.

Parsing a blueprint to a JSON or YAML string

The drafter_parse_blueprint_to takes a source blueprint and returns the given blueprint parsed and serialized as API Elements in YAML or JSON.

int drafter_parse_blueprint_to(const char* source, char ** out, const drafter_options options);
#include <drafter/drafter.h>

const char* blueprint =
  "# My API\n"
  "## GET /message\n"
  "+ Response 200 (text/plain)\n"
  "\n"
  "      Hello World!\n";

drafter_options options;
options.format = DRAFTER_SERIALIZE_JSON;
options.sourcemap = true;

char* result = NULL;
if (drafter_parse_blueprint_to(blueprint, &result, options) == 0) {
    printf("%s\n", result);
    free(result);
}

Checking the validity of a blueprint

The drafter_check_blueprint function allows checking the validity of a blueprint. This function will return a drafter_result when the blueprint produces warnings and/or errors. With a drafter_result, the drafter_serialize function can be used to serialized the result as API Elements in YAML or JSON.

drafter_result* drafter_check_blueprint(const char* source);
#include <drafter/drafter.h>

const char* blueprint =
  "# My API\n"
  "## GET /message\n"
  "+ Response 200 (text/plain)\n"
  "\n"
  "      Hello World!\n";

drafter_result* result = drafter_check_blueprint(blueprint);
if (result) {
    // Serialize the result to print the warnings/errors

    drafter_options options;
    options.format = DRAFTER_SERIALIZE_JSON;
    options.sourcemap = true;

    char* out = drafter_serialize(result, options);
    printf("The blueprint produces warnings or errors:\n\n%s\n", out);
    free(out);

    drafter_free_result(result);
} else {
    printf("The given blueprint was valid.\n");
}

Build

Compiler Support

Compiler Minimum Supported Version
Clang 4.0
GCC 5.3
MSVC++ 2015
  1. Clone the repo + fetch the submodules:

    $ git clone --recursive git://github.com/apiaryio/drafter.git
    $ cd drafter
  2. Build & test Drafter:

    $ ./configure
    $ make test

    To include integration tests (using Cucumber) use the --include-integration-tests flag:

    $ ./configure --include-integration-tests
    $ make test

We love Windows too! Please refer to Building on Windows.

Drafter command line tool

  1. Build drafter:

    $ make drafter
  2. Install & use drafter:

    $ sudo make install
    $ drafter --help

Bindings

Drafter bindings in other languages:

CLI Wrapper

Contribute

Fork & Pull Request

If you want to create a binding for Drafter please refer to the Writing a Binding article.

License

MIT License. See the LICENSE file.

drafter's People

Contributors

pksunkara avatar zdne avatar klokane avatar kylef avatar tjanc avatar w-vi avatar alikh31 avatar kuangmarkeleven avatar goganchic avatar danielgtaylor avatar fbidu avatar abtris avatar ivangoncharov avatar almad avatar kuba-kubula avatar realityone avatar nadade avatar tobiashm avatar tnewmandenso avatar smizell avatar samuelmarks avatar ryansb avatar fosrias avatar lfaraone avatar linusu avatar lilymgoh avatar ksmyth avatar dewe avatar tenzer avatar janpio 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.