renderer

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SCHEMA_PATH = "components/schemas"

Default location for schema references without leading or training "/".

Functions

func RenderSchema

func RenderSchema(schema *types.Schema, r Renderer) []string

RenderStrings builds a string representation of a type result using the given pre, path, and post functions.

func RenderType

func RenderType(t *types.TypeElement, r Renderer) []string

RenderType builds strings for a TypeElement and its children.

Types

type JSONRenderer

type JSONRenderer struct {
	// contains filtered or unexported fields
}

JSONRenderer provides a simple string renderer.

func NewJSONRenderer

func NewJSONRenderer(opt *Options) *JSONRenderer

func (*JSONRenderer) DeReference

func (r *JSONRenderer) DeReference() bool

func (*JSONRenderer) Indent

func (r *JSONRenderer) Indent() int

func (*JSONRenderer) Path

func (r *JSONRenderer) Path(t *types.TypeElement) []string

Path is a function that builds a path string from a TypeElement. Format is: [<Name>:]<Type>[:<TypeRef>] - If Name is set, prefix with "Name", otherwise "-" - If TypeRef is set, suffix with "TypeRef", otherwise "-" - If Error is set, wrap entire string with "!"

func (*JSONRenderer) Post

func (r *JSONRenderer) Post(t *types.TypeElement) []string

func (*JSONRenderer) Pre

func (r *JSONRenderer) Pre(t *types.TypeElement) []string

func (*JSONRenderer) Prefix

func (r *JSONRenderer) Prefix() string

func (*JSONRenderer) ProcessResult

func (r *JSONRenderer) ProcessResult(result *types.Schema) ([]string, error)

func (*JSONRenderer) SetIndent

func (r *JSONRenderer) SetIndent(value int)

type OpenAPIRenderer

type OpenAPIRenderer struct {
	// Path
	URLPath string
	// contains filtered or unexported fields
}

OpenAPIRenderer provides a simple string renderer.

func NewOpenAPIRenderer

func NewOpenAPIRenderer(urlPath string, opt *Options) *OpenAPIRenderer

func (*OpenAPIRenderer) DeReference

func (r *OpenAPIRenderer) DeReference() bool

func (*OpenAPIRenderer) Indent

func (r *OpenAPIRenderer) Indent() int

func (*OpenAPIRenderer) Path

func (r *OpenAPIRenderer) Path(t *types.TypeElement) []string

Path is a function that builds a path string from a TypeElement.

func (*OpenAPIRenderer) Post

func (r *OpenAPIRenderer) Post(t *types.TypeElement) []string

func (*OpenAPIRenderer) Pre

func (r *OpenAPIRenderer) Pre(t *types.TypeElement) []string

func (*OpenAPIRenderer) Prefix

func (r *OpenAPIRenderer) Prefix() string

func (*OpenAPIRenderer) ProcessResult

func (r *OpenAPIRenderer) ProcessResult(result *types.Schema) ([]string, error)

func (*OpenAPIRenderer) SetIndent

func (r *OpenAPIRenderer) SetIndent(value int)

type Options

type Options struct {
	// DeReference converts TypeRefs to their included types.
	// - If TyepRefs have a cyclical relationship, the last TypeRef is kept as a TypeRef.
	DeReference bool

	// Prefix is a string used as a prefix for indented lines.
	Prefix string

	// Indent is used for rendering where indent matters.
	Indent int
}

func NewOptions

func NewOptions() *Options

type Renderer

type Renderer interface {
	// ProcessResult starts the render process on a Schema and returns a slice of strings.
	ProcessResult(result *types.Schema) ([]string, error)

	// DeReference returns true if schema references should be replaced with inline types.
	DeReference() bool

	// Indent returns the current indent value.
	Indent() int

	// SetIndent sets the indent to a given value.
	SetIndent(value int)

	// Prefix returns a prefix string with the current indent.
	Prefix() string

	// Pre and Post return strings before/after a type element's children are processed.
	Pre(t *types.TypeElement) []string
	Post(t *types.TypeElement) []string

	// Path is a function that builds a path string from a TypeElement.
	Path(t *types.TypeElement) []string
}

type SimpleRenderer

type SimpleRenderer struct {
	// contains filtered or unexported fields
}

SimpleRenderer provides a simple string renderer.

func NewSimpleRenderer

func NewSimpleRenderer(opt *Options) *SimpleRenderer

func (*SimpleRenderer) DeReference

func (r *SimpleRenderer) DeReference() bool

func (*SimpleRenderer) Indent

func (r *SimpleRenderer) Indent() int

func (*SimpleRenderer) Path

func (r *SimpleRenderer) Path(t *types.TypeElement) []string

Path is a function that builds a path string from a TypeElement. Format is: [<Name>:]<Type>[:<TypeRef>] - If Name is set, prefix with "Name", otherwise "-" - If TypeRef is set, suffix with "TypeRef", otherwise "-" - If Error is set, wrap entire string with "!"

func (*SimpleRenderer) Post

func (r *SimpleRenderer) Post(t *types.TypeElement) []string

func (*SimpleRenderer) Pre

func (r *SimpleRenderer) Pre(t *types.TypeElement) []string

func (*SimpleRenderer) Prefix

func (r *SimpleRenderer) Prefix() string

func (*SimpleRenderer) ProcessResult

func (r *SimpleRenderer) ProcessResult(result *types.Schema) ([]string, error)

func (*SimpleRenderer) SetIndent

func (r *SimpleRenderer) SetIndent(value int)

Jump to

Keyboard shortcuts

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