vendor files

This commit is contained in:
Serguei Bezverkhi
2018-01-09 13:57:14 -05:00
parent 558bc6c02a
commit 7b24313bd6
16547 changed files with 4527373 additions and 0 deletions

10
vendor/github.com/googleapis/gnostic/surface/README.md generated vendored Normal file
View File

@ -0,0 +1,10 @@
# API Code Surface
This directory contains a Protocol Buffer-language model
suitable for generating support code for calling and
implementing an API.
It can be generated from other formats read by gnostic
and passed to code generator plugins to assist them by
providing a preprocessed API description that is easier
to generate.

20
vendor/github.com/googleapis/gnostic/surface/field.go generated vendored Normal file
View File

@ -0,0 +1,20 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package surface_v1
// ServiceType returns the Type associated with a field.
func (f *Field) ServiceType(m *Model) *Type {
return m.TypeWithTypeName(f.NativeType)
}

58
vendor/github.com/googleapis/gnostic/surface/model.go generated vendored Normal file
View File

@ -0,0 +1,58 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package surface_v1
import (
"path"
"strings"
)
func (m *Model) addType(t *Type) {
m.Types = append(m.Types, t)
}
func (m *Model) addMethod(method *Method) {
m.Methods = append(m.Methods, method)
}
func (m *Model) TypeWithTypeName(name string) *Type {
if name == "" {
return nil
}
for _, t := range m.Types {
if t.TypeName == name {
return t
}
}
return nil
}
func generateOperationName(method, path string) string {
filteredPath := strings.Replace(path, "/", "_", -1)
filteredPath = strings.Replace(filteredPath, ".", "_", -1)
filteredPath = strings.Replace(filteredPath, "{", "", -1)
filteredPath = strings.Replace(filteredPath, "}", "", -1)
return strings.Title(method) + filteredPath
}
func sanitizeOperationName(name string) string {
name = strings.Title(name)
name = strings.Replace(name, ".", "_", -1)
return name
}
func typeForRef(ref string) (typeName string) {
return path.Base(ref)
}

View File

@ -0,0 +1,251 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package surface_v1
import (
"fmt"
openapiv2 "github.com/googleapis/gnostic/OpenAPIv2"
)
// NewModelFromOpenAPI2 builds a model of an API service for use in code generation.
func NewModelFromOpenAPI2(document *openapiv2.Document) (*Model, error) {
return newOpenAPI2Builder().buildModel(document)
}
type OpenAPI2Builder struct {
model *Model
}
func newOpenAPI2Builder() *OpenAPI2Builder {
return &OpenAPI2Builder{model: &Model{}}
}
func (b *OpenAPI2Builder) buildModel(document *openapiv2.Document) (*Model, error) {
// Set model properties from passed-in document.
b.model.Name = document.Info.Title
b.model.Types = make([]*Type, 0)
b.model.Methods = make([]*Method, 0)
err := b.build(document)
if err != nil {
return nil, err
}
return b.model, nil
}
// buildV2 builds an API service description, preprocessing its types and methods for code generation.
func (b *OpenAPI2Builder) build(document *openapiv2.Document) (err error) {
// Collect service type descriptions from Definitions section.
if document.Definitions != nil {
for _, pair := range document.Definitions.AdditionalProperties {
t, err := b.buildTypeFromDefinition(pair.Name, pair.Value)
if err != nil {
return err
}
b.model.addType(t)
}
}
// Collect service method descriptions from Paths section.
for _, pair := range document.Paths.Path {
v := pair.Value
if v.Get != nil {
b.buildMethodFromOperation(v.Get, "GET", pair.Name)
}
if v.Post != nil {
b.buildMethodFromOperation(v.Post, "POST", pair.Name)
}
if v.Put != nil {
b.buildMethodFromOperation(v.Put, "PUT", pair.Name)
}
if v.Delete != nil {
b.buildMethodFromOperation(v.Delete, "DELETE", pair.Name)
}
}
return err
}
func (b *OpenAPI2Builder) buildTypeFromDefinition(name string, schema *openapiv2.Schema) (t *Type, err error) {
t = &Type{}
t.Name = name
t.Description = "implements the service definition of " + name
t.Fields = make([]*Field, 0)
if schema.Properties != nil {
if len(schema.Properties.AdditionalProperties) > 0 {
// If the schema has properties, generate a struct.
t.Kind = TypeKind_STRUCT
}
for _, pair2 := range schema.Properties.AdditionalProperties {
var f Field
f.Name = pair2.Name
f.Kind, f.Type, f.Format = b.typeForSchema(pair2.Value)
f.Serialize = true
t.addField(&f)
}
}
if len(t.Fields) == 0 {
if schema.AdditionalProperties != nil {
// If the schema has no fixed properties and additional properties of a specified type,
// generate a map pointing to objects of that type.
t.Kind = TypeKind_OBJECT
t.ContentType = typeForRef(schema.AdditionalProperties.GetSchema().XRef)
}
}
return t, err
}
func (b *OpenAPI2Builder) buildMethodFromOperation(op *openapiv2.Operation, method string, path string) (err error) {
var m Method
m.Operation = op.OperationId
m.Path = path
m.Method = method
m.Description = op.Description
m.Name = sanitizeOperationName(op.OperationId)
if m.Name == "" {
m.Name = generateOperationName(method, path)
}
m.ParametersTypeName, err = b.buildTypeFromParameters(m.Name, op.Parameters)
m.ResponsesTypeName, err = b.buildTypeFromResponses(&m, m.Name, op.Responses)
b.model.addMethod(&m)
return err
}
func (b *OpenAPI2Builder) buildTypeFromParameters(name string, parameters []*openapiv2.ParametersItem) (typeName string, err error) {
t := &Type{}
t.Name = name + "Parameters"
t.Description = t.Name + " holds parameters to " + name
t.Kind = TypeKind_STRUCT
t.Fields = make([]*Field, 0)
for _, parametersItem := range parameters {
var f Field
f.Type = fmt.Sprintf("%+v", parametersItem)
parameter := parametersItem.GetParameter()
if parameter != nil {
bodyParameter := parameter.GetBodyParameter()
if bodyParameter != nil {
f.Name = bodyParameter.Name
if bodyParameter.Schema != nil {
f.Kind, f.Type, f.Format = b.typeForSchema(bodyParameter.Schema)
}
f.Position = Position_BODY
}
nonBodyParameter := parameter.GetNonBodyParameter()
if nonBodyParameter != nil {
headerParameter := nonBodyParameter.GetHeaderParameterSubSchema()
if headerParameter != nil {
f.Name = headerParameter.Name
f.Type = headerParameter.Type
f.Position = Position_HEADER
}
formDataParameter := nonBodyParameter.GetFormDataParameterSubSchema()
if formDataParameter != nil {
f.Name = formDataParameter.Name
f.Type = formDataParameter.Type
f.Position = Position_FORMDATA
}
queryParameter := nonBodyParameter.GetQueryParameterSubSchema()
if queryParameter != nil {
f.Name = queryParameter.Name
f.Type = queryParameter.Type
f.Position = Position_QUERY
}
pathParameter := nonBodyParameter.GetPathParameterSubSchema()
if pathParameter != nil {
f.Name = pathParameter.Name
f.Type = pathParameter.Type
f.Format = pathParameter.Format
f.Position = Position_PATH
}
}
f.Serialize = true
t.addField(&f)
}
}
if len(t.Fields) > 0 {
b.model.addType(t)
return t.Name, err
}
return "", err
}
func (b *OpenAPI2Builder) buildTypeFromResponses(m *Method, name string, responses *openapiv2.Responses) (typeName string, err error) {
t := &Type{}
t.Name = name + "Responses"
t.Description = t.Name + " holds responses of " + name
t.Kind = TypeKind_STRUCT
t.Fields = make([]*Field, 0)
for _, responseCode := range responses.ResponseCode {
var f Field
f.Name = responseCode.Name
f.Serialize = false
response := responseCode.Value.GetResponse()
if response != nil && response.Schema != nil && response.Schema.GetSchema() != nil {
f.Kind, f.Type, f.Format = b.typeForSchema(response.Schema.GetSchema())
f.Kind = FieldKind_REFERENCE
t.addField(&f)
}
}
if len(t.Fields) > 0 {
b.model.addType(t)
return t.Name, err
}
return "", err
}
func (b *OpenAPI2Builder) typeForSchema(schema *openapiv2.Schema) (kind FieldKind, typeName, format string) {
ref := schema.XRef
format = schema.Format
if ref != "" {
return FieldKind_SCALAR, typeForRef(ref), format
}
if schema.Type != nil {
types := schema.Type.Value
if len(types) == 1 && types[0] == "string" {
return FieldKind_SCALAR, "string", format
}
if len(types) == 1 && types[0] == "integer" && format == "int32" {
return FieldKind_SCALAR, "integer", format
}
if len(types) == 1 && types[0] == "integer" {
return FieldKind_SCALAR, "integer", format
}
if len(types) == 1 && types[0] == "number" {
return FieldKind_SCALAR, "number", format
}
if len(types) == 1 && types[0] == "array" && schema.Items != nil {
// we have an array.., but of what?
items := schema.Items.Schema
if len(items) == 1 && items[0].XRef != "" {
return FieldKind_ARRAY, typeForRef(items[0].XRef), format
}
}
if len(types) == 1 && types[0] == "object" && schema.AdditionalProperties == nil {
return FieldKind_MAP, "object", format
}
}
if schema.AdditionalProperties != nil {
additionalProperties := schema.AdditionalProperties
if propertySchema := additionalProperties.GetSchema(); propertySchema != nil {
if ref := propertySchema.XRef; ref != "" {
return FieldKind_MAP, typeForRef(ref), format
}
}
}
// this function is incomplete... so return a string representing anything that we don't handle
return FieldKind_SCALAR, fmt.Sprintf("%v", schema), format
}

