openrpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: MIT Imports: 7 Imported by: 4

README

g0penrpc

Package g0penrpc defines go types for openrpc encoding/decoding, some helper functions to convert reflect.Type to a json schema, and some data structures to aide in building openrpc documents.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeSchema

func MakeSchema(t reflect.Type, schema Schema) error

Types

type Components

type Components struct {
	ContentDescriptors    *SchemaRegistry `json:"contentDescriptors,omitempty"`
	Schemas               *SchemaRegistry `json:"schemas,omitempty"`
	Examples              *SchemaRegistry `json:"examples,omitempty"`
	Links                 *SchemaRegistry `json:"links,omitempty"`
	Errors                *SchemaRegistry `json:"errors,omitempty"`
	ExamplePairingObjects *SchemaRegistry `json:"examplePairingObjects,omitempty"`
	Tags                  *SchemaRegistry `json:"tags,omitempty"`
}

type Contact

type Contact struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

type ContentDescriptor

type ContentDescriptor struct {
	Name        string  `json:"name"`
	Summary     string  `json:"summary,omitempty"`
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Deprecated  bool    `json:"deprecated,omitempty"`
	Schema      Pointer `json:"schema"`
}

type DocumentSpec1

type DocumentSpec1 struct {
	OpenRPC      string        `json:"openrpc"`
	Info         *Info         `json:"info"`
	Servers      []*Server     `json:"servers,omitempty"`
	Methods      []*Method     `json:"methods"`
	Components   *Components   `json:"components,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

func NewDocument

func NewDocument(methods []*Method, info *Info) *DocumentSpec1

NewDocument populates with references the components obj

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Example

type Example struct {
	Name          string      `json:"name,omitempty"`
	Summary       string      `json:"summary,omitempty"`
	Description   string      `json:"description,omitempty"`
	Value         interface{} `json:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty"`
}

type ExamplePairing

type ExamplePairing struct {
	Name        string     `json:"name,omitempty"`
	Description string     `json:"description,omitempty"`
	Summary     string     `json:"summary,omitempty"`
	Params      []*Example `json:"params,omitempty"`
	Result      *Example   `json:"result,omitempty"`
}

type ExternalDocs

type ExternalDocs struct {
	Description string `json:"description,omitempty"`
	URL         string `json:"url"`
}

type Info

type Info struct {
	Title          string   `json:"title"`
	Description    string   `json:"description,omitempty"`
	TermsOfService string   `json:"termsOfService,omitempty"`
	Contact        Contact  `json:"contact,omitempty"`
	License        *License `json:"license,omitempty"`
	Version        string   `json:"version"`
}

type License

type License struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}
type Link struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	Summary     string                 `json:"summary,omitempty"`
	Method      string                 `json:"method,omitempty"`
	Params      map[string]interface{} `json:"params,omitempty"`
	Server      *Server                `json:"server,omitempty"`
}

type Method

type Method struct {
	Name           string               `json:"name"`
	Tags           []Tag                `json:"tags,omitempty"`
	Summary        string               `json:"summary,omitempty"`
	Description    string               `json:"description,omitempty"`
	ExternalDocs   *ExternalDocs        `json:"externalDocs,omitempty"`
	Params         []*ContentDescriptor `json:"params"`
	Result         *ContentDescriptor   `json:"result"`
	Deprecated     bool                 `json:"deprecated,omitempty"`
	Servers        []Server             `json:"servers,omitempty"`
	Errors         []Error              `json:"errors,omitempty"`
	Links          []Link               `json:"links,omitempty"`
	ParamStructure string               `json:"paramStructure,omitempty"`
	Examples       []*ExamplePairing    `json:"examples,omitempty"`
}

type Pointer

type Pointer interface {
	//Refs returns a slice containing all the (ordered) references of a pointer
	Refs() []string
	//String formats the references as a slash-separated string
	String() string

	json.Marshaler
}

Pointer represents a generic json pointer

func NewPointer

func NewPointer(path string) (Pointer, error)

type PointerStore

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

PointerStore is a simple collection of json pointers

func NewPointerRegistry

func NewPointerRegistry() *PointerStore

func (*PointerStore) Get

func (r *PointerStore) Get(p Pointer) (s Schema, ok bool)

func (*PointerStore) Set

func (r *PointerStore) Set(pointer Pointer, item Schema)

type PointerTree

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

PointerTree is used to represent the hierarchy of properties of a json object

func NewPointerTree

func NewPointerTree(ptr Pointer) *PointerTree

func (*PointerTree) Find

func (pt *PointerTree) Find(match Pointer) *PointerTree

func (*PointerTree) Insert

func (pt *PointerTree) Insert(p Pointer) *PointerTree

func (*PointerTree) MarshalJSON

func (pt *PointerTree) MarshalJSON() ([]byte, error)

func (*PointerTree) ResolvePointers

func (pt *PointerTree) ResolvePointers(reg *PointerStore) (json.RawMessage, error)

ResolvePointers recursively marshals a tree; if a tree has no children it is treated as a pointer and used to fetch a Schema from the registry

type Schema

type Schema interface {
	json.Marshaler
	json.Unmarshaler
}

Schema is a json schema

func NewSchema

func NewSchema() Schema

type SchemaRegistry

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

SchemaRegistry is a collection of Schemas

func NewRegistry

func NewRegistry(unmarshalFrom Pointer) (*SchemaRegistry, error)

func NewSchemaRegistry

func NewSchemaRegistry(unmarshalFrom Pointer) (*SchemaRegistry, error)

NewSchemaRegistry returns a new JSON schema registry with 5 basic schemas already registered; the Pointer argument is used to select the subtree from which to start marshaling, can be nil

func (*SchemaRegistry) AddTypeException

func (s *SchemaRegistry) AddTypeException(typ reflect.Type)

AddTypeException signals that the type t should always be represented as a string regardless what its kind is

func (*SchemaRegistry) MarshalJSON

func (s *SchemaRegistry) MarshalJSON() ([]byte, error)

func (*SchemaRegistry) RegisterType

func (s *SchemaRegistry) RegisterType(t reflect.Type, registerAsString bool) (Pointer, string, error)

Register creates a new schema for the provided type, and returns the Pointer by which it is referenced

func (*SchemaRegistry) String

func (s *SchemaRegistry) String() string

type Server

type Server struct {
	Name        string                     `json:"name"`
	URL         string                     `json:"url"`
	Summary     string                     `json:"summary,omitempty"`
	Description string                     `json:"description,omitempty"`
	Variables   map[string]*ServerVariable `json:"variables,omitempty"`
}

type ServerVariable

type ServerVariable struct {
	Enum        []string `json:"enum,omitempty"`
	Default     string   `json:"default"`
	Description string   `json:"description,omitempty"`
}

type Tag

type Tag struct {
	Name         string        `json:"name"`
	Summary      string        `json:"summary,omitempty"`
	Description  string        `json:"description,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"`
}

Jump to

Keyboard shortcuts

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