Socket
Socket
Sign inDemoInstall

ocelot-docs

Package Overview
Dependencies
150
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ocelot-docs

Api docs generators using yaml


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
13.9 MB
Created
Weekly downloads
 

Readme

Source

Ocelot Docs

Generate Api documentation using YAML

version: 0.4.2
---
wizards:
  name: Management
  endpoints:
  - get: /wizards listWizards
    info: Finds all of the wizards that are available, sorted by hat size
    
  - post: /wizard createWizard
    info: Gives birth to a new wizard setting their name & (optionally) hat size
    body:
      name: string - What to call the wizard
      hatSize?: number - How big to make his hat
    responses:
    - 200: Success created.json

Docs are rendered to index.html & spec.json in your output directory, which is docs by default. If there are compilation errors they are rendered instead.

Example Docs

Contents

Using the CLI


# Install for your project
npm install --save-dev ocelot-docs

# Run inside your project
npx ocedocs --help

# Generate documentation
npx ocedocs --input apispec --output apidocs

# Watch the docs (regenerates the docs on page load)
npx ocedocs -w

Writing Docs

You write you doc specification in its own directory, which defaults to api/. There should be an info.yml in that directory which describes your api, it can have a name, description and template. The template refers to an npm package defining the api template, see Custom Templates.

Api Info

info.yml

name: Wizards Api
# template: my-custom-npm-template
description: >
  A simple API for creating & managing those pesky wizards

Endpoint Versions

Ocelot expects each version of your api to be in its own directory inside your input directory, e.g. v1/ or 1.0.0/, but you can have a single version at the root if you want. Ocelot sees any directory with an endpoints.yml file in as an api version.

endpoints.yml

wizards:
  base: /wzrd
  name: Wizards
  endpoints:
  - id: index
    method: get
    url: /list
    name: Fetch Wizards
    info: Looks for all wizards and sorts them by hat size
  - post: /new create
    name: Create Wizard
    body:
      name: string - The name of the wizard

Above is an example of an endpoints file, at the top level you have your groups which are a set of endpoint definitions.

Group Definition
FieldInfo
nameThe name of the group
baseoptional – A base url for this group, relative to the version's base
endpointsThe list of endpoint definitions
Endpoint Definition

An endpoint is a specific url & http method that performs some logic in your api and returns a response.

FieldInfo
idAn identifier for the endpoint
methodThe http method to access the endpoint
urlThe url to access the endpoint, relative to the group
nameThe name of the endpoint
infooptional – A longer description of the endpoint
responsesoptional – A list of Response Definition
paramsoptional – The url parameters e.g. /find/:id, an Argument Definition
queryoptional – The query parameters e.g. ?key=val, an Argument Definition
bodyoptional – The json/form body parameters, an Argument Definition
Endpoint Shorthand

As seen at the very top, you can use the endpoint shorthand which defines the method, url & id in one go. The equivalent of the previous example would be:

endpoints:
  - get: /list index
    name: Fetch Wizards
    info: Looks for all wizards and sorts them by hat size
Argument Definition

An argument definition is a YAML object with descriptions for a set of arguments. They key is the name of the argument and the value is a string definition containing the type, a dash (-) and the description. If the key ends with a ?, it is marked as optional.

name: string - The name of the wizard
age?: number - An optional age of the wizard
Response Definition
- 200: Success index/success.json
- 404: Not Found index/failed.json

A response definition is an array of objects which describe potential responses that the endpoint can return. It is in three parts, the key is the http status code, the first part is the human-friendly name and the last is the body, a reference to a file with an example json response in.

  • name is a friendly name of this response
  • status is the http status code this response comes with
  • body is a reference to a file which contains the example body (a json file)

To look for the body it will look look in data/ directory relative to your endpoints.yml file.

Version Info

When writing an endpoints.yml file, you can optionally define a version block at the top which defines meta information about this version of your api.

version: 0.0.1
base: /
groups:
  - wizards
  - witches
  - misc
---
wizards:
  # An endpoint group ...

Version Block

FieldInfo
versionThe name of this version
baseoptional – The base url for this version, all endpoints will be under this
groupsoptional - The order of the endpoint groups in this version, an array of strings

Custom templates

A template is an npm package used to render an api definition using pug. The package should have a template/ directory which should contain:

  • info.yml – A file containing info about the template
  • index.pug – A pug template to render the api definition
  • error.pug – A pug template to render errors or warnings

info.yml

name: Custom Template
version: 0.1.2
link: https://example.com

assets:
- js
- css
- img
FieldInfo
nameThe name of the template
versionThe version of the template
linkA link to the template's author
assetsoptional – A list of directories that will be copied into the compiled result

For more info, see the default template. There is also the spec.json, which is created along side your index.html, which is used to render the docs.

FAQs

Last updated on 18 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc