disco

package
v0.0.0-...-112b1c4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package disco represents Google API discovery documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	OAuth2Scopes []Scope
}

Auth represents the auth section of a discovery document. Only OAuth2 information is retained.

func (*Auth) UnmarshalJSON

func (a *Auth) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Document

type Document struct {
	ID                string             `json:"id"`
	Name              string             `json:"name"`
	Version           string             `json:"version"`
	Title             string             `json:"title"`
	RootURL           string             `json:"rootUrl"`
	MTLSRootURL       string             `json:"mtlsRootUrl"`
	ServicePath       string             `json:"servicePath"`
	BasePath          string             `json:"basePath"`
	DocumentationLink string             `json:"documentationLink"`
	Auth              Auth               `json:"auth"`
	Features          []string           `json:"features"`
	Methods           MethodList         `json:"methods"`
	Schemas           map[string]*Schema `json:"schemas"`
	Resources         ResourceList       `json:"resources"`
}

A Document is an API discovery document.

func NewDocument

func NewDocument(bytes []byte) (*Document, error)

NewDocument unmarshals the bytes into a Document. It also validates the document to make sure it is error-free.

type Kind

type Kind int

Kind classifies a Schema.

const (
	// SimpleKind is the category for any JSON Schema that maps to a
	// primitive Go type: strings, numbers, booleans, and "any" (since it
	// maps to interface{}).
	SimpleKind Kind = iota

	// StructKind is the category for a JSON Schema that declares a JSON
	// object without any additional (arbitrary) properties.
	StructKind

	// MapKind is the category for a JSON Schema that declares a JSON
	// object with additional (arbitrary) properties that have a non-"any"
	// schema type.
	MapKind

	// AnyStructKind is the category for a JSON Schema that declares a
	// JSON object with additional (arbitrary) properties that can be any
	// type.
	AnyStructKind

	// ArrayKind is the category for a JSON Schema that declares an
	// "array" type.
	ArrayKind

	// ReferenceKind is the category for a JSON Schema that is a reference
	// to another JSON Schema.  During code generation, these references
	// are resolved using the API.schemas map.
	// See https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.28
	// for more details on the format.
	ReferenceKind
)

type MediaUpload

type MediaUpload struct {
	Accept    []string
	MaxSize   string
	Protocols map[string]Protocol
}

type Method

type Method struct {
	Name                  string
	ID                    string
	Path                  string
	HTTPMethod            string
	Description           string
	Parameters            ParameterList
	ParameterOrder        []string
	Request               *Schema
	Response              *Schema
	Scopes                []string
	MediaUpload           *MediaUpload
	SupportsMediaDownload bool

	JSONMap map[string]interface{} `json:"-"`
}

A Method holds information about a resource method.

func (*Method) UnmarshalJSON

func (m *Method) UnmarshalJSON(data []byte) error

type MethodList

type MethodList []*Method

func (*MethodList) UnmarshalJSON

func (ml *MethodList) UnmarshalJSON(data []byte) error

type Parameter

type Parameter struct {
	Name string
	Schema
	Required bool
	Repeated bool
	Location string
}

A Parameter holds information about a method parameter.

type ParameterList

type ParameterList []*Parameter

func (*ParameterList) UnmarshalJSON

func (pl *ParameterList) UnmarshalJSON(data []byte) error

type Property

type Property struct {
	Name   string
	Schema *Schema
}

type PropertyList

type PropertyList []*Property

func (*PropertyList) UnmarshalJSON

func (pl *PropertyList) UnmarshalJSON(data []byte) error

type Protocol

type Protocol struct {
	Multipart bool
	Path      string
}

type Resource

type Resource struct {
	Name      string
	FullName  string // {parent.FullName}.{Name}
	Methods   MethodList
	Resources ResourceList
}

A Resource holds information about a Google API Resource.

type ResourceList

type ResourceList []*Resource

func (*ResourceList) UnmarshalJSON

func (rl *ResourceList) UnmarshalJSON(data []byte) error

type Schema

type Schema struct {
	ID                   string // union types not supported
	Type                 string // union types not supported
	Format               string
	Description          string
	Properties           PropertyList
	ItemSchema           *Schema `json:"items"` // array of schemas not supported
	AdditionalProperties *Schema // boolean not supported
	Ref                  string  `json:"$ref"`
	Default              string
	Pattern              string
	Enums                []string `json:"enum"`
	// Google extensions to JSON Schema
	EnumDescriptions []string
	Variant          *Variant

	RefSchema *Schema `json:"-"` // Schema referred to by $ref
	Name      string  `json:"-"` // Schema name, if top level
	Kind      Kind    `json:"-"`
}

A Schema holds a JSON Schema as defined by https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1. We only support the subset of JSON Schema needed for Google API generation.

func (*Schema) ElementSchema

func (s *Schema) ElementSchema() *Schema

ElementSchema returns the schema for the element type of s. For maps, this is the schema of the map values. For arrays, it is the schema of the array item type.

ElementSchema panics if called on a schema that is not of kind map or array.

func (*Schema) IsIntAsString

func (s *Schema) IsIntAsString() bool

IsIntAsString reports whether the schema represents an integer value formatted as a string.

type Scope

type Scope struct {
	ID          string
	Description string
}

A Scope is an OAuth2 scope.

type Variant

type Variant struct {
	Discriminant string
	Map          []*VariantMapItem
}

type VariantMapItem

type VariantMapItem struct {
	TypeValue string `json:"type_value"`
	Ref       string `json:"$ref"`
}

Jump to

Keyboard shortcuts

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