templater

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingEncoder = errors.New("missing encoder")
View Source
var ErrUnknownLanguage = errors.New("language is not known")

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	HTTPVerb string
	Path     string
	OpenAPI  struct {
		Operation *openapi3.Operation
		PathItem  *openapi3.PathItem
		Document  *openapi3.T
	}
}

Endpoint defines a openapi operation and meta information for templating

func NewEndpoint

func NewEndpoint(HTTPVerb string, path string, operation *openapi3.Operation, pathItem *openapi3.PathItem, document *openapi3.T) *Endpoint

type Language

type Language interface {
	GetAdditionals(data *TemplateData) map[string]interface{} // Allows the language to set additional data to the template data
	GetTemplate() (*template.Template, error)                 // Must return the template for the code sample
	Name() string
}

Language defines an interface for each language to be used with the templater

type TemplateData

type TemplateData struct {
	Parameters         *types.Parameters      // Different parameter types
	SecurityParameters *types.Parameters      // Security related parameters (authentication), their value is either "${TOKEN}" or "Bearer ${TOKEN}"
	Path               string                 // Example path
	QueryParamsString  string                 // Example query params as urlencoded string
	URL                string                 // Example URL
	HTTPVerb           string                 // HTTP Method
	Body               interface{}            // The body as golang data type
	BodyString         string                 // The body formatted in the endpoints "accept" format	Meta               *types.FormattingMeta
	BasicAuth          bool                   // True if basic Auth is enabled
	Additionals        map[string]interface{} // Language specific data
	Formatting         *types.FormattingMeta  // Metadata about the format used
}

TemplateData holds all data available in templating

type Templater

type Templater interface {
	Template(language types.Language, endpoint *Endpoint) (*types.CodeSample, error)
}

Templater templates a template

func NewTemplater

func NewTemplater(encoders map[string]types.Encoder, extractor types.Extractor, languages map[types.Language]Language) Templater

NewTemplater creates a new templating instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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