docs

package module
v0.0.0-...-3528c8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 15 Imported by: 0

README

http-api-docs

A generator for go-btfs API endpoints documentation.

Table of Contents

Install

In order to build this project, you need to first install Go, clone this repo, and finally run make install:

> git clone https://github.com/TRON-US/http-api-docs "$(go env GOPATH)/src/github.com/TRON-US/http-api-docs"
> cd "$(go env GOPATH)/src/github.com/TRON-US/http-api-docs"
> make install

Usage

After installing you can run:

> http-api-docs

This should spit out a Markdown document. This is exactly the api.md documentation at https://github.com/TRON-US/go-btfs/tree/master/docs/content/reference/api/http.md, so you can redirect the output to just overwrite that file.

Captain

This project is captained by @hsanjuan.

Contribute

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT (C) TRON-US

Documentation

Overview

Package docs can be used to gather go-btfs commands and automatically generate documentation or tests.

Index

Constants

View Source
const APIPrefix = "/api/" + shell.API_VERSION
View Source
const IndentLevel = 4

How much to indent when generating the response schemas

View Source
const MaxIndent = 20

Failsafe when traversing objects containing objects of the same type

Variables

View Source
var IgnoreEndpoints = map[string]bool{}

A map of single endpoints to be skipped (subcommands are processed though).

View Source
var JsondocGlossary = jsondoc.NewGlossary().
	WithSchema(new(cid.Cid), jsondoc.Object{"/": "<cid-string>"}).
	WithName(new(multiaddr.Multiaddr), "multiaddr-string").
	WithName(new(peer.ID), "peer-id").
	WithSchema(new(peerstore.PeerInfo),
		jsondoc.Object{"ID": "peer-id", "Addrs": []string{"<multiaddr-string>"}})

Functions

func BTFSVersion

func BTFSVersion() string

func GenerateDocs

func GenerateDocs(api []*Endpoint, formatter Formatter) string

GenerateDocs uses a formatter to generate documentation for every endpoint

Types

type Argument

type Argument struct {
	Name        string
	Description string
	Type        string
	Required    bool
	Default     string
}

Argument defines an BTFS RPC API endpoint argument.

type Endpoint

type Endpoint struct {
	Name        string
	Arguments   []*Argument
	Options     []*Argument
	Description string
	Response    string
	Group       string
}

Endpoint defines an BTFS RPC API endpoint.

func AllEndpoints

func AllEndpoints() []*Endpoint

AllEndpoints gathers all the endpoints from go-btfs.

func Endpoints

func Endpoints(name string, cmd *cmds.Command) (endpoints []*Endpoint)

Endpoints receives a name and a go-btfs command and returns the endpoints it defines] (sorted). It does this by recursively gathering endpoints defined by subcommands. Thus, calling it with the core command Root generates all the endpoints.

type Formatter

type Formatter interface {
	GenerateIntro() string
	GenerateIndex(endp []*Endpoint) string
	GenerateEndpointBlock(endp *Endpoint) string
	GenerateArgumentsBlock(args []*Argument, opts []*Argument) string
	GenerateBodyBlock(args []*Argument) string
	GenerateResponseBlock(response string) string
	GenerateExampleBlock(endp *Endpoint) string
}

Formatter allows to implement generation of docs in different formats.

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter implements a markdown doc generator. It is used to generate the BTFS website API reference at https://github.com/ipfs/website/blob/master/content/pages/docs/api.md

func (*MarkdownFormatter) GenerateArgumentsBlock

func (md *MarkdownFormatter) GenerateArgumentsBlock(args []*Argument, opts []*Argument) string

func (*MarkdownFormatter) GenerateBodyBlock

func (md *MarkdownFormatter) GenerateBodyBlock(args []*Argument) string

func (*MarkdownFormatter) GenerateEndpointBlock

func (md *MarkdownFormatter) GenerateEndpointBlock(endp *Endpoint) string

func (*MarkdownFormatter) GenerateExampleBlock

func (md *MarkdownFormatter) GenerateExampleBlock(endp *Endpoint) string

func (*MarkdownFormatter) GenerateIndex

func (md *MarkdownFormatter) GenerateIndex(endps []*Endpoint) string

func (*MarkdownFormatter) GenerateIntro

func (md *MarkdownFormatter) GenerateIntro() string

func (*MarkdownFormatter) GenerateResponseBlock

func (md *MarkdownFormatter) GenerateResponseBlock(response string) string

Directories

Path Synopsis
This is an utility to generate documentation from go-btfs commands
This is an utility to generate documentation from go-btfs commands

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL