• Stars
    star
    302
  • Rank 134,999 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API Blueprint Parser (C++)

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.

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 installation 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

#include <drafter/drafter.h>

The header itself is annotated with comments. C API unit tests provide more examples.

Parse API Blueprint into API Elements

The drafter_parse_blueprint_to function translates a buffered API blueprint into API Elements, serialized into one of its supported serialization formats.

drafter_error drafter_parse_blueprint_to(
    const char* source,
    char** out,
    const drafter_parse_options* parse_opts,
    const drafter_serialize_options* serialize_opts);
);

Given a pointer to a UTF-8 encoded c-string,

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

Without options, the resulting API Elements is serialized as YAML.

char* yamlApie = NULL;
if (DRAFTER_OK == drafter_parse_blueprint_to(blueprint, &yamlApie, NULL, NULL)) {
    printf("%s\n", yamlApie);
}

free(yamlApie);
Serialized as JSON

Tweaking drafter_serialize_options allows serialization into JSON.

drafter_serialize_options* serialize_options = drafter_init_serialize_options();
drafter_set_format(serialize_options, DRAFTER_SERIALIZE_JSON);

char* jsonApie = NULL;
if (DRAFTER_OK == drafter_parse_blueprint_to(blueprint, &jsonApie, NULL, serialize_options)) {
    printf("%s\n", jsonApie);
}

free(jsonApie);
drafter_free_serialize_options(serialize_options);

Validate API Blueprint

API Blueprint can be validated via drafter_check_blueprint.

drafter_error drafter_check_blueprint(
    const char* source,
    drafter_result** res,
    const drafter_parse_options* parse_opts);
Simple validation

The return value of drafter_check_blueprint indicates validation success.

drafter_result* result = NULL;
if (DRAFTER_OK == drafter_check_blueprint(blueprint, result)) {
    printf("Understood.\n");
}

drafter_free_result(result);
Access warnings and errors

After running drafter_check_blueprint, the result parameter is set to reference an API Element containing validation warnings or errors.

Because the result is an API Element - drafter_result - it can be serialized as such.

drafter_result* result = NULL;
drafter_check_blueprint(blueprint, result);

if(result) {
    char* yamlApie = drafter_serialize(result, NULL);
    printf("%s\n", yamlApie);
    free(yamlApie);
}

drafter_free_result(result);

Serialization of API Elements as JSON is achieved by tweaking drafter_serialize_options as discussed here.

Installation

Building Drafter will require a modern C++ compiler and CMake. The following compilers are tested and known to work:

Compiler Minimum Version
Clang 4.0
GCC 5.3
MSVC++ 2015

The following steps can be used to build and install Drafter:

  1. Download a stable release of Drafter (release tarballs can be found in GitHub Releases):

    $ curl -OL <url to drafter release from GitHub releases>
    $ tar xvf drafter.tar.gz
    $ cd drafter

    Alternatively, you can clone the source repository, for example:

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

    POSIX (macOS/Linux):

    $ mkdir build
    $ cd build
    $ cmake ..
    $ make
    $ [sudo] make install

    NOTE: You can use cmake -DCMAKE_INSTALL_PREFIX="$HOME/.local .. if you don't want a system wide install.

    Windows:

    > mkdir build
    > cd build
    > cmake ..
    > cmake --build . --target drafter --config Release

    On Windows, drafter.exe can be found inside src\Release

  3. You can now use Drafter CLI and library:

    $ 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.

More Repositories

1

api-blueprint

API Blueprint
8,622
star
2

dredd

Language-agnostic HTTP API Testing Tool
JavaScript
4,145
star
3

mson

Markdown Syntax for Object Notation
896
star
4

snowcrash

API Blueprint Parser
C++
373
star
5

protagonist

Protagonist is Node.js wrapper for the API Blueprint parser
C++
349
star
6

apiary-client

Apiary CLI client
Ruby
203
star
7

curl-trace-parser

Parser for output from Curl --trace option
JavaScript
198
star
8

api-blueprint-sublime-plugin

API Blueprint Sublime Text plugin
Python
176
star
9

s3-streaming-upload

s3-streaming-upload is node.js library that listens to your stream and upload its data to Amazon S3 using ManagedUpload API.
JavaScript
123
star
10

gavel-spec

Behavior specification for Gavel, validator of HTTP transactions
Gherkin
105
star
11

swagger2blueprint

Convert Swagger API descriptions into API Blueprint
JavaScript
99
star
12

gavel.js

Validator of HTTP messages (JavaScript implementation)
JavaScript
96
star
13

dredd-example

Example application using Dredd and CI
JavaScript
85
star
14

api-elements.js

Library for consuming API Elements in JavaScript
JavaScript
74
star
15

redsnow

Ruby binding for the Snow Crash library, also a thermonuclear weapon.
Ruby
69
star
16

drafter.js

API Blueprint parser in JS
JavaScript
55
star
17

fury.js

API Description SDK
JavaScript
52
star
18

emscripten-docker

Emscripten as docker images
Dockerfile
51
star
19

cloudwatch-to-papertrail

Lambda to send logs from Cloudwatch to Papertrail
JavaScript
48
star
20

blueprint-parser

Deprecated PEG.js-based parser for parsing legacy Apiary Blueprint Format
CoffeeScript
47
star
21

polls-api

Polls is an example web API that allows consumers to view polls and vote in them.
Python
46
star
22

api-blueprint-rfcs

The API Blueprint RFC process
44
star
23

chrome-extension-ci

How to put a Chrome Extension into CI
JavaScript
41
star
24

attributes-kit

DEPRECATED Attributes Kit helps you with rendering MSON.
JavaScript
39
star
25

drafter-npm

Node API Blueprint Parser
JavaScript
37
star
26

language-templates

Language templates used to render example HTTP calls in different languages
HTML
36
star
27

polls-app

Swift iPhone and iPad Client for Polls API, using Hyperdrive API client
Swift
34
star
28

heroku-datadog-drain-golang

Funnel metrics from multiple Heroku apps into DataDog using statsd.
Go
34
star
29

api-blueprint-ast

API Blueprint AST Serialization Media Types [adhd, apib]
32
star
30

Paw-APIBlueprintGenerator

Paw extension providing support to export API Blueprint as a code generator.
CoffeeScript
32
star
31

api-elements

API Elements is a structure for describing APIs and the complex data structures used within them.
Python
28
star
32

http-string-parser

Parse HTTP Request and Response from String in Node.JS
CoffeeScript
26
star
33

apiblueprint.org

API Blueprint Website
CSS
19
star
34

apiblueprintorg

old apiblueprint.org site
CoffeeScript
19
star
35

dredd-hooks-python

Python Hooks for Dredd API Testing Framework
Python
19
star
36

matter_compiler

API Blueprint AST to API Blueprint Conversion Tool [adhd]
Ruby
16
star
37

apiaryio.github.com

Apiary Blog
HTML
16
star
38

api-blueprint-cheatsheet

API Blueprint Cheatsheet
API Blueprint
16
star
39

dredd-hooks-ruby

Ruby Hooks Worker for Dredd API Testing Framework
Ruby
15
star
40

fury-cli

Command line tool interface for Fury.js
JavaScript
12
star
41

fury-adapter-swagger

Swagger 2.0 parser adapter for Fury.js
JavaScript
11
star
42

dredd-transactions

Compiles a list of HTTP transactions (request-response pairs) from an API description document
JavaScript
10
star
43

markdown-parser

The real Markdown parser deal. You know, the one with a Markdown AST. Based on Upskirt, Sundown, Redcarpet or Hoedown whatever is trending.
C++
10
star
44

ivy

A Node.js queue library focused on easy, yet flexible task execution.
CoffeeScript
9
star
45

Paw-APIBlueprintImporter

Paw extension to import API Blueprint
JavaScript
8
star
46

sos

Simple c++ Object Serialization
C++
8
star
47

api.apiblueprint.org

API Blueprint
7
star
48

docker-base-images

Base docker images for Apiary applications
Dockerfile
7
star
49

deckardcain

Deckard Cain library identifies (media) type of API description files
JavaScript
6
star
50

black-belt

Internal toolbelt on steroids (idle since September 2018)
Python
6
star
51

constitutions

Write API Style Guide Rules locally, collaboratively and test them in CI
JavaScript
6
star
52

boutique.js

The finest representations to emphasize natural beauty of your MSON AST
CoffeeScript
6
star
53

protected-s3

Simple application that allows you to display the content of your S3 to authorised users only.
JavaScript
6
star
54

mson-ast

MSON AST Serialization Media Types
4
star
55

dredd-docker

Docker image for Dredd, a language-agnostic HTTP API testing tool
Shell
4
star
56

dredd-hooks-template

Template of an integration test suite for writing Dredd hooks handler in a new language
JavaScript
4
star
57

mson-zoo

Collection of MSON samples that can be used as a showcase or testing purposes
JavaScript
4
star
58

base-styles

Apiary Base CSS Styles
CSS
3
star
59

fury-adapter-apib-serializer

API Blueprint serializer for Fury.js
JavaScript
3
star
60

dredd-test-rails

Example Rails application for testing with API Blueprint and Dredd
Ruby
3
star
61

npm-boilerplate

Boilerplate for NPM package with Mocha, CoffeeScript and test directory structure
Shell
3
star
62

swagger-zoo

A collection of Swagger examples and their Refract representation
JavaScript
2
star
63

heroku-kafka-demo-nodejs

HTML
2
star
64

blueprint-transactions

Deprecated compiler of HTTP Transactions from API Blueprint AST
CoffeeScript
2
star
65

refract-query

JavaScript
2
star
66

generator-apiary-lib

Deprecated Apiary's Yeoman generator for basic library scaffolding
JavaScript
2
star
67

datapool

Library of miscellaneous reusable data models for API Blueprint
2
star
68

apiary_blueprint_convertor

Legacy Apiary Blueprint AST to API Blueprint AST convertor.
Ruby
1
star
69

metamorphoses

Transforms API Blueprint AST or legacy Apiary Blueprint AST into Apiary Application AST
CoffeeScript
1
star
70

wercker-npm-install-test

Dockerfile
1
star
71

pagerduty-overlap-checker

Pager Duty Overrides Checker
JavaScript
1
star
72

tully-test

API Blueprint
1
star
73

api-blueprint-http-formatter

Format pair of HTTP Request and Response to API Blueprint format
CoffeeScript
1
star
74

abagnale

Forge unique IDs for Refract data structure elements
JavaScript
1
star
75

blueprint-markdown-renderer

Default parser and set of settings for parsing Markdown blocks in API Blueprint
JavaScript
1
star
76

misterio

Testing project to compare C++ parser generator for ability to parse blueprint
C++
1
star
77

dribbble-api

API Blueprint
1
star
78

example-intersphinx-repo

This repository demonstrates using Intersphinx with indexes being exported in Docker volume
Python
1
star
79

console-proxy

Apiary Browser Console
JavaScript
1
star