View File

@ -0,0 +1,303 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package surface_v1
import (
"errors"
"fmt"
"log"
openapiv3 "github.com/googleapis/gnostic/OpenAPIv3"
"strings"
)
// NewModelFromOpenAPIv3 builds a model of an API service for use in code generation.
func NewModelFromOpenAPI3(document *openapiv3.Document) (*Model, error) {
return newOpenAPI3Builder().buildModel(document)
}
type OpenAPI3Builder struct {
model *Model
}
func newOpenAPI3Builder() *OpenAPI3Builder {
return &OpenAPI3Builder{model: &Model{}}
}
func (b *OpenAPI3Builder) buildModel(document *openapiv3.Document) (*Model, error) {
// Set model properties from passed-in document.
b.model.Name = document.Info.Title
b.model.Types = make([]*Type, 0)
b.model.Methods = make([]*Method, 0)
err := b.build(document)
if err != nil {
return nil, err
}
return b.model, nil
}
// build builds an API service description, preprocessing its types and methods for code generation.
func (b *OpenAPI3Builder) build(document *openapiv3.Document) (err error) {
// Collect service type descriptions from Components/Schemas.
if document.Components != nil && document.Components.Schemas != nil {
for _, pair := range document.Components.Schemas.AdditionalProperties {
t, err := b.buildTypeFromSchemaOrReference(pair.Name, pair.Value)
if err != nil {
return err
}
if t != nil {
b.model.addType(t)
}
}
}
// Collect service method descriptions from each PathItem.
for _, pair := range document.Paths.Path {
b.buildMethodFromPathItem(pair.Name, pair.Value)
}
return err
}
// buildTypeFromSchemaOrReference builds a service type description from a schema in the API description.
func (b *OpenAPI3Builder) buildTypeFromSchemaOrReference(
name string,
schemaOrReference *openapiv3.SchemaOrReference) (t *Type, err error) {
if schema := schemaOrReference.GetSchema(); schema != nil {
t = &Type{}
t.Name = name
t.Description = "implements the service definition of " + name
t.Fields = make([]*Field, 0)
if schema.Properties != nil {
if len(schema.Properties.AdditionalProperties) > 0 {
// If the schema has properties, generate a struct.
t.Kind = TypeKind_STRUCT
}
for _, pair2 := range schema.Properties.AdditionalProperties {
if schema := pair2.Value; schema != nil {
var f Field
f.Name = pair2.Name
f.Kind, f.Type, f.Format = b.typeForSchemaOrReference(schema)
f.Serialize = true
t.addField(&f)
}
}
}
if len(t.Fields) == 0 {
if schema.AdditionalProperties != nil {
// If the schema has no fixed properties and additional properties of a specified type,
// generate a map pointing to objects of that type.
t.Kind = TypeKind_OBJECT
t.ContentType = typeForRef(schema.AdditionalProperties.GetSchemaOrReference().GetReference().GetXRef())
}
}
return t, err
} else {
return nil, errors.New("unable to determine service type for referenced schema " + name)
}
}
// buildMethodFromOperation builds a service method description
func (b *OpenAPI3Builder) buildMethodFromPathItem(
path string,
pathItem *openapiv3.PathItem) (err error) {
for _, method := range []string{"GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"} {
var op *openapiv3.Operation
switch method {
case "GET":
op = pathItem.Get
case "PUT":
op = pathItem.Put
case "POST":
op = pathItem.Post
case "DELETE":
op = pathItem.Delete
case "OPTIONS":
op = pathItem.Options
case "HEAD":
op = pathItem.Head
case "PATCH":
op = pathItem.Patch
case "TRACE":
op = pathItem.Trace
}
if op != nil {
var m Method
m.Operation = op.OperationId
m.Path = path
m.Method = method
m.Name = sanitizeOperationName(op.OperationId)
if m.Name == "" {
m.Name = generateOperationName(method, path)
}
m.Description = op.Description
m.ParametersTypeName, err = b.buildTypeFromParameters(m.Name, op.Parameters, op.RequestBody)
m.ResponsesTypeName, err = b.buildTypeFromResponses(&m, m.Name, op.Responses)
b.model.addMethod(&m)
}
}
return err
}
// buildTypeFromParameters builds a service type description from the parameters of an API method
func (b *OpenAPI3Builder) buildTypeFromParameters(
name string,
parameters []*openapiv3.ParameterOrReference,
requestBody *openapiv3.RequestBodyOrReference) (typeName string, err error) {
t := &Type{}
t.Name = name + "Parameters"
t.Description = t.Name + " holds parameters to " + name
t.Kind = TypeKind_STRUCT
t.Fields = make([]*Field, 0)
for _, parametersItem := range parameters {
var f Field
f.Type = fmt.Sprintf("%+v", parametersItem)
parameter := parametersItem.GetParameter()
if parameter != nil {
switch parameter.In {
case "body":
f.Position = Position_BODY
case "header":
f.Position = Position_HEADER
case "formdata":
f.Position = Position_FORMDATA
case "query":
f.Position = Position_QUERY
case "path":
f.Position = Position_PATH
}
f.Name = parameter.Name
if parameter.GetSchema() != nil && parameter.GetSchema() != nil {
f.Kind, f.Type, f.Format = b.typeForSchemaOrReference(parameter.GetSchema())
}
f.Serialize = true
t.addField(&f)
}
}
if requestBody != nil {
content := requestBody.GetRequestBody().GetContent()
if content != nil {
for _, pair2 := range content.GetAdditionalProperties() {
var f Field
f.Position = Position_BODY
f.Kind, f.Type, f.Format = b.typeForSchemaOrReference(pair2.GetValue().GetSchema())
f.Name = strings.ToLower(f.Type) // use the schema name as the parameter name, since none is directly specified
f.Serialize = true
t.addField(&f)
}
}
}
if len(t.Fields) > 0 {
b.model.addType(t)
return t.Name, err
}
return "", err
}
// buildTypeFromResponses builds a service type description from the responses of an API method
func (b *OpenAPI3Builder) buildTypeFromResponses(
m *Method,
name string,
responses *openapiv3.Responses) (typeName string, err error) {
t := &Type{}
t.Name = name + "Responses"
t.Description = t.Name + " holds responses of " + name
t.Kind = TypeKind_STRUCT
t.Fields = make([]*Field, 0)
addResponse := func(name string, value *openapiv3.ResponseOrReference) {
var f Field
f.Name = name
f.Serialize = false
response := value.GetResponse()
if response != nil && response.GetContent() != nil {
for _, pair2 := range response.GetContent().GetAdditionalProperties() {
f.Kind, f.Type, f.Format = b.typeForSchemaOrReference(pair2.GetValue().GetSchema())
f.Kind = FieldKind_REFERENCE
t.addField(&f)
}
}
}
for _, pair := range responses.ResponseOrReference {
addResponse(pair.Name, pair.Value)
}
if responses.Default != nil {
addResponse("default", responses.Default)
}
if len(t.Fields) > 0 {
b.model.addType(t)
return t.Name, err
}
return "", err
}
// typeForSchemaOrReference determines the language-specific type of a schema or reference
func (b *OpenAPI3Builder) typeForSchemaOrReference(value *openapiv3.SchemaOrReference) (kind FieldKind, typeName, format string) {
if value.GetSchema() != nil {
return b.typeForSchema(value.GetSchema())
}
if value.GetReference() != nil {
return FieldKind_SCALAR, typeForRef(value.GetReference().XRef), ""
}
return FieldKind_SCALAR, "todo", ""
}
// typeForSchema determines the language-specific type of a schema
func (b *OpenAPI3Builder) typeForSchema(schema *openapiv3.Schema) (kind FieldKind, typeName, format string) {
if schema.Type != "" {
format := schema.Format
switch schema.Type {
case "string":
return FieldKind_SCALAR, "string", format
case "integer":
return FieldKind_SCALAR, "integer", format
case "number":
return FieldKind_SCALAR, "number", format
case "boolean":
return FieldKind_SCALAR, "boolean", format
case "array":
if schema.Items != nil {
// we have an array.., but of what?
items := schema.Items.SchemaOrReference
if len(items) == 1 {
if items[0].GetReference().GetXRef() != "" {
return FieldKind_ARRAY, typeForRef(items[0].GetReference().GetXRef()), format
} else if items[0].GetSchema().Type == "string" {
return FieldKind_ARRAY, "string", format
} else if items[0].GetSchema().Type == "object" {
return FieldKind_ARRAY, "interface{}", format
}
}
}
case "object":
if schema.AdditionalProperties == nil {
return FieldKind_MAP, "object", format
}
default:
}
}
if schema.AdditionalProperties != nil {
additionalProperties := schema.AdditionalProperties
if propertySchema := additionalProperties.GetSchemaOrReference().GetReference(); propertySchema != nil {
if ref := propertySchema.XRef; ref != "" {
return FieldKind_MAP, "map[string]" + typeForRef(ref), ""
}
}
}
// this function is incomplete... return a string representing anything that we don't handle
log.Printf("unimplemented: %v", schema)
return FieldKind_SCALAR, fmt.Sprintf("unimplemented: %v", schema), ""
}

