gosnow

package module
Version: v0.0.0-...-b678a93 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2015 License: MIT Imports: 4 Imported by: 0

README

Gosnow GoDoc Build Status Coverage Status

A Go library for handling the API Blueprint format, wrapping Drafter and Snow Crash.

Based on RedSnow, the Ruby binding for Snow Crash.

Setup

Setup the inner drafter directory with: git submodule update --init --recursive

Install the drafter dylib with make install

Run the pure C tests with make test

Issues

linking to the libdrafter.dylib is currently done by linking the library to the global scope in /usr/local/lib/. It would be much preferred to have the dylib found locally.

This is the runtime error that occurs when the global library is not present

dyld: Library not loaded: /usr/local/lib/libdrafter.dylib
  Referenced from: /Users/uname/dev/gosnow/./test
  Reason: image not found

Documentation

Index

Constants

View Source
const (
	NoWarning                 = 0
	APINameWarning            = 1
	DuplicateWarning          = 2
	FormattingWarning         = 3
	RedefinitionWarning       = 4
	IgnoringWarning           = 5
	EmptyDefinitionWarning    = 6
	NotEmptyDefinitionWarning = 7
	LogicalErrorWarning       = 8
	DeprecatedWarning         = 9
	IndentationWarning        = 10
	AmbiguityWarning          = 11
	URIWarning                = 12
)

Warning Codes see https://github.com/apiaryio/snowcrash/blob/master/src/SourceAnnotation.h#L128

View Source
const (
	NoError          = 0
	ApplicationError = 1
	BusinessError    = 2
	SymbolError      = 3
)

Error Codes see https://github.com/apiaryio/snowcrash/blob/master/src/SourceAnnotation.h#L113

View Source
const (
	// ScRenderDescriptionsOptionKey causes the parser to render markdown in description
	ScRenderDescriptionsOptionKey = 1 << 0
	// RequireBlueprintNameOptionKey causes the parser to treat missing blueprint name as error
	RequireBlueprintNameOptionKey = 1 << 1
	// ExportSourcemapOptionKey causes the parser to export source maps AST
	ExportSourcemapOptionKey = 1 << 2
)

Variables

This section is empty.

Functions

func RawOptionParse

func RawOptionParse(source string, flags int) ([]byte, error)

RawOptionParse parses the inputted string and passes it to the drafter library for parsing. The raw JSON result is then returned from the function

Types

type Action

type Action struct {
	Name        string
	Description string
	// HTTP request method or nil
	Method string
	// action-specific URI parameters or nil
	Parameters []Parameter
	// TODO: in RedSnow, these are flattened out. Ideally these should be too
	Attributes struct {
		// action relation attribute
		Relation string
		// action uri template attribute
		UTITemplate string
	}
	Content []interface{}
	// action transaction examples
	Examples []TransactionExample
}

Action Blueprint AST node represents 'action section'

type Blueprint

type Blueprint struct {
	Version string `json:"_version"`
	// Metadata collection Blueprint AST node
	Metadata []struct {
		Name  string
		Value string
	}
	// Resource group Blueprint AST node
	// array of resources in the group
	ResourceGroups []struct {
		Name        string
		Description string
		Resources   []Resource
	}
	Name        string
	Description string
	Element     string
}

Blueprint is a data representation of the ast blueprints

type BlueprintSourcemap

type BlueprintSourcemap interface{}

BlueprintSourcemap is a blueprint for sourcemaps

TODO: fill this out just as the AST blueprint is

type LocationPoint

type LocationPoint struct {
	// Zero-based index of the character where warning has occurred.
	Index int
	//  Number of the characters from index where warning has occurred.
	Length int
}

LocationPoint makes up an array of possibly non-continuous blocks of the source API Blueprint.

type Parameter

type Parameter struct {
	Name string
	// an arbitrary type of the parameter or nil
	Type        string
	Description string
	// parameter necessity flag
	// TODO: change this to be an enum indicating required`, optional or undefined
	// Where undefined implies required according to the API Blueprint Specification
	Required bool
	// default value of the parameter or nil
	DefaultValue string `json:"default"`
	// example value of the parameter or nil
	ExampleValue string `json:"example"`
	// an enumeration of possible parameter values
	Values []struct {
		Value string
	}
}

Parameter is a URI parameter Blueprint AST node represents one 'parameters section' parameter

type ParseResult

type ParseResult struct {
	AST       Blueprint
	SourceMap BlueprintSourcemap
	// Description of a parsing error as occurred during parsing.
	// If this field is present && code different from 0 then the
	// content of ast field should be ignored.
	Error SourceAnnotation
	// Ordered array of parser warnings as occurred during the parsing.
	Warnings []SourceAnnotation
}

ParseResult contains all the information resulting from the parse in a fully typed structured format see: https://github.com/apiaryio/api-blueprint-ast/blob/master/Parse%20Result.md

func OptionParse

func OptionParse(source string, options int) (*ParseResult, error)

OptionParse parses the inputted string using the drafter library with the specified options to affect the parse and unmarshals the returned json into a struct containing all the necessary information

func Parse

func Parse(source string) (*ParseResult, error)

Parse is a wrapper around OptionParse passing in 0 for the options value, indicating normal parsing behavior

type Payload

type Payload struct {
	Name        string
	Description string
	// array of HTTP header fields of the message or nil
	Headers []struct {
		Name  string
		Value string
	}
	// HTTP-message body or nil
	Body string
	// HTTP-message body validation schema or nil
	Schema string
	// Symbol Reference if the payload is a reference
	Reference struct {
		ID string
	}
	Content []interface{}
}

Payload is a HTTP message payload Blueprint AST node

type Resource

type Resource struct {
	Element     string
	Name        string
	Description string
	URITemplate string
	Model       Payload
	Parameters  []Parameter
	Actions     []Action
}

Resource is a resource within the blueprint

type SourceAnnotation

type SourceAnnotation struct {
	Message  string
	Code     int
	Location []LocationPoint
}

SourceAnnotation is a building block of the json for API Blueprints

func (*SourceAnnotation) Ok

func (s *SourceAnnotation) Ok() bool

Ok returns whether or not the return code indicated success

type TransactionExample

type TransactionExample struct {
	Name        string
	Description string
	// example request payloads
	Requests []Payload
	// example response payloads
	Responses []Payload
}

TransactionExample Blueprint AST node

Jump to

Keyboard shortcuts

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