...

Package disco

import "google.golang.org/api/google-api-go-generator/internal/disco"
Overview
Index

Overview ▾

Package disco represents Google API discovery documents.

type Auth

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

type Auth struct {
    OAuth2Scopes []Scope
}

func (*Auth) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

type Document

A Document is an API discovery 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"`
}

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

Kind classifies a Schema.

type Kind int
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

A Method holds information about a resource 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
    APIVersion            string

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

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

A Parameter holds information about a method parameter.

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

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

A Resource holds information about a Google API Resource.

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

type ResourceList

type ResourceList []*Resource

func (*ResourceList) UnmarshalJSON

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

type Schema

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.

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:"-"`
}

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

A Scope is an OAuth2 scope.

type Scope struct {
    ID          string
    Description string
}

type Variant

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

type VariantMapItem

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