View File

@ -0,0 +1,424 @@
// Code generated by protoc-gen-go.
// source: surface.proto
// DO NOT EDIT!
/*
Package surface_v1 is a generated protocol buffer package.
It is generated from these files:
surface.proto
It has these top-level messages:
Field
Type
Method
Model
*/
package surface_v1
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type FieldKind int32
const (
FieldKind_SCALAR FieldKind = 0
FieldKind_MAP FieldKind = 1
FieldKind_ARRAY FieldKind = 2
FieldKind_REFERENCE FieldKind = 3
)
var FieldKind_name = map[int32]string{
0: "SCALAR",
1: "MAP",
2: "ARRAY",
3: "REFERENCE",
}
var FieldKind_value = map[string]int32{
"SCALAR": 0,
"MAP": 1,
"ARRAY": 2,
"REFERENCE": 3,
}
func (x FieldKind) String() string {
return proto.EnumName(FieldKind_name, int32(x))
}
func (FieldKind) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type TypeKind int32
const (
TypeKind_STRUCT TypeKind = 0
TypeKind_OBJECT TypeKind = 1
)
var TypeKind_name = map[int32]string{
0: "STRUCT",
1: "OBJECT",
}
var TypeKind_value = map[string]int32{
"STRUCT": 0,
"OBJECT": 1,
}
func (x TypeKind) String() string {
return proto.EnumName(TypeKind_name, int32(x))
}
func (TypeKind) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
type Position int32
const (
Position_BODY Position = 0
Position_HEADER Position = 1
Position_FORMDATA Position = 2
Position_QUERY Position = 3
Position_PATH Position = 4
)
var Position_name = map[int32]string{
0: "BODY",
1: "HEADER",
2: "FORMDATA",
3: "QUERY",
4: "PATH",
}
var Position_value = map[string]int32{
"BODY": 0,
"HEADER": 1,
"FORMDATA": 2,
"QUERY": 3,
"PATH": 4,
}
func (x Position) String() string {
return proto.EnumName(Position_name, int32(x))
}
func (Position) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
// Field is a field in a definition and can be associated with
// a position in a request structure.
type Field struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Type string `protobuf:"bytes,2,opt,name=type" json:"type,omitempty"`
Kind FieldKind `protobuf:"varint,3,opt,name=kind,enum=surface.v1.FieldKind" json:"kind,omitempty"`
Format string `protobuf:"bytes,4,opt,name=format" json:"format,omitempty"`
Position Position `protobuf:"varint,5,opt,name=position,enum=surface.v1.Position" json:"position,omitempty"`
NativeType string `protobuf:"bytes,6,opt,name=nativeType" json:"nativeType,omitempty"`
FieldName string `protobuf:"bytes,7,opt,name=fieldName" json:"fieldName,omitempty"`
ParameterName string `protobuf:"bytes,8,opt,name=parameterName" json:"parameterName,omitempty"`
Serialize bool `protobuf:"varint,9,opt,name=serialize" json:"serialize,omitempty"`
}
func (m *Field) Reset() { *m = Field{} }
func (m *Field) String() string { return proto.CompactTextString(m) }
func (*Field) ProtoMessage() {}
func (*Field) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Field) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Field) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *Field) GetKind() FieldKind {
if m != nil {
return m.Kind
}
return FieldKind_SCALAR
}
func (m *Field) GetFormat() string {
if m != nil {
return m.Format
}
return ""
}
func (m *Field) GetPosition() Position {
if m != nil {
return m.Position
}
return Position_BODY
}
func (m *Field) GetNativeType() string {
if m != nil {
return m.NativeType
}
return ""
}
func (m *Field) GetFieldName() string {
if m != nil {
return m.FieldName
}
return ""
}
func (m *Field) GetParameterName() string {
if m != nil {
return m.ParameterName
}
return ""
}
func (m *Field) GetSerialize() bool {
if m != nil {
return m.Serialize
}
return false
}
// Type typically corresponds to a definition, parameter, or response
// in an API and is represented by a type in generated code.
type Type struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Kind TypeKind `protobuf:"varint,2,opt,name=kind,enum=surface.v1.TypeKind" json:"kind,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description" json:"description,omitempty"`
ContentType string `protobuf:"bytes,4,opt,name=contentType" json:"contentType,omitempty"`
Fields []*Field `protobuf:"bytes,5,rep,name=fields" json:"fields,omitempty"`
TypeName string `protobuf:"bytes,6,opt,name=typeName" json:"typeName,omitempty"`
}
func (m *Type) Reset() { *m = Type{} }
func (m *Type) String() string { return proto.CompactTextString(m) }
func (*Type) ProtoMessage() {}
func (*Type) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Type) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Type) GetKind() TypeKind {
if m != nil {
return m.Kind
}
return TypeKind_STRUCT
}
func (m *Type) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *Type) GetContentType() string {
if m != nil {
return m.ContentType
}
return ""
}
func (m *Type) GetFields() []*Field {
if m != nil {
return m.Fields
}
return nil
}
func (m *Type) GetTypeName() string {
if m != nil {
return m.TypeName
}
return ""
}
// Method is an operation of an API and typically has associated client and server code.
type Method struct {
Operation string `protobuf:"bytes,1,opt,name=operation" json:"operation,omitempty"`
Path string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"`
Method string `protobuf:"bytes,3,opt,name=method" json:"method,omitempty"`
Description string `protobuf:"bytes,4,opt,name=description" json:"description,omitempty"`
Name string `protobuf:"bytes,5,opt,name=name" json:"name,omitempty"`
HandlerName string `protobuf:"bytes,6,opt,name=handlerName" json:"handlerName,omitempty"`
ProcessorName string `protobuf:"bytes,7,opt,name=processorName" json:"processorName,omitempty"`
ClientName string `protobuf:"bytes,8,opt,name=clientName" json:"clientName,omitempty"`
ParametersTypeName string `protobuf:"bytes,9,opt,name=parametersTypeName" json:"parametersTypeName,omitempty"`
ResponsesTypeName string `protobuf:"bytes,10,opt,name=responsesTypeName" json:"responsesTypeName,omitempty"`
}
func (m *Method) Reset() { *m = Method{} }
func (m *Method) String() string { return proto.CompactTextString(m) }
func (*Method) ProtoMessage() {}
func (*Method) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *Method) GetOperation() string {
if m != nil {
return m.Operation
}
return ""
}
func (m *Method) GetPath() string {
if m != nil {
return m.Path
}
return ""
}
func (m *Method) GetMethod() string {
if m != nil {
return m.Method
}
return ""
}
func (m *Method) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *Method) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Method) GetHandlerName() string {
if m != nil {
return m.HandlerName
}
return ""
}
func (m *Method) GetProcessorName() string {
if m != nil {
return m.ProcessorName
}
return ""
}
func (m *Method) GetClientName() string {
if m != nil {
return m.ClientName
}
return ""
}
func (m *Method) GetParametersTypeName() string {
if m != nil {
return m.ParametersTypeName
}
return ""
}
func (m *Method) GetResponsesTypeName() string {
if m != nil {
return m.ResponsesTypeName
}
return ""
}
// Model represents an API for code generation.
type Model struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Types []*Type `protobuf:"bytes,2,rep,name=types" json:"types,omitempty"`
Methods []*Method `protobuf:"bytes,3,rep,name=methods" json:"methods,omitempty"`
}
func (m *Model) Reset() { *m = Model{} }
func (m *Model) String() string { return proto.CompactTextString(m) }
func (*Model) ProtoMessage() {}
func (*Model) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *Model) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Model) GetTypes() []*Type {
if m != nil {
return m.Types
}
return nil
}
func (m *Model) GetMethods() []*Method {
if m != nil {
return m.Methods
}
return nil
}
func init() {
proto.RegisterType((*Field)(nil), "surface.v1.Field")
proto.RegisterType((*Type)(nil), "surface.v1.Type")
proto.RegisterType((*Method)(nil), "surface.v1.Method")
proto.RegisterType((*Model)(nil), "surface.v1.Model")
proto.RegisterEnum("surface.v1.FieldKind", FieldKind_name, FieldKind_value)
proto.RegisterEnum("surface.v1.TypeKind", TypeKind_name, TypeKind_value)
proto.RegisterEnum("surface.v1.Position", Position_name, Position_value)
}
func init() { proto.RegisterFile("surface.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 573 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x54, 0x5f, 0x6f, 0xd3, 0x3e,
0x14, 0x5d, 0xfe, 0x36, 0xb9, 0xfd, 0xf5, 0xa7, 0xcc, 0x02, 0x14, 0x21, 0x84, 0xa2, 0x0a, 0xa1,
0xae, 0x9a, 0x2a, 0x18, 0x6f, 0xbc, 0x65, 0x6d, 0xaa, 0x09, 0xe8, 0x5a, 0x4c, 0xf6, 0xd0, 0xc7,
0xd0, 0xb8, 0x6a, 0x44, 0x1b, 0x87, 0x38, 0x4c, 0x82, 0x0f, 0xc4, 0xc7, 0x81, 0xaf, 0x84, 0x7c,
0x93, 0xb4, 0xde, 0xda, 0x37, 0xfb, 0xdc, 0xe3, 0x6b, 0x9f, 0x73, 0x6e, 0x02, 0x3d, 0xf1, 0xa3,
0x5c, 0x27, 0x2b, 0x36, 0x2a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04, 0xc0, 0xfe, 0x32, 0x0e, 0x3f, 0x85, 0xd4, 0x3b, 0x23, 0x1d,
0x30, 0x66, 0xe1, 0xc2, 0xd3, 0x88, 0x0b, 0x56, 0x48, 0x69, 0xb8, 0xf4, 0x74, 0xd2, 0x03, 0x97,
0x46, 0xd3, 0x88, 0x46, 0xb7, 0xe3, 0xc8, 0x33, 0x86, 0x7d, 0x70, 0xda, 0xe1, 0xc4, 0xa3, 0x31,
0xbd, 0x1b, 0xc7, 0xde, 0x99, 0x5c, 0xcf, 0xaf, 0x3f, 0x44, 0xe3, 0xd8, 0xd3, 0x86, 0x63, 0x70,
0xda, 0xaf, 0x91, 0x38, 0x60, 0x5e, 0xcf, 0x27, 0xcb, 0x9a, 0x71, 0x13, 0x85, 0x93, 0x88, 0x7a,
0x1a, 0xf9, 0x0f, 0x9c, 0xe9, 0x9c, 0xce, 0x26, 0x61, 0x1c, 0x7a, 0xba, 0xbc, 0xed, 0xf3, 0x5d,
0x44, 0x97, 0x9e, 0x21, 0xe9, 0x8b, 0x30, 0xbe, 0xf1, 0xcc, 0xaf, 0x36, 0xfe, 0x76, 0xde, 0xfd,
0x0b, 0x00, 0x00, 0xff, 0xff, 0x15, 0x52, 0x6a, 0x89, 0x87, 0x04, 0x00, 0x00,
}

View File

@ -0,0 +1,90 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Model an API surface for code generation.
syntax = "proto3";
package surface.v1;
enum FieldKind {
SCALAR = 0;
MAP = 1;
ARRAY = 2;
REFERENCE = 3;
}
enum TypeKind {
STRUCT = 0; // implement with named fields
OBJECT = 1; // implement with a map
}
enum Position {
BODY = 0;
HEADER = 1;
FORMDATA = 2;
QUERY = 3;
PATH = 4;
}
// Field is a field in a definition and can be associated with
// a position in a request structure.
message Field {
string name = 1; // the name as specified in the API description
string type = 2; // the specified content type of the field
FieldKind kind = 3; // what kind of thing is this field? scalar, reference, array, map of strings to the specified type
string format = 4; // the specified format of the field
Position position = 5; // "body", "header", "formdata", "query", or "path"
string nativeType = 6; // the programming-language native type of the field
string fieldName = 7; // the name to use for a data structure field
string parameterName = 8; // the name to use for a function parameter
bool serialize = 9; // true if this field should be serialized (to JSON, etc)
}
// Type typically corresponds to a definition, parameter, or response
// in an API and is represented by a type in generated code.
message Type {
string name = 1; // the name to use for the type
TypeKind kind = 2; // a meta-description of the type (struct, map, etc)
string description = 3; // a comment describing the type
string contentType = 4; // if the type is a map, this is its content type
repeated Field fields = 5; // the fields of the type
string typeName = 6; // language-specific type name
}
// Method is an operation of an API and typically has associated client and server code.
message Method {
string operation = 1; // Operation ID
string path = 2; // HTTP path
string method = 3; // HTTP method name
string description = 4; // description of method
string name = 5; // Operation name, possibly generated from method and path
string handlerName = 6; // name of the generated handler
string processorName = 7; // name of the processing function in the service interface
string clientName = 8; // name of client
string parametersTypeName = 9; // parameters (input), with fields corresponding to input parameters
string responsesTypeName = 10; // responses (output), with fields corresponding to possible response values
}
// Model represents an API for code generation.
message Model {
string name = 1; // a free-form title for the API
repeated Type types = 2; // the types used by the API
repeated Method methods = 3; // the methods (functions) of the API
}

51
vendor/github.com/googleapis/gnostic/surface/type.go generated vendored Normal file
View File

@ -0,0 +1,51 @@
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package surface_v1
func (t *Type) addField(f *Field) {
t.Fields = append(t.Fields, f)
}
func (s *Type) HasFieldWithName(name string) bool {
return s.FieldWithName(name) != nil
}
func (s *Type) FieldWithName(name string) *Field {
if s == nil || s.Fields == nil || name == "" {
return nil
}
for _, f := range s.Fields {
if f.FieldName == name {
return f
}
}
return nil
}
func (s *Type) HasFieldWithPosition(position Position) bool {
return s.FieldWithPosition(position) != nil
}
func (s *Type) FieldWithPosition(position Position) *Field {
if s == nil || s.Fields == nil {
return nil
}
for _, f := range s.Fields {
if f.Position == position {
return f
}
}
return nil
}