Giter VIP home page Giter VIP logo

apib2json's Introduction

apib2json

build status code coverage version docker pulls docker pulls

A command-line utility to convert API Blueprint to JSON Schema.

Introduction

If you are building your API with Apiary you should know API Blueprint, right? Good documentation is cool but it would be nice to re-use your validation which you already wrote in MSON (or JSON Schema). So there is the task: Convert Blueprint to JSON Schema. This tool is specially for it.

It is built on top of apiaryio/protagonist which do hard job, but if you know this Node.js C++ binding you sure know that compilation of this library (npm install protagonist) takes time. This is the reason why this tool is also wrapped with Docker, but sure you can also use it with npm.

Installation

$ npm install --global apib2json

NOTE: Recommended way is using a dockerized version, just try $ docker run --rm bugyik/apib2json --help

Usage

$ apib2json --help

Usage: apib2json [options]

A command-line utility to convert API Blueprint to JSON Schema

Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -v, --verbose        Verbose mode, use with --output - default: false
    -p, --pretty         Output pretty (indented) JSON - default: false
    --indent <n>         Number of space characters used to indent code, use with --pretty - default: 2
    -i, --input <file>   Path to input (Apib) file - default: STDIN
    -o, --output <file>  Path to output (JSON) file - default: STDOUT

Example

NOTE: The example below requires docker installed (npm's version without prefix docker run --rm -i bugyik/)

$ docker run --rm -i bugyik/apib2json --pretty < input.apib > output.json

$ cat input.apib

## Coupon [/coupons/{id}]
A coupon contains information about a percent-off or amount-off discount you
might want to apply to a customer.

+ Attributes (object)
    + id: 250FF (string, required)
    + created: 1415203908 (number) - Time stamp
    + percent_off: 25 (number)

        A positive integer between 1 and 100 that represents the discount the coupon will apply.

    + redeem_by (number) - Date after which the coupon can no longer be redeemed
    
### Retrieve a Coupon [GET]
Retrieves the coupon with the given ID.

+ Response 200 (application/json)
    + Attributes (Coupon)

$ cat output.json

{
  "[GET]/coupons/{id}": [
    {
      "meta": {
        "type": "response",
        "title": null
      },
      "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "created": {
            "type": "number",
            "description": "Time stamp"
          },
          "percent_off": {
            "type": "number",
            "description": "A positive integer between 1 and 100 that represents the discount the coupon will apply."
          },
          "redeem_by": {
            "type": "number",
            "description": "Date after which the coupon can no longer be redeemed"
          }
        },
        "required": [
          "id"
        ]
      }
    }
  ]
}

NOTE: More examples of input/ouput are available in test/fixtures folder.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

Pull Requests are welcome!

Do you hate contributing to projects where you have to install direct version of Node.js? I know there are tools like nvm but there is also Docker to rescue! To begin developing, you just need docker and docker-compose installed and do this:

$ git clone [email protected]:o5/apib2json.git && cd apib2json/
$ docker-compose up

Do you need to go inside the container?

$ docker exec -it apib2json sh

NOTE: Assumes docker-composer up was finished.

License

MIT @ Petr Bugyík

apib2json's People

Contributors

o5 avatar mariochavez 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.