0.8.1 • Published 6 years ago

cozumel v0.8.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Cozumel

NPM version

Installation

Cozumel requires node v7.10.1 or higher for ES6 and async function support.

yarn global add cozumel

or

npm install -g cozumel

Usage

cozumel [options] <path>

Options

Run this command to see a list of all available options:

cozumel -h

Mirror

Coming soon

The mirror mode will test the api definition against the provided host, it will measure the response time and report any errors that occurred in the process.

cozumel -m api.example.com <path>

Adapters

Currently supported adapters:

Feel free to add your own by opening a pull request.

Gist

cozumel <gist-id>

The gist adapter makes use of the other file adapters. In case you want to use a specific revision, you can do so by doing the following:

cozumel <gist-id>:<sha>

JSON

{
  "hello-world": {
    "GET": {
      "response": {
        "type": "json",
        "content": "{\"message\": \"hello world!\"}"
      }
    }
  }
}

YAML

hello-world:
  GET:
    response:
      type: json
      content: "{\"message\": \"hello world!\"}"

Markdown

Custom Adapter

import {Adapter, App} from "../core"

export class MyAdapter extends Adapter
{
  isMatch(key: string)
  {
    return /^ya?ml/i.test(key);
  }

  async load (app: App, data: string)
  {
    ...
    return data;
  }
}

Your adapter has to return an object like the following

{
  'users': {
    GET: {
      params: [
        { name: 'id', type: 'number', required: false }
      ],
      response: {
        type?: string,
        content?: string
      }
    },

    POST: {
      params: [
        { name: 'login', type: 'string', required: true },
        { name: 'password', type: 'string', required: true }
      ],
      response: {
        type?: string,
        content?: string
      }
    }
  },
  'users/block': {
    POST: {
      params: [
        { name: 'id', type: 'number', required: true }
      ],
      response: {
        type?: string,
        content?: string
      }
    }
  }
}