id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
18,500
graph-gophers/dataloader
trace.go
TraceLoad
func (NoopTracer) TraceLoad(ctx context.Context, key Key) (context.Context, TraceLoadFinishFunc) { return ctx, func(Thunk) {} }
go
func (NoopTracer) TraceLoad(ctx context.Context, key Key) (context.Context, TraceLoadFinishFunc) { return ctx, func(Thunk) {} }
[ "func", "(", "NoopTracer", ")", "TraceLoad", "(", "ctx", "context", ".", "Context", ",", "key", "Key", ")", "(", "context", ".", "Context", ",", "TraceLoadFinishFunc", ")", "{", "return", "ctx", ",", "func", "(", "Thunk", ")", "{", "}", "\n", "}" ]
// TraceLoad is a noop function
[ "TraceLoad", "is", "a", "noop", "function" ]
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L66-L68
18,501
graph-gophers/dataloader
trace.go
TraceLoadMany
func (NoopTracer) TraceLoadMany(ctx context.Context, keys Keys) (context.Context, TraceLoadManyFinishFunc) { return ctx, func(ThunkMany) {} }
go
func (NoopTracer) TraceLoadMany(ctx context.Context, keys Keys) (context.Context, TraceLoadManyFinishFunc) { return ctx, func(ThunkMany) {} }
[ "func", "(", "NoopTracer", ")", "TraceLoadMany", "(", "ctx", "context", ".", "Context", ",", "keys", "Keys", ")", "(", "context", ".", "Context", ",", "TraceLoadManyFinishFunc", ")", "{", "return", "ctx", ",", "func", "(", "ThunkMany", ")", "{", "}", "\n", "}" ]
// TraceLoadMany is a noop function
[ "TraceLoadMany", "is", "a", "noop", "function" ]
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L71-L73
18,502
graph-gophers/dataloader
trace.go
TraceBatch
func (NoopTracer) TraceBatch(ctx context.Context, keys Keys) (context.Context, TraceBatchFinishFunc) { return ctx, func(result []*Result) {} }
go
func (NoopTracer) TraceBatch(ctx context.Context, keys Keys) (context.Context, TraceBatchFinishFunc) { return ctx, func(result []*Result) {} }
[ "func", "(", "NoopTracer", ")", "TraceBatch", "(", "ctx", "context", ".", "Context", ",", "keys", "Keys", ")", "(", "context", ".", "Context", ",", "TraceBatchFinishFunc", ")", "{", "return", "ctx", ",", "func", "(", "result", "[", "]", "*", "Result", ")", "{", "}", "\n", "}" ]
// TraceBatch is a noop function
[ "TraceBatch", "is", "a", "noop", "function" ]
1232fe340ae7c1ca82f7b43eb35dd7ced94aa085
https://github.com/graph-gophers/dataloader/blob/1232fe340ae7c1ca82f7b43eb35dd7ced94aa085/trace.go#L76-L78
18,503
googleapis/gnostic
plugins/gnostic-go-generator/main.go
main
func main() { env, err := plugins.NewEnvironment() env.RespondAndExitIfError(err) packageName, err := resolvePackageName(env.Request.OutputPath) env.RespondAndExitIfError(err) // Use the name used to run the plugin to decide which files to generate. var files []string switch { case strings.Contains(env.Invocation, "gnostic-go-client"): files = []string{"client.go", "types.go", "constants.go"} case strings.Contains(env.Invocation, "gnostic-go-server"): files = []string{"server.go", "provider.go", "types.go", "constants.go"} default: files = []string{"client.go", "server.go", "provider.go", "types.go", "constants.go"} } for _, model := range env.Request.Models { switch model.TypeUrl { case "surface.v1.Model": surfaceModel := &surface.Model{} err = proto.Unmarshal(model.Value, surfaceModel) if err == nil { // Customize the code surface model for Go NewGoLanguageModel().Prepare(surfaceModel) modelJSON, _ := json.MarshalIndent(surfaceModel, "", " ") modelFile := &plugins.File{Name: "model.json", Data: modelJSON} env.Response.Files = append(env.Response.Files, modelFile) // Create the renderer. renderer, err := NewServiceRenderer(surfaceModel) renderer.Package = packageName env.RespondAndExitIfError(err) // Run the renderer to generate files and add them to the response object. err = renderer.Render(env.Response, files) env.RespondAndExitIfError(err) // Return with success. env.RespondAndExit() } } } err = errors.New("No generated code surface model is available.") env.RespondAndExitIfError(err) }
go
func main() { env, err := plugins.NewEnvironment() env.RespondAndExitIfError(err) packageName, err := resolvePackageName(env.Request.OutputPath) env.RespondAndExitIfError(err) // Use the name used to run the plugin to decide which files to generate. var files []string switch { case strings.Contains(env.Invocation, "gnostic-go-client"): files = []string{"client.go", "types.go", "constants.go"} case strings.Contains(env.Invocation, "gnostic-go-server"): files = []string{"server.go", "provider.go", "types.go", "constants.go"} default: files = []string{"client.go", "server.go", "provider.go", "types.go", "constants.go"} } for _, model := range env.Request.Models { switch model.TypeUrl { case "surface.v1.Model": surfaceModel := &surface.Model{} err = proto.Unmarshal(model.Value, surfaceModel) if err == nil { // Customize the code surface model for Go NewGoLanguageModel().Prepare(surfaceModel) modelJSON, _ := json.MarshalIndent(surfaceModel, "", " ") modelFile := &plugins.File{Name: "model.json", Data: modelJSON} env.Response.Files = append(env.Response.Files, modelFile) // Create the renderer. renderer, err := NewServiceRenderer(surfaceModel) renderer.Package = packageName env.RespondAndExitIfError(err) // Run the renderer to generate files and add them to the response object. err = renderer.Render(env.Response, files) env.RespondAndExitIfError(err) // Return with success. env.RespondAndExit() } } } err = errors.New("No generated code surface model is available.") env.RespondAndExitIfError(err) }
[ "func", "main", "(", ")", "{", "env", ",", "err", ":=", "plugins", ".", "NewEnvironment", "(", ")", "\n", "env", ".", "RespondAndExitIfError", "(", "err", ")", "\n\n", "packageName", ",", "err", ":=", "resolvePackageName", "(", "env", ".", "Request", ".", "OutputPath", ")", "\n", "env", ".", "RespondAndExitIfError", "(", "err", ")", "\n\n", "// Use the name used to run the plugin to decide which files to generate.", "var", "files", "[", "]", "string", "\n", "switch", "{", "case", "strings", ".", "Contains", "(", "env", ".", "Invocation", ",", "\"", "\"", ")", ":", "files", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "case", "strings", ".", "Contains", "(", "env", ".", "Invocation", ",", "\"", "\"", ")", ":", "files", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "default", ":", "files", "=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "}", "\n\n", "for", "_", ",", "model", ":=", "range", "env", ".", "Request", ".", "Models", "{", "switch", "model", ".", "TypeUrl", "{", "case", "\"", "\"", ":", "surfaceModel", ":=", "&", "surface", ".", "Model", "{", "}", "\n", "err", "=", "proto", ".", "Unmarshal", "(", "model", ".", "Value", ",", "surfaceModel", ")", "\n", "if", "err", "==", "nil", "{", "// Customize the code surface model for Go", "NewGoLanguageModel", "(", ")", ".", "Prepare", "(", "surfaceModel", ")", "\n\n", "modelJSON", ",", "_", ":=", "json", ".", "MarshalIndent", "(", "surfaceModel", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "modelFile", ":=", "&", "plugins", ".", "File", "{", "Name", ":", "\"", "\"", ",", "Data", ":", "modelJSON", "}", "\n", "env", ".", "Response", ".", "Files", "=", "append", "(", "env", ".", "Response", ".", "Files", ",", "modelFile", ")", "\n\n", "// Create the renderer.", "renderer", ",", "err", ":=", "NewServiceRenderer", "(", "surfaceModel", ")", "\n", "renderer", ".", "Package", "=", "packageName", "\n", "env", ".", "RespondAndExitIfError", "(", "err", ")", "\n\n", "// Run the renderer to generate files and add them to the response object.", "err", "=", "renderer", ".", "Render", "(", "env", ".", "Response", ",", "files", ")", "\n", "env", ".", "RespondAndExitIfError", "(", "err", ")", "\n\n", "// Return with success.", "env", ".", "RespondAndExit", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "env", ".", "RespondAndExitIfError", "(", "err", ")", "\n", "}" ]
// This is the main function for the code generation plugin.
[ "This", "is", "the", "main", "function", "for", "the", "code", "generation", "plugin", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/plugins/gnostic-go-generator/main.go#L32-L79
18,504
googleapis/gnostic
plugins/gnostic-go-generator/main.go
resolvePackageName
func resolvePackageName(p string) (string, error) { p, err := filepath.Abs(p) if err == nil { p = filepath.Base(p) _, err = format.Source([]byte("package " + p)) } if err != nil { return "", errors.New("invalid package name " + p) } return p, nil }
go
func resolvePackageName(p string) (string, error) { p, err := filepath.Abs(p) if err == nil { p = filepath.Base(p) _, err = format.Source([]byte("package " + p)) } if err != nil { return "", errors.New("invalid package name " + p) } return p, nil }
[ "func", "resolvePackageName", "(", "p", "string", ")", "(", "string", ",", "error", ")", "{", "p", ",", "err", ":=", "filepath", ".", "Abs", "(", "p", ")", "\n", "if", "err", "==", "nil", "{", "p", "=", "filepath", ".", "Base", "(", "p", ")", "\n", "_", ",", "err", "=", "format", ".", "Source", "(", "[", "]", "byte", "(", "\"", "\"", "+", "p", ")", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", "+", "p", ")", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// resolvePackageName converts a path to a valid package name or // error if path can't be resolved or resolves to an invalid package name.
[ "resolvePackageName", "converts", "a", "path", "to", "a", "valid", "package", "name", "or", "error", "if", "path", "can", "t", "be", "resolved", "or", "resolves", "to", "an", "invalid", "package", "name", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/plugins/gnostic-go-generator/main.go#L83-L93
18,505
googleapis/gnostic
printer/code.go
Print
func (c *Code) Print(args ...interface{}) { if len(args) > 0 { for i := 0; i < c.indent; i++ { c.text += indentation } c.text += fmt.Sprintf(args[0].(string), args[1:]...) } c.text += "\n" }
go
func (c *Code) Print(args ...interface{}) { if len(args) > 0 { for i := 0; i < c.indent; i++ { c.text += indentation } c.text += fmt.Sprintf(args[0].(string), args[1:]...) } c.text += "\n" }
[ "func", "(", "c", "*", "Code", ")", "Print", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "len", "(", "args", ")", ">", "0", "{", "for", "i", ":=", "0", ";", "i", "<", "c", ".", "indent", ";", "i", "++", "{", "c", ".", "text", "+=", "indentation", "\n", "}", "\n", "c", ".", "text", "+=", "fmt", ".", "Sprintf", "(", "args", "[", "0", "]", ".", "(", "string", ")", ",", "args", "[", "1", ":", "]", "...", ")", "\n", "}", "\n", "c", ".", "text", "+=", "\"", "\\n", "\"", "\n", "}" ]
// Print adds a line of code using the current indentation. Accepts printf-style format strings and arguments.
[ "Print", "adds", "a", "line", "of", "code", "using", "the", "current", "indentation", ".", "Accepts", "printf", "-", "style", "format", "strings", "and", "arguments", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/printer/code.go#L31-L39
18,506
googleapis/gnostic
printer/code.go
PrintIf
func (c *Code) PrintIf(condition bool, args ...interface{}) { if !condition { return } if len(args) > 0 { for i := 0; i < c.indent; i++ { c.text += indentation } c.text += fmt.Sprintf(args[0].(string), args[1:]...) } c.text += "\n" }
go
func (c *Code) PrintIf(condition bool, args ...interface{}) { if !condition { return } if len(args) > 0 { for i := 0; i < c.indent; i++ { c.text += indentation } c.text += fmt.Sprintf(args[0].(string), args[1:]...) } c.text += "\n" }
[ "func", "(", "c", "*", "Code", ")", "PrintIf", "(", "condition", "bool", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "!", "condition", "{", "return", "\n", "}", "\n", "if", "len", "(", "args", ")", ">", "0", "{", "for", "i", ":=", "0", ";", "i", "<", "c", ".", "indent", ";", "i", "++", "{", "c", ".", "text", "+=", "indentation", "\n", "}", "\n", "c", ".", "text", "+=", "fmt", ".", "Sprintf", "(", "args", "[", "0", "]", ".", "(", "string", ")", ",", "args", "[", "1", ":", "]", "...", ")", "\n", "}", "\n", "c", ".", "text", "+=", "\"", "\\n", "\"", "\n", "}" ]
// PrintIf adds a line of code using the current indentation if a condition is true. Accepts printf-style format strings and arguments.
[ "PrintIf", "adds", "a", "line", "of", "code", "using", "the", "current", "indentation", "if", "a", "condition", "is", "true", ".", "Accepts", "printf", "-", "style", "format", "strings", "and", "arguments", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/printer/code.go#L42-L53
18,507
googleapis/gnostic
jsonschema/operations.go
IsEmpty
func (schema *Schema) IsEmpty() bool { return (schema.Schema == nil) && (schema.ID == nil) && (schema.MultipleOf == nil) && (schema.Maximum == nil) && (schema.ExclusiveMaximum == nil) && (schema.Minimum == nil) && (schema.ExclusiveMinimum == nil) && (schema.MaxLength == nil) && (schema.MinLength == nil) && (schema.Pattern == nil) && (schema.AdditionalItems == nil) && (schema.Items == nil) && (schema.MaxItems == nil) && (schema.MinItems == nil) && (schema.UniqueItems == nil) && (schema.MaxProperties == nil) && (schema.MinProperties == nil) && (schema.Required == nil) && (schema.AdditionalProperties == nil) && (schema.Properties == nil) && (schema.PatternProperties == nil) && (schema.Dependencies == nil) && (schema.Enumeration == nil) && (schema.Type == nil) && (schema.AllOf == nil) && (schema.AnyOf == nil) && (schema.OneOf == nil) && (schema.Not == nil) && (schema.Definitions == nil) && (schema.Title == nil) && (schema.Description == nil) && (schema.Default == nil) && (schema.Format == nil) && (schema.Ref == nil) }
go
func (schema *Schema) IsEmpty() bool { return (schema.Schema == nil) && (schema.ID == nil) && (schema.MultipleOf == nil) && (schema.Maximum == nil) && (schema.ExclusiveMaximum == nil) && (schema.Minimum == nil) && (schema.ExclusiveMinimum == nil) && (schema.MaxLength == nil) && (schema.MinLength == nil) && (schema.Pattern == nil) && (schema.AdditionalItems == nil) && (schema.Items == nil) && (schema.MaxItems == nil) && (schema.MinItems == nil) && (schema.UniqueItems == nil) && (schema.MaxProperties == nil) && (schema.MinProperties == nil) && (schema.Required == nil) && (schema.AdditionalProperties == nil) && (schema.Properties == nil) && (schema.PatternProperties == nil) && (schema.Dependencies == nil) && (schema.Enumeration == nil) && (schema.Type == nil) && (schema.AllOf == nil) && (schema.AnyOf == nil) && (schema.OneOf == nil) && (schema.Not == nil) && (schema.Definitions == nil) && (schema.Title == nil) && (schema.Description == nil) && (schema.Default == nil) && (schema.Format == nil) && (schema.Ref == nil) }
[ "func", "(", "schema", "*", "Schema", ")", "IsEmpty", "(", ")", "bool", "{", "return", "(", "schema", ".", "Schema", "==", "nil", ")", "&&", "(", "schema", ".", "ID", "==", "nil", ")", "&&", "(", "schema", ".", "MultipleOf", "==", "nil", ")", "&&", "(", "schema", ".", "Maximum", "==", "nil", ")", "&&", "(", "schema", ".", "ExclusiveMaximum", "==", "nil", ")", "&&", "(", "schema", ".", "Minimum", "==", "nil", ")", "&&", "(", "schema", ".", "ExclusiveMinimum", "==", "nil", ")", "&&", "(", "schema", ".", "MaxLength", "==", "nil", ")", "&&", "(", "schema", ".", "MinLength", "==", "nil", ")", "&&", "(", "schema", ".", "Pattern", "==", "nil", ")", "&&", "(", "schema", ".", "AdditionalItems", "==", "nil", ")", "&&", "(", "schema", ".", "Items", "==", "nil", ")", "&&", "(", "schema", ".", "MaxItems", "==", "nil", ")", "&&", "(", "schema", ".", "MinItems", "==", "nil", ")", "&&", "(", "schema", ".", "UniqueItems", "==", "nil", ")", "&&", "(", "schema", ".", "MaxProperties", "==", "nil", ")", "&&", "(", "schema", ".", "MinProperties", "==", "nil", ")", "&&", "(", "schema", ".", "Required", "==", "nil", ")", "&&", "(", "schema", ".", "AdditionalProperties", "==", "nil", ")", "&&", "(", "schema", ".", "Properties", "==", "nil", ")", "&&", "(", "schema", ".", "PatternProperties", "==", "nil", ")", "&&", "(", "schema", ".", "Dependencies", "==", "nil", ")", "&&", "(", "schema", ".", "Enumeration", "==", "nil", ")", "&&", "(", "schema", ".", "Type", "==", "nil", ")", "&&", "(", "schema", ".", "AllOf", "==", "nil", ")", "&&", "(", "schema", ".", "AnyOf", "==", "nil", ")", "&&", "(", "schema", ".", "OneOf", "==", "nil", ")", "&&", "(", "schema", ".", "Not", "==", "nil", ")", "&&", "(", "schema", ".", "Definitions", "==", "nil", ")", "&&", "(", "schema", ".", "Title", "==", "nil", ")", "&&", "(", "schema", ".", "Description", "==", "nil", ")", "&&", "(", "schema", ".", "Default", "==", "nil", ")", "&&", "(", "schema", ".", "Format", "==", "nil", ")", "&&", "(", "schema", ".", "Ref", "==", "nil", ")", "\n", "}" ]
// // OPERATIONS // The following methods perform operations on Schemas. // // IsEmpty returns true if no members of the Schema are specified.
[ "OPERATIONS", "The", "following", "methods", "perform", "operations", "on", "Schemas", ".", "IsEmpty", "returns", "true", "if", "no", "members", "of", "the", "Schema", "are", "specified", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L29-L64
18,508
googleapis/gnostic
jsonschema/operations.go
IsEqual
func (schema *Schema) IsEqual(schema2 *Schema) bool { return schema.String() == schema2.String() }
go
func (schema *Schema) IsEqual(schema2 *Schema) bool { return schema.String() == schema2.String() }
[ "func", "(", "schema", "*", "Schema", ")", "IsEqual", "(", "schema2", "*", "Schema", ")", "bool", "{", "return", "schema", ".", "String", "(", ")", "==", "schema2", ".", "String", "(", ")", "\n", "}" ]
// IsEqual returns true if two schemas are equal.
[ "IsEqual", "returns", "true", "if", "two", "schemas", "are", "equal", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L67-L69
18,509
googleapis/gnostic
jsonschema/operations.go
applyToSchemas
func (schema *Schema) applyToSchemas(operation SchemaOperation, context string) { if schema.AdditionalItems != nil { s := schema.AdditionalItems.Schema if s != nil { s.applyToSchemas(operation, "AdditionalItems") } } if schema.Items != nil { if schema.Items.SchemaArray != nil { for _, s := range *(schema.Items.SchemaArray) { s.applyToSchemas(operation, "Items.SchemaArray") } } else if schema.Items.Schema != nil { schema.Items.Schema.applyToSchemas(operation, "Items.Schema") } } if schema.AdditionalProperties != nil { s := schema.AdditionalProperties.Schema if s != nil { s.applyToSchemas(operation, "AdditionalProperties") } } if schema.Properties != nil { for _, pair := range *(schema.Properties) { s := pair.Value s.applyToSchemas(operation, "Properties") } } if schema.PatternProperties != nil { for _, pair := range *(schema.PatternProperties) { s := pair.Value s.applyToSchemas(operation, "PatternProperties") } } if schema.Dependencies != nil { for _, pair := range *(schema.Dependencies) { schemaOrStringArray := pair.Value s := schemaOrStringArray.Schema if s != nil { s.applyToSchemas(operation, "Dependencies") } } } if schema.AllOf != nil { for _, s := range *(schema.AllOf) { s.applyToSchemas(operation, "AllOf") } } if schema.AnyOf != nil { for _, s := range *(schema.AnyOf) { s.applyToSchemas(operation, "AnyOf") } } if schema.OneOf != nil { for _, s := range *(schema.OneOf) { s.applyToSchemas(operation, "OneOf") } } if schema.Not != nil { schema.Not.applyToSchemas(operation, "Not") } if schema.Definitions != nil { for _, pair := range *(schema.Definitions) { s := pair.Value s.applyToSchemas(operation, "Definitions") } } operation(schema, context) }
go
func (schema *Schema) applyToSchemas(operation SchemaOperation, context string) { if schema.AdditionalItems != nil { s := schema.AdditionalItems.Schema if s != nil { s.applyToSchemas(operation, "AdditionalItems") } } if schema.Items != nil { if schema.Items.SchemaArray != nil { for _, s := range *(schema.Items.SchemaArray) { s.applyToSchemas(operation, "Items.SchemaArray") } } else if schema.Items.Schema != nil { schema.Items.Schema.applyToSchemas(operation, "Items.Schema") } } if schema.AdditionalProperties != nil { s := schema.AdditionalProperties.Schema if s != nil { s.applyToSchemas(operation, "AdditionalProperties") } } if schema.Properties != nil { for _, pair := range *(schema.Properties) { s := pair.Value s.applyToSchemas(operation, "Properties") } } if schema.PatternProperties != nil { for _, pair := range *(schema.PatternProperties) { s := pair.Value s.applyToSchemas(operation, "PatternProperties") } } if schema.Dependencies != nil { for _, pair := range *(schema.Dependencies) { schemaOrStringArray := pair.Value s := schemaOrStringArray.Schema if s != nil { s.applyToSchemas(operation, "Dependencies") } } } if schema.AllOf != nil { for _, s := range *(schema.AllOf) { s.applyToSchemas(operation, "AllOf") } } if schema.AnyOf != nil { for _, s := range *(schema.AnyOf) { s.applyToSchemas(operation, "AnyOf") } } if schema.OneOf != nil { for _, s := range *(schema.OneOf) { s.applyToSchemas(operation, "OneOf") } } if schema.Not != nil { schema.Not.applyToSchemas(operation, "Not") } if schema.Definitions != nil { for _, pair := range *(schema.Definitions) { s := pair.Value s.applyToSchemas(operation, "Definitions") } } operation(schema, context) }
[ "func", "(", "schema", "*", "Schema", ")", "applyToSchemas", "(", "operation", "SchemaOperation", ",", "context", "string", ")", "{", "if", "schema", ".", "AdditionalItems", "!=", "nil", "{", "s", ":=", "schema", ".", "AdditionalItems", ".", "Schema", "\n", "if", "s", "!=", "nil", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "schema", ".", "Items", "!=", "nil", "{", "if", "schema", ".", "Items", ".", "SchemaArray", "!=", "nil", "{", "for", "_", ",", "s", ":=", "range", "*", "(", "schema", ".", "Items", ".", "SchemaArray", ")", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "if", "schema", ".", "Items", ".", "Schema", "!=", "nil", "{", "schema", ".", "Items", ".", "Schema", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "schema", ".", "AdditionalProperties", "!=", "nil", "{", "s", ":=", "schema", ".", "AdditionalProperties", ".", "Schema", "\n", "if", "s", "!=", "nil", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "schema", ".", "Properties", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "*", "(", "schema", ".", "Properties", ")", "{", "s", ":=", "pair", ".", "Value", "\n", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "schema", ".", "PatternProperties", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "*", "(", "schema", ".", "PatternProperties", ")", "{", "s", ":=", "pair", ".", "Value", "\n", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "schema", ".", "Dependencies", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "*", "(", "schema", ".", "Dependencies", ")", "{", "schemaOrStringArray", ":=", "pair", ".", "Value", "\n", "s", ":=", "schemaOrStringArray", ".", "Schema", "\n", "if", "s", "!=", "nil", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "schema", ".", "AllOf", "!=", "nil", "{", "for", "_", ",", "s", ":=", "range", "*", "(", "schema", ".", "AllOf", ")", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "schema", ".", "AnyOf", "!=", "nil", "{", "for", "_", ",", "s", ":=", "range", "*", "(", "schema", ".", "AnyOf", ")", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "schema", ".", "OneOf", "!=", "nil", "{", "for", "_", ",", "s", ":=", "range", "*", "(", "schema", ".", "OneOf", ")", "{", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "schema", ".", "Not", "!=", "nil", "{", "schema", ".", "Not", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "schema", ".", "Definitions", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "*", "(", "schema", ".", "Definitions", ")", "{", "s", ":=", "pair", ".", "Value", "\n", "s", ".", "applyToSchemas", "(", "operation", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "operation", "(", "schema", ",", "context", ")", "\n", "}" ]
// Applies a specified function to a Schema and all of the Schemas that it contains.
[ "Applies", "a", "specified", "function", "to", "a", "Schema", "and", "all", "of", "the", "Schemas", "that", "it", "contains", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L75-L151
18,510
googleapis/gnostic
jsonschema/operations.go
TypeIs
func (schema *Schema) TypeIs(typeName string) bool { if schema.Type != nil { // the schema Type is either a string or an array of strings if schema.Type.String != nil { return (*(schema.Type.String) == typeName) } else if schema.Type.StringArray != nil { for _, n := range *(schema.Type.StringArray) { if n == typeName { return true } } } } return false }
go
func (schema *Schema) TypeIs(typeName string) bool { if schema.Type != nil { // the schema Type is either a string or an array of strings if schema.Type.String != nil { return (*(schema.Type.String) == typeName) } else if schema.Type.StringArray != nil { for _, n := range *(schema.Type.StringArray) { if n == typeName { return true } } } } return false }
[ "func", "(", "schema", "*", "Schema", ")", "TypeIs", "(", "typeName", "string", ")", "bool", "{", "if", "schema", ".", "Type", "!=", "nil", "{", "// the schema Type is either a string or an array of strings", "if", "schema", ".", "Type", ".", "String", "!=", "nil", "{", "return", "(", "*", "(", "schema", ".", "Type", ".", "String", ")", "==", "typeName", ")", "\n", "}", "else", "if", "schema", ".", "Type", ".", "StringArray", "!=", "nil", "{", "for", "_", ",", "n", ":=", "range", "*", "(", "schema", ".", "Type", ".", "StringArray", ")", "{", "if", "n", "==", "typeName", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// TypeIs returns true if the Type of a Schema includes the specified type
[ "TypeIs", "returns", "true", "if", "the", "Type", "of", "a", "Schema", "includes", "the", "specified", "type" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L260-L274
18,511
googleapis/gnostic
jsonschema/operations.go
resolveJSONPointer
func (schema *Schema) resolveJSONPointer(ref string) (result *Schema, err error) { parts := strings.Split(ref, "#") if len(parts) == 2 { documentName := parts[0] + "#" if documentName == "#" && schema.ID != nil { documentName = *(schema.ID) } path := parts[1] document := schemas[documentName] pathParts := strings.Split(path, "/") // we currently do a very limited (hard-coded) resolution of certain paths and log errors for missed cases if len(pathParts) == 1 { return document, nil } else if len(pathParts) == 3 { switch pathParts[1] { case "definitions": dictionary := document.Definitions for _, pair := range *dictionary { if pair.Name == pathParts[2] { result = pair.Value } } case "properties": dictionary := document.Properties for _, pair := range *dictionary { if pair.Name == pathParts[2] { result = pair.Value } } default: break } } } if result == nil { return nil, fmt.Errorf("unresolved pointer: %+v", ref) } return result, nil }
go
func (schema *Schema) resolveJSONPointer(ref string) (result *Schema, err error) { parts := strings.Split(ref, "#") if len(parts) == 2 { documentName := parts[0] + "#" if documentName == "#" && schema.ID != nil { documentName = *(schema.ID) } path := parts[1] document := schemas[documentName] pathParts := strings.Split(path, "/") // we currently do a very limited (hard-coded) resolution of certain paths and log errors for missed cases if len(pathParts) == 1 { return document, nil } else if len(pathParts) == 3 { switch pathParts[1] { case "definitions": dictionary := document.Definitions for _, pair := range *dictionary { if pair.Name == pathParts[2] { result = pair.Value } } case "properties": dictionary := document.Properties for _, pair := range *dictionary { if pair.Name == pathParts[2] { result = pair.Value } } default: break } } } if result == nil { return nil, fmt.Errorf("unresolved pointer: %+v", ref) } return result, nil }
[ "func", "(", "schema", "*", "Schema", ")", "resolveJSONPointer", "(", "ref", "string", ")", "(", "result", "*", "Schema", ",", "err", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "ref", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "==", "2", "{", "documentName", ":=", "parts", "[", "0", "]", "+", "\"", "\"", "\n", "if", "documentName", "==", "\"", "\"", "&&", "schema", ".", "ID", "!=", "nil", "{", "documentName", "=", "*", "(", "schema", ".", "ID", ")", "\n", "}", "\n", "path", ":=", "parts", "[", "1", "]", "\n", "document", ":=", "schemas", "[", "documentName", "]", "\n", "pathParts", ":=", "strings", ".", "Split", "(", "path", ",", "\"", "\"", ")", "\n\n", "// we currently do a very limited (hard-coded) resolution of certain paths and log errors for missed cases", "if", "len", "(", "pathParts", ")", "==", "1", "{", "return", "document", ",", "nil", "\n", "}", "else", "if", "len", "(", "pathParts", ")", "==", "3", "{", "switch", "pathParts", "[", "1", "]", "{", "case", "\"", "\"", ":", "dictionary", ":=", "document", ".", "Definitions", "\n", "for", "_", ",", "pair", ":=", "range", "*", "dictionary", "{", "if", "pair", ".", "Name", "==", "pathParts", "[", "2", "]", "{", "result", "=", "pair", ".", "Value", "\n", "}", "\n", "}", "\n", "case", "\"", "\"", ":", "dictionary", ":=", "document", ".", "Properties", "\n", "for", "_", ",", "pair", ":=", "range", "*", "dictionary", "{", "if", "pair", ".", "Name", "==", "pathParts", "[", "2", "]", "{", "result", "=", "pair", ".", "Value", "\n", "}", "\n", "}", "\n", "default", ":", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "result", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ref", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// resolveJSONPointer resolves JSON pointers. // This current implementation is very crude and custom for OpenAPI 2.0 schemas. // It panics for any pointer that it is unable to resolve.
[ "resolveJSONPointer", "resolves", "JSON", "pointers", ".", "This", "current", "implementation", "is", "very", "crude", "and", "custom", "for", "OpenAPI", "2", ".", "0", "schemas", ".", "It", "panics", "for", "any", "pointer", "that", "it", "is", "unable", "to", "resolve", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L312-L351
18,512
googleapis/gnostic
jsonschema/operations.go
ResolveAllOfs
func (schema *Schema) ResolveAllOfs() { schema.applyToSchemas( func(schema *Schema, context string) { if schema.AllOf != nil { for _, allOf := range *(schema.AllOf) { schema.CopyProperties(allOf) } schema.AllOf = nil } }, "resolveAllOfs") }
go
func (schema *Schema) ResolveAllOfs() { schema.applyToSchemas( func(schema *Schema, context string) { if schema.AllOf != nil { for _, allOf := range *(schema.AllOf) { schema.CopyProperties(allOf) } schema.AllOf = nil } }, "resolveAllOfs") }
[ "func", "(", "schema", "*", "Schema", ")", "ResolveAllOfs", "(", ")", "{", "schema", ".", "applyToSchemas", "(", "func", "(", "schema", "*", "Schema", ",", "context", "string", ")", "{", "if", "schema", ".", "AllOf", "!=", "nil", "{", "for", "_", ",", "allOf", ":=", "range", "*", "(", "schema", ".", "AllOf", ")", "{", "schema", ".", "CopyProperties", "(", "allOf", ")", "\n", "}", "\n", "schema", ".", "AllOf", "=", "nil", "\n", "}", "\n", "}", ",", "\"", "\"", ")", "\n", "}" ]
// ResolveAllOfs replaces "allOf" elements by merging their properties into the parent Schema.
[ "ResolveAllOfs", "replaces", "allOf", "elements", "by", "merging", "their", "properties", "into", "the", "parent", "Schema", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L354-L364
18,513
googleapis/gnostic
jsonschema/operations.go
ResolveAnyOfs
func (schema *Schema) ResolveAnyOfs() { schema.applyToSchemas( func(schema *Schema, context string) { if schema.AnyOf != nil { schema.OneOf = schema.AnyOf schema.AnyOf = nil } }, "resolveAnyOfs") }
go
func (schema *Schema) ResolveAnyOfs() { schema.applyToSchemas( func(schema *Schema, context string) { if schema.AnyOf != nil { schema.OneOf = schema.AnyOf schema.AnyOf = nil } }, "resolveAnyOfs") }
[ "func", "(", "schema", "*", "Schema", ")", "ResolveAnyOfs", "(", ")", "{", "schema", ".", "applyToSchemas", "(", "func", "(", "schema", "*", "Schema", ",", "context", "string", ")", "{", "if", "schema", ".", "AnyOf", "!=", "nil", "{", "schema", ".", "OneOf", "=", "schema", ".", "AnyOf", "\n", "schema", ".", "AnyOf", "=", "nil", "\n", "}", "\n", "}", ",", "\"", "\"", ")", "\n", "}" ]
// ResolveAnyOfs replaces all "anyOf" elements with "oneOf".
[ "ResolveAnyOfs", "replaces", "all", "anyOf", "elements", "with", "oneOf", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L367-L375
18,514
googleapis/gnostic
jsonschema/operations.go
CopyOfficialSchemaProperty
func (schema *Schema) CopyOfficialSchemaProperty(name string) { *schema.Properties = append(*schema.Properties, NewNamedSchema(name, &Schema{Ref: stringptr("http://json-schema.org/draft-04/schema#/properties/" + name)})) }
go
func (schema *Schema) CopyOfficialSchemaProperty(name string) { *schema.Properties = append(*schema.Properties, NewNamedSchema(name, &Schema{Ref: stringptr("http://json-schema.org/draft-04/schema#/properties/" + name)})) }
[ "func", "(", "schema", "*", "Schema", ")", "CopyOfficialSchemaProperty", "(", "name", "string", ")", "{", "*", "schema", ".", "Properties", "=", "append", "(", "*", "schema", ".", "Properties", ",", "NewNamedSchema", "(", "name", ",", "&", "Schema", "{", "Ref", ":", "stringptr", "(", "\"", "\"", "+", "name", ")", "}", ")", ")", "\n", "}" ]
// CopyOfficialSchemaProperty copies a named property from the official JSON Schema definition
[ "CopyOfficialSchemaProperty", "copies", "a", "named", "property", "from", "the", "official", "JSON", "Schema", "definition" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L383-L387
18,515
googleapis/gnostic
jsonschema/operations.go
CopyOfficialSchemaProperties
func (schema *Schema) CopyOfficialSchemaProperties(names []string) { for _, name := range names { schema.CopyOfficialSchemaProperty(name) } }
go
func (schema *Schema) CopyOfficialSchemaProperties(names []string) { for _, name := range names { schema.CopyOfficialSchemaProperty(name) } }
[ "func", "(", "schema", "*", "Schema", ")", "CopyOfficialSchemaProperties", "(", "names", "[", "]", "string", ")", "{", "for", "_", ",", "name", ":=", "range", "names", "{", "schema", ".", "CopyOfficialSchemaProperty", "(", "name", ")", "\n", "}", "\n", "}" ]
// CopyOfficialSchemaProperties copies named properties from the official JSON Schema definition
[ "CopyOfficialSchemaProperties", "copies", "named", "properties", "from", "the", "official", "JSON", "Schema", "definition" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/operations.go#L390-L394
18,516
googleapis/gnostic
jsonwriter/writer.go
escape
func escape(s string) string { s = strings.Replace(s, "\n", "\\n", -1) s = strings.Replace(s, "\"", "\\\"", -1) return s }
go
func escape(s string) string { s = strings.Replace(s, "\n", "\\n", -1) s = strings.Replace(s, "\"", "\\\"", -1) return s }
[ "func", "escape", "(", "s", "string", ")", "string", "{", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\n", "\"", ",", "\"", "\\\\", "\"", ",", "-", "1", ")", "\n", "s", "=", "strings", ".", "Replace", "(", "s", ",", "\"", "\\\"", "\"", ",", "\"", "\\\\", "\\\"", "\"", ",", "-", "1", ")", "\n", "return", "s", "\n", "}" ]
// basic escaping, will need to be improved or replaced
[ "basic", "escaping", "will", "need", "to", "be", "improved", "or", "replaced" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonwriter/writer.go#L29-L33
18,517
googleapis/gnostic
jsonwriter/writer.go
Marshal
func Marshal(in interface{}) (out []byte, err error) { var w writer m, ok := in.(yaml.MapSlice) if !ok { return nil, errors.New("invalid type passed to Marshal") } w.writeMap(m, "") w.writeString("\n") return w.bytes(), err }
go
func Marshal(in interface{}) (out []byte, err error) { var w writer m, ok := in.(yaml.MapSlice) if !ok { return nil, errors.New("invalid type passed to Marshal") } w.writeMap(m, "") w.writeString("\n") return w.bytes(), err }
[ "func", "Marshal", "(", "in", "interface", "{", "}", ")", "(", "out", "[", "]", "byte", ",", "err", "error", ")", "{", "var", "w", "writer", "\n", "m", ",", "ok", ":=", "in", ".", "(", "yaml", ".", "MapSlice", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "w", ".", "writeMap", "(", "m", ",", "\"", "\"", ")", "\n", "w", ".", "writeString", "(", "\"", "\\n", "\"", ")", "\n", "return", "w", ".", "bytes", "(", ")", ",", "err", "\n", "}" ]
// Marshal writes a yaml.MapSlice as JSON
[ "Marshal", "writes", "a", "yaml", ".", "MapSlice", "as", "JSON" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonwriter/writer.go#L159-L168
18,518
googleapis/gnostic
compiler/context.go
NewContextWithExtensions
func NewContextWithExtensions(name string, parent *Context, extensionHandlers *[]ExtensionHandler) *Context { return &Context{Name: name, Parent: parent, ExtensionHandlers: extensionHandlers} }
go
func NewContextWithExtensions(name string, parent *Context, extensionHandlers *[]ExtensionHandler) *Context { return &Context{Name: name, Parent: parent, ExtensionHandlers: extensionHandlers} }
[ "func", "NewContextWithExtensions", "(", "name", "string", ",", "parent", "*", "Context", ",", "extensionHandlers", "*", "[", "]", "ExtensionHandler", ")", "*", "Context", "{", "return", "&", "Context", "{", "Name", ":", "name", ",", "Parent", ":", "parent", ",", "ExtensionHandlers", ":", "extensionHandlers", "}", "\n", "}" ]
// NewContextWithExtensions returns a new object representing the compiler state
[ "NewContextWithExtensions", "returns", "a", "new", "object", "representing", "the", "compiler", "state" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/context.go#L25-L27
18,519
googleapis/gnostic
compiler/context.go
NewContext
func NewContext(name string, parent *Context) *Context { if parent != nil { return &Context{Name: name, Parent: parent, ExtensionHandlers: parent.ExtensionHandlers} } return &Context{Name: name, Parent: parent, ExtensionHandlers: nil} }
go
func NewContext(name string, parent *Context) *Context { if parent != nil { return &Context{Name: name, Parent: parent, ExtensionHandlers: parent.ExtensionHandlers} } return &Context{Name: name, Parent: parent, ExtensionHandlers: nil} }
[ "func", "NewContext", "(", "name", "string", ",", "parent", "*", "Context", ")", "*", "Context", "{", "if", "parent", "!=", "nil", "{", "return", "&", "Context", "{", "Name", ":", "name", ",", "Parent", ":", "parent", ",", "ExtensionHandlers", ":", "parent", ".", "ExtensionHandlers", "}", "\n", "}", "\n", "return", "&", "Context", "{", "Name", ":", "name", ",", "Parent", ":", "parent", ",", "ExtensionHandlers", ":", "nil", "}", "\n", "}" ]
// NewContext returns a new object representing the compiler state
[ "NewContext", "returns", "a", "new", "object", "representing", "the", "compiler", "state" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/context.go#L30-L35
18,520
googleapis/gnostic
compiler/context.go
Description
func (context *Context) Description() string { if context.Parent != nil { return context.Parent.Description() + "." + context.Name } return context.Name }
go
func (context *Context) Description() string { if context.Parent != nil { return context.Parent.Description() + "." + context.Name } return context.Name }
[ "func", "(", "context", "*", "Context", ")", "Description", "(", ")", "string", "{", "if", "context", ".", "Parent", "!=", "nil", "{", "return", "context", ".", "Parent", ".", "Description", "(", ")", "+", "\"", "\"", "+", "context", ".", "Name", "\n", "}", "\n", "return", "context", ".", "Name", "\n", "}" ]
// Description returns a text description of the compiler state
[ "Description", "returns", "a", "text", "description", "of", "the", "compiler", "state" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/context.go#L38-L43
18,521
googleapis/gnostic
linters/go/gnostic-lint-descriptions/linter_v2.go
analyzeDocument
func (s *DocumentLinterV2) analyzeDocument(document *openapi.Document) []*plugins.Message { messages := make([]*plugins.Message, 0, 0) for _, pair := range document.Paths.Path { path := pair.Value if path.Get != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "get"}, path.Get)...) } if path.Post != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "post"}, path.Post)...) } if path.Put != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "put"}, path.Put)...) } if path.Delete != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "delete"}, path.Delete)...) } } if document.Definitions != nil { for _, pair := range document.Definitions.AdditionalProperties { definition := pair.Value messages = append(messages, s.analyzeDefinition([]string{"definitions", pair.Name}, definition)...) } } return messages }
go
func (s *DocumentLinterV2) analyzeDocument(document *openapi.Document) []*plugins.Message { messages := make([]*plugins.Message, 0, 0) for _, pair := range document.Paths.Path { path := pair.Value if path.Get != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "get"}, path.Get)...) } if path.Post != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "post"}, path.Post)...) } if path.Put != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "put"}, path.Put)...) } if path.Delete != nil { messages = append(messages, s.analyzeOperation([]string{"paths", pair.Name, "delete"}, path.Delete)...) } } if document.Definitions != nil { for _, pair := range document.Definitions.AdditionalProperties { definition := pair.Value messages = append(messages, s.analyzeDefinition([]string{"definitions", pair.Name}, definition)...) } } return messages }
[ "func", "(", "s", "*", "DocumentLinterV2", ")", "analyzeDocument", "(", "document", "*", "openapi", ".", "Document", ")", "[", "]", "*", "plugins", ".", "Message", "{", "messages", ":=", "make", "(", "[", "]", "*", "plugins", ".", "Message", ",", "0", ",", "0", ")", "\n", "for", "_", ",", "pair", ":=", "range", "document", ".", "Paths", ".", "Path", "{", "path", ":=", "pair", ".", "Value", "\n", "if", "path", ".", "Get", "!=", "nil", "{", "messages", "=", "append", "(", "messages", ",", "s", ".", "analyzeOperation", "(", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", ",", "\"", "\"", "}", ",", "path", ".", "Get", ")", "...", ")", "\n", "}", "\n", "if", "path", ".", "Post", "!=", "nil", "{", "messages", "=", "append", "(", "messages", ",", "s", ".", "analyzeOperation", "(", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", ",", "\"", "\"", "}", ",", "path", ".", "Post", ")", "...", ")", "\n", "}", "\n", "if", "path", ".", "Put", "!=", "nil", "{", "messages", "=", "append", "(", "messages", ",", "s", ".", "analyzeOperation", "(", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", ",", "\"", "\"", "}", ",", "path", ".", "Put", ")", "...", ")", "\n", "}", "\n", "if", "path", ".", "Delete", "!=", "nil", "{", "messages", "=", "append", "(", "messages", ",", "s", ".", "analyzeOperation", "(", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", ",", "\"", "\"", "}", ",", "path", ".", "Delete", ")", "...", ")", "\n", "}", "\n", "}", "\n", "if", "document", ".", "Definitions", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "document", ".", "Definitions", ".", "AdditionalProperties", "{", "definition", ":=", "pair", ".", "Value", "\n", "messages", "=", "append", "(", "messages", ",", "s", ".", "analyzeDefinition", "(", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", "}", ",", "definition", ")", "...", ")", "\n", "}", "\n", "}", "\n", "return", "messages", "\n", "}" ]
// Analyze an OpenAPI description.
[ "Analyze", "an", "OpenAPI", "description", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/linters/go/gnostic-lint-descriptions/linter_v2.go#L36-L60
18,522
googleapis/gnostic
linters/go/gnostic-lint-descriptions/linter_v2.go
analyzeDefinition
func (s *DocumentLinterV2) analyzeDefinition(keys []string, definition *openapi.Schema) []*plugins.Message { messages := make([]*plugins.Message, 0) if definition.Description == "" { messages = append(messages, &plugins.Message{ Level: plugins.Message_WARNING, Code: "NODESCRIPTION", Text: "Definition has no description.", Keys: keys}) } if definition.Properties != nil { for _, pair := range definition.Properties.AdditionalProperties { propertySchema := pair.Value if propertySchema.Description == "" { messages = append(messages, &plugins.Message{ Level: plugins.Message_WARNING, Code: "NODESCRIPTION", Text: "Property has no description.", Keys: append(keys, []string{"properties", pair.Name}...)}) } } } return messages }
go
func (s *DocumentLinterV2) analyzeDefinition(keys []string, definition *openapi.Schema) []*plugins.Message { messages := make([]*plugins.Message, 0) if definition.Description == "" { messages = append(messages, &plugins.Message{ Level: plugins.Message_WARNING, Code: "NODESCRIPTION", Text: "Definition has no description.", Keys: keys}) } if definition.Properties != nil { for _, pair := range definition.Properties.AdditionalProperties { propertySchema := pair.Value if propertySchema.Description == "" { messages = append(messages, &plugins.Message{ Level: plugins.Message_WARNING, Code: "NODESCRIPTION", Text: "Property has no description.", Keys: append(keys, []string{"properties", pair.Name}...)}) } } } return messages }
[ "func", "(", "s", "*", "DocumentLinterV2", ")", "analyzeDefinition", "(", "keys", "[", "]", "string", ",", "definition", "*", "openapi", ".", "Schema", ")", "[", "]", "*", "plugins", ".", "Message", "{", "messages", ":=", "make", "(", "[", "]", "*", "plugins", ".", "Message", ",", "0", ")", "\n", "if", "definition", ".", "Description", "==", "\"", "\"", "{", "messages", "=", "append", "(", "messages", ",", "&", "plugins", ".", "Message", "{", "Level", ":", "plugins", ".", "Message_WARNING", ",", "Code", ":", "\"", "\"", ",", "Text", ":", "\"", "\"", ",", "Keys", ":", "keys", "}", ")", "\n", "}", "\n\n", "if", "definition", ".", "Properties", "!=", "nil", "{", "for", "_", ",", "pair", ":=", "range", "definition", ".", "Properties", ".", "AdditionalProperties", "{", "propertySchema", ":=", "pair", ".", "Value", "\n", "if", "propertySchema", ".", "Description", "==", "\"", "\"", "{", "messages", "=", "append", "(", "messages", ",", "&", "plugins", ".", "Message", "{", "Level", ":", "plugins", ".", "Message_WARNING", ",", "Code", ":", "\"", "\"", ",", "Text", ":", "\"", "\"", ",", "Keys", ":", "append", "(", "keys", ",", "[", "]", "string", "{", "\"", "\"", ",", "pair", ".", "Name", "}", "...", ")", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "messages", "\n", "}" ]
// Analyze a definition in an OpenAPI description.
[ "Analyze", "a", "definition", "in", "an", "OpenAPI", "description", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/linters/go/gnostic-lint-descriptions/linter_v2.go#L155-L180
18,523
googleapis/gnostic
jsonschema/reader.go
NewSchemaFromFile
func NewSchemaFromFile(filename string) (schema *Schema, err error) { file, err := ioutil.ReadFile(filename) if err != nil { return nil, err } var info yaml.MapSlice err = yaml.Unmarshal(file, &info) if err != nil { return nil, err } return NewSchemaFromObject(info), nil }
go
func NewSchemaFromFile(filename string) (schema *Schema, err error) { file, err := ioutil.ReadFile(filename) if err != nil { return nil, err } var info yaml.MapSlice err = yaml.Unmarshal(file, &info) if err != nil { return nil, err } return NewSchemaFromObject(info), nil }
[ "func", "NewSchemaFromFile", "(", "filename", "string", ")", "(", "schema", "*", "Schema", ",", "err", "error", ")", "{", "file", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "info", "yaml", ".", "MapSlice", "\n", "err", "=", "yaml", ".", "Unmarshal", "(", "file", ",", "&", "info", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "NewSchemaFromObject", "(", "info", ")", ",", "nil", "\n", "}" ]
// NewSchemaFromFile reads a schema from a file. // Currently this assumes that schemas are stored in the source distribution of this project.
[ "NewSchemaFromFile", "reads", "a", "schema", "from", "a", "file", ".", "Currently", "this", "assumes", "that", "schemas", "are", "stored", "in", "the", "source", "distribution", "of", "this", "project", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/reader.go#L30-L41
18,524
googleapis/gnostic
generate-gnostic/domain.go
NewDomain
func NewDomain(schema *jsonschema.Schema, version string) *Domain { cc := &Domain{} cc.TypeModels = make(map[string]*TypeModel, 0) cc.TypeNameOverrides = make(map[string]string, 0) cc.PropertyNameOverrides = make(map[string]string, 0) cc.ObjectTypeRequests = make(map[string]*TypeRequest, 0) cc.MapTypeRequests = make(map[string]string, 0) cc.Schema = schema cc.Version = version return cc }
go
func NewDomain(schema *jsonschema.Schema, version string) *Domain { cc := &Domain{} cc.TypeModels = make(map[string]*TypeModel, 0) cc.TypeNameOverrides = make(map[string]string, 0) cc.PropertyNameOverrides = make(map[string]string, 0) cc.ObjectTypeRequests = make(map[string]*TypeRequest, 0) cc.MapTypeRequests = make(map[string]string, 0) cc.Schema = schema cc.Version = version return cc }
[ "func", "NewDomain", "(", "schema", "*", "jsonschema", ".", "Schema", ",", "version", "string", ")", "*", "Domain", "{", "cc", ":=", "&", "Domain", "{", "}", "\n", "cc", ".", "TypeModels", "=", "make", "(", "map", "[", "string", "]", "*", "TypeModel", ",", "0", ")", "\n", "cc", ".", "TypeNameOverrides", "=", "make", "(", "map", "[", "string", "]", "string", ",", "0", ")", "\n", "cc", ".", "PropertyNameOverrides", "=", "make", "(", "map", "[", "string", "]", "string", ",", "0", ")", "\n", "cc", ".", "ObjectTypeRequests", "=", "make", "(", "map", "[", "string", "]", "*", "TypeRequest", ",", "0", ")", "\n", "cc", ".", "MapTypeRequests", "=", "make", "(", "map", "[", "string", "]", "string", ",", "0", ")", "\n", "cc", ".", "Schema", "=", "schema", "\n", "cc", ".", "Version", "=", "version", "\n", "return", "cc", "\n", "}" ]
// NewDomain creates a domain representation.
[ "NewDomain", "creates", "a", "domain", "representation", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L40-L50
18,525
googleapis/gnostic
generate-gnostic/domain.go
TypeNameForStub
func (domain *Domain) TypeNameForStub(stub string) string { return domain.Prefix + strings.ToUpper(stub[0:1]) + stub[1:len(stub)] }
go
func (domain *Domain) TypeNameForStub(stub string) string { return domain.Prefix + strings.ToUpper(stub[0:1]) + stub[1:len(stub)] }
[ "func", "(", "domain", "*", "Domain", ")", "TypeNameForStub", "(", "stub", "string", ")", "string", "{", "return", "domain", ".", "Prefix", "+", "strings", ".", "ToUpper", "(", "stub", "[", "0", ":", "1", "]", ")", "+", "stub", "[", "1", ":", "len", "(", "stub", ")", "]", "\n", "}" ]
// TypeNameForStub returns a capitalized name to use for a generated type.
[ "TypeNameForStub", "returns", "a", "capitalized", "name", "to", "use", "for", "a", "generated", "type", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L53-L57
18,526
googleapis/gnostic
generate-gnostic/domain.go
typeNameForReference
func (domain *Domain) typeNameForReference(reference string) string { parts := strings.Split(reference, "/") first := parts[0] last := parts[len(parts)-1] if first == "#" { return domain.TypeNameForStub(last) } return "Schema" }
go
func (domain *Domain) typeNameForReference(reference string) string { parts := strings.Split(reference, "/") first := parts[0] last := parts[len(parts)-1] if first == "#" { return domain.TypeNameForStub(last) } return "Schema" }
[ "func", "(", "domain", "*", "Domain", ")", "typeNameForReference", "(", "reference", "string", ")", "string", "{", "parts", ":=", "strings", ".", "Split", "(", "reference", ",", "\"", "\"", ")", "\n", "first", ":=", "parts", "[", "0", "]", "\n", "last", ":=", "parts", "[", "len", "(", "parts", ")", "-", "1", "]", "\n", "if", "first", "==", "\"", "\"", "{", "return", "domain", ".", "TypeNameForStub", "(", "last", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// typeNameForReference returns a capitalized name to use for a generated type based on a JSON reference
[ "typeNameForReference", "returns", "a", "capitalized", "name", "to", "use", "for", "a", "generated", "type", "based", "on", "a", "JSON", "reference" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L60-L68
18,527
googleapis/gnostic
generate-gnostic/domain.go
propertyNameForReference
func (domain *Domain) propertyNameForReference(reference string) *string { parts := strings.Split(reference, "/") first := parts[0] last := parts[len(parts)-1] if first == "#" { return &last } return nil }
go
func (domain *Domain) propertyNameForReference(reference string) *string { parts := strings.Split(reference, "/") first := parts[0] last := parts[len(parts)-1] if first == "#" { return &last } return nil }
[ "func", "(", "domain", "*", "Domain", ")", "propertyNameForReference", "(", "reference", "string", ")", "*", "string", "{", "parts", ":=", "strings", ".", "Split", "(", "reference", ",", "\"", "\"", ")", "\n", "first", ":=", "parts", "[", "0", "]", "\n", "last", ":=", "parts", "[", "len", "(", "parts", ")", "-", "1", "]", "\n", "if", "first", "==", "\"", "\"", "{", "return", "&", "last", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// propertyNameForReference returns a property name to use for a JSON reference
[ "propertyNameForReference", "returns", "a", "property", "name", "to", "use", "for", "a", "JSON", "reference" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L71-L79
18,528
googleapis/gnostic
generate-gnostic/domain.go
arrayItemTypeForSchema
func (domain *Domain) arrayItemTypeForSchema(propertyName string, schema *jsonschema.Schema) string { // default itemTypeName := "Any" if schema.Items != nil { if schema.Items.SchemaArray != nil { if len(*(schema.Items.SchemaArray)) > 0 { ref := (*schema.Items.SchemaArray)[0].Ref if ref != nil { itemTypeName = domain.typeNameForReference(*ref) } else { types := (*schema.Items.SchemaArray)[0].Type if types == nil { // do nothing } else if (types.StringArray != nil) && len(*(types.StringArray)) == 1 { itemTypeName = (*types.StringArray)[0] } else if (types.StringArray != nil) && len(*(types.StringArray)) > 1 { itemTypeName = fmt.Sprintf("%+v", types.StringArray) } else if types.String != nil { itemTypeName = *(types.String) } else { itemTypeName = "UNKNOWN" } } } } else if schema.Items.Schema != nil { types := schema.Items.Schema.Type if schema.Items.Schema.Ref != nil { itemTypeName = domain.typeNameForReference(*schema.Items.Schema.Ref) } else if schema.Items.Schema.OneOf != nil { // this type is implied by the "oneOf" itemTypeName = domain.TypeNameForStub(propertyName + "Item") domain.ObjectTypeRequests[itemTypeName] = NewTypeRequest(itemTypeName, propertyName, schema.Items.Schema) } else if types == nil { // do nothing } else if (types.StringArray != nil) && len(*(types.StringArray)) == 1 { itemTypeName = (*types.StringArray)[0] } else if (types.StringArray != nil) && len(*(types.StringArray)) > 1 { itemTypeName = fmt.Sprintf("%+v", types.StringArray) } else if types.String != nil { itemTypeName = *(types.String) } else { itemTypeName = "UNKNOWN" } } } return itemTypeName }
go
func (domain *Domain) arrayItemTypeForSchema(propertyName string, schema *jsonschema.Schema) string { // default itemTypeName := "Any" if schema.Items != nil { if schema.Items.SchemaArray != nil { if len(*(schema.Items.SchemaArray)) > 0 { ref := (*schema.Items.SchemaArray)[0].Ref if ref != nil { itemTypeName = domain.typeNameForReference(*ref) } else { types := (*schema.Items.SchemaArray)[0].Type if types == nil { // do nothing } else if (types.StringArray != nil) && len(*(types.StringArray)) == 1 { itemTypeName = (*types.StringArray)[0] } else if (types.StringArray != nil) && len(*(types.StringArray)) > 1 { itemTypeName = fmt.Sprintf("%+v", types.StringArray) } else if types.String != nil { itemTypeName = *(types.String) } else { itemTypeName = "UNKNOWN" } } } } else if schema.Items.Schema != nil { types := schema.Items.Schema.Type if schema.Items.Schema.Ref != nil { itemTypeName = domain.typeNameForReference(*schema.Items.Schema.Ref) } else if schema.Items.Schema.OneOf != nil { // this type is implied by the "oneOf" itemTypeName = domain.TypeNameForStub(propertyName + "Item") domain.ObjectTypeRequests[itemTypeName] = NewTypeRequest(itemTypeName, propertyName, schema.Items.Schema) } else if types == nil { // do nothing } else if (types.StringArray != nil) && len(*(types.StringArray)) == 1 { itemTypeName = (*types.StringArray)[0] } else if (types.StringArray != nil) && len(*(types.StringArray)) > 1 { itemTypeName = fmt.Sprintf("%+v", types.StringArray) } else if types.String != nil { itemTypeName = *(types.String) } else { itemTypeName = "UNKNOWN" } } } return itemTypeName }
[ "func", "(", "domain", "*", "Domain", ")", "arrayItemTypeForSchema", "(", "propertyName", "string", ",", "schema", "*", "jsonschema", ".", "Schema", ")", "string", "{", "// default", "itemTypeName", ":=", "\"", "\"", "\n\n", "if", "schema", ".", "Items", "!=", "nil", "{", "if", "schema", ".", "Items", ".", "SchemaArray", "!=", "nil", "{", "if", "len", "(", "*", "(", "schema", ".", "Items", ".", "SchemaArray", ")", ")", ">", "0", "{", "ref", ":=", "(", "*", "schema", ".", "Items", ".", "SchemaArray", ")", "[", "0", "]", ".", "Ref", "\n", "if", "ref", "!=", "nil", "{", "itemTypeName", "=", "domain", ".", "typeNameForReference", "(", "*", "ref", ")", "\n", "}", "else", "{", "types", ":=", "(", "*", "schema", ".", "Items", ".", "SchemaArray", ")", "[", "0", "]", ".", "Type", "\n", "if", "types", "==", "nil", "{", "// do nothing", "}", "else", "if", "(", "types", ".", "StringArray", "!=", "nil", ")", "&&", "len", "(", "*", "(", "types", ".", "StringArray", ")", ")", "==", "1", "{", "itemTypeName", "=", "(", "*", "types", ".", "StringArray", ")", "[", "0", "]", "\n", "}", "else", "if", "(", "types", ".", "StringArray", "!=", "nil", ")", "&&", "len", "(", "*", "(", "types", ".", "StringArray", ")", ")", ">", "1", "{", "itemTypeName", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "types", ".", "StringArray", ")", "\n", "}", "else", "if", "types", ".", "String", "!=", "nil", "{", "itemTypeName", "=", "*", "(", "types", ".", "String", ")", "\n", "}", "else", "{", "itemTypeName", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n\n", "}", "else", "if", "schema", ".", "Items", ".", "Schema", "!=", "nil", "{", "types", ":=", "schema", ".", "Items", ".", "Schema", ".", "Type", "\n\n", "if", "schema", ".", "Items", ".", "Schema", ".", "Ref", "!=", "nil", "{", "itemTypeName", "=", "domain", ".", "typeNameForReference", "(", "*", "schema", ".", "Items", ".", "Schema", ".", "Ref", ")", "\n", "}", "else", "if", "schema", ".", "Items", ".", "Schema", ".", "OneOf", "!=", "nil", "{", "// this type is implied by the \"oneOf\"", "itemTypeName", "=", "domain", ".", "TypeNameForStub", "(", "propertyName", "+", "\"", "\"", ")", "\n", "domain", ".", "ObjectTypeRequests", "[", "itemTypeName", "]", "=", "NewTypeRequest", "(", "itemTypeName", ",", "propertyName", ",", "schema", ".", "Items", ".", "Schema", ")", "\n", "}", "else", "if", "types", "==", "nil", "{", "// do nothing", "}", "else", "if", "(", "types", ".", "StringArray", "!=", "nil", ")", "&&", "len", "(", "*", "(", "types", ".", "StringArray", ")", ")", "==", "1", "{", "itemTypeName", "=", "(", "*", "types", ".", "StringArray", ")", "[", "0", "]", "\n", "}", "else", "if", "(", "types", ".", "StringArray", "!=", "nil", ")", "&&", "len", "(", "*", "(", "types", ".", "StringArray", ")", ")", ">", "1", "{", "itemTypeName", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "types", ".", "StringArray", ")", "\n", "}", "else", "if", "types", ".", "String", "!=", "nil", "{", "itemTypeName", "=", "*", "(", "types", ".", "String", ")", "\n", "}", "else", "{", "itemTypeName", "=", "\"", "\"", "\n", "}", "\n", "}", "\n\n", "}", "\n", "return", "itemTypeName", "\n", "}" ]
// arrayItemTypeForSchema determines the item type for arrays defined by a schema
[ "arrayItemTypeForSchema", "determines", "the", "item", "type", "for", "arrays", "defined", "by", "a", "schema" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L82-L135
18,529
googleapis/gnostic
generate-gnostic/domain.go
BuildTypeForDefinition
func (domain *Domain) BuildTypeForDefinition( typeName string, propertyName string, schema *jsonschema.Schema) *TypeModel { if (schema.Type == nil) || (*schema.Type.String == "object") { return domain.buildTypeForDefinitionObject(typeName, propertyName, schema) } return nil }
go
func (domain *Domain) BuildTypeForDefinition( typeName string, propertyName string, schema *jsonschema.Schema) *TypeModel { if (schema.Type == nil) || (*schema.Type.String == "object") { return domain.buildTypeForDefinitionObject(typeName, propertyName, schema) } return nil }
[ "func", "(", "domain", "*", "Domain", ")", "BuildTypeForDefinition", "(", "typeName", "string", ",", "propertyName", "string", ",", "schema", "*", "jsonschema", ".", "Schema", ")", "*", "TypeModel", "{", "if", "(", "schema", ".", "Type", "==", "nil", ")", "||", "(", "*", "schema", ".", "Type", ".", "String", "==", "\"", "\"", ")", "{", "return", "domain", ".", "buildTypeForDefinitionObject", "(", "typeName", ",", "propertyName", ",", "schema", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// BuildTypeForDefinition creates a type representation for a schema definition.
[ "BuildTypeForDefinition", "creates", "a", "type", "representation", "for", "a", "schema", "definition", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L479-L487
18,530
googleapis/gnostic
generate-gnostic/domain.go
Description
func (domain *Domain) Description() string { typeNames := domain.sortedTypeNames() result := "" for _, typeName := range typeNames { result += domain.TypeModels[typeName].description() } return result }
go
func (domain *Domain) Description() string { typeNames := domain.sortedTypeNames() result := "" for _, typeName := range typeNames { result += domain.TypeModels[typeName].description() } return result }
[ "func", "(", "domain", "*", "Domain", ")", "Description", "(", ")", "string", "{", "typeNames", ":=", "domain", ".", "sortedTypeNames", "(", ")", "\n", "result", ":=", "\"", "\"", "\n", "for", "_", ",", "typeName", ":=", "range", "typeNames", "{", "result", "+=", "domain", ".", "TypeModels", "[", "typeName", "]", ".", "description", "(", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// Description returns a string representation of a domain.
[ "Description", "returns", "a", "string", "representation", "of", "a", "domain", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/domain.go#L617-L624
18,531
googleapis/gnostic
compiler/helpers.go
UnpackMap
func UnpackMap(in interface{}) (yaml.MapSlice, bool) { m, ok := in.(yaml.MapSlice) if ok { return m, true } // do we have an empty array? a, ok := in.([]interface{}) if ok && len(a) == 0 { // if so, return an empty map return yaml.MapSlice{}, true } return nil, false }
go
func UnpackMap(in interface{}) (yaml.MapSlice, bool) { m, ok := in.(yaml.MapSlice) if ok { return m, true } // do we have an empty array? a, ok := in.([]interface{}) if ok && len(a) == 0 { // if so, return an empty map return yaml.MapSlice{}, true } return nil, false }
[ "func", "UnpackMap", "(", "in", "interface", "{", "}", ")", "(", "yaml", ".", "MapSlice", ",", "bool", ")", "{", "m", ",", "ok", ":=", "in", ".", "(", "yaml", ".", "MapSlice", ")", "\n", "if", "ok", "{", "return", "m", ",", "true", "\n", "}", "\n", "// do we have an empty array?", "a", ",", "ok", ":=", "in", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "if", "ok", "&&", "len", "(", "a", ")", "==", "0", "{", "// if so, return an empty map", "return", "yaml", ".", "MapSlice", "{", "}", ",", "true", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// compiler helper functions, usually called from generated code // UnpackMap gets a yaml.MapSlice if possible.
[ "compiler", "helper", "functions", "usually", "called", "from", "generated", "code", "UnpackMap", "gets", "a", "yaml", ".", "MapSlice", "if", "possible", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L28-L40
18,532
googleapis/gnostic
compiler/helpers.go
SortedKeysForMap
func SortedKeysForMap(m yaml.MapSlice) []string { keys := make([]string, 0) for _, item := range m { keys = append(keys, item.Key.(string)) } sort.Strings(keys) return keys }
go
func SortedKeysForMap(m yaml.MapSlice) []string { keys := make([]string, 0) for _, item := range m { keys = append(keys, item.Key.(string)) } sort.Strings(keys) return keys }
[ "func", "SortedKeysForMap", "(", "m", "yaml", ".", "MapSlice", ")", "[", "]", "string", "{", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", "{", "keys", "=", "append", "(", "keys", ",", "item", ".", "Key", ".", "(", "string", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "return", "keys", "\n", "}" ]
// SortedKeysForMap returns the sorted keys of a yaml.MapSlice.
[ "SortedKeysForMap", "returns", "the", "sorted", "keys", "of", "a", "yaml", ".", "MapSlice", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L43-L50
18,533
googleapis/gnostic
compiler/helpers.go
MapHasKey
func MapHasKey(m yaml.MapSlice, key string) bool { for _, item := range m { itemKey, ok := item.Key.(string) if ok && key == itemKey { return true } } return false }
go
func MapHasKey(m yaml.MapSlice, key string) bool { for _, item := range m { itemKey, ok := item.Key.(string) if ok && key == itemKey { return true } } return false }
[ "func", "MapHasKey", "(", "m", "yaml", ".", "MapSlice", ",", "key", "string", ")", "bool", "{", "for", "_", ",", "item", ":=", "range", "m", "{", "itemKey", ",", "ok", ":=", "item", ".", "Key", ".", "(", "string", ")", "\n", "if", "ok", "&&", "key", "==", "itemKey", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// MapHasKey returns true if a yaml.MapSlice contains a specified key.
[ "MapHasKey", "returns", "true", "if", "a", "yaml", ".", "MapSlice", "contains", "a", "specified", "key", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L53-L61
18,534
googleapis/gnostic
compiler/helpers.go
MapValueForKey
func MapValueForKey(m yaml.MapSlice, key string) interface{} { for _, item := range m { itemKey, ok := item.Key.(string) if ok && key == itemKey { return item.Value } } return nil }
go
func MapValueForKey(m yaml.MapSlice, key string) interface{} { for _, item := range m { itemKey, ok := item.Key.(string) if ok && key == itemKey { return item.Value } } return nil }
[ "func", "MapValueForKey", "(", "m", "yaml", ".", "MapSlice", ",", "key", "string", ")", "interface", "{", "}", "{", "for", "_", ",", "item", ":=", "range", "m", "{", "itemKey", ",", "ok", ":=", "item", ".", "Key", ".", "(", "string", ")", "\n", "if", "ok", "&&", "key", "==", "itemKey", "{", "return", "item", ".", "Value", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MapValueForKey gets the value of a map value for a specified key.
[ "MapValueForKey", "gets", "the", "value", "of", "a", "map", "value", "for", "a", "specified", "key", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L64-L72
18,535
googleapis/gnostic
compiler/helpers.go
ConvertInterfaceArrayToStringArray
func ConvertInterfaceArrayToStringArray(interfaceArray []interface{}) []string { stringArray := make([]string, 0) for _, item := range interfaceArray { v, ok := item.(string) if ok { stringArray = append(stringArray, v) } } return stringArray }
go
func ConvertInterfaceArrayToStringArray(interfaceArray []interface{}) []string { stringArray := make([]string, 0) for _, item := range interfaceArray { v, ok := item.(string) if ok { stringArray = append(stringArray, v) } } return stringArray }
[ "func", "ConvertInterfaceArrayToStringArray", "(", "interfaceArray", "[", "]", "interface", "{", "}", ")", "[", "]", "string", "{", "stringArray", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "interfaceArray", "{", "v", ",", "ok", ":=", "item", ".", "(", "string", ")", "\n", "if", "ok", "{", "stringArray", "=", "append", "(", "stringArray", ",", "v", ")", "\n", "}", "\n", "}", "\n", "return", "stringArray", "\n", "}" ]
// ConvertInterfaceArrayToStringArray converts an array of interfaces to an array of strings, if possible.
[ "ConvertInterfaceArrayToStringArray", "converts", "an", "array", "of", "interfaces", "to", "an", "array", "of", "strings", "if", "possible", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L75-L84
18,536
googleapis/gnostic
compiler/helpers.go
MissingKeysInMap
func MissingKeysInMap(m yaml.MapSlice, requiredKeys []string) []string { missingKeys := make([]string, 0) for _, k := range requiredKeys { if !MapHasKey(m, k) { missingKeys = append(missingKeys, k) } } return missingKeys }
go
func MissingKeysInMap(m yaml.MapSlice, requiredKeys []string) []string { missingKeys := make([]string, 0) for _, k := range requiredKeys { if !MapHasKey(m, k) { missingKeys = append(missingKeys, k) } } return missingKeys }
[ "func", "MissingKeysInMap", "(", "m", "yaml", ".", "MapSlice", ",", "requiredKeys", "[", "]", "string", ")", "[", "]", "string", "{", "missingKeys", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "k", ":=", "range", "requiredKeys", "{", "if", "!", "MapHasKey", "(", "m", ",", "k", ")", "{", "missingKeys", "=", "append", "(", "missingKeys", ",", "k", ")", "\n", "}", "\n", "}", "\n", "return", "missingKeys", "\n", "}" ]
// MissingKeysInMap identifies which keys from a list of required keys are not in a map.
[ "MissingKeysInMap", "identifies", "which", "keys", "from", "a", "list", "of", "required", "keys", "are", "not", "in", "a", "map", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L87-L95
18,537
googleapis/gnostic
compiler/helpers.go
InvalidKeysInMap
func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []*regexp.Regexp) []string { invalidKeys := make([]string, 0) for _, item := range m { itemKey, ok := item.Key.(string) if ok { key := itemKey found := false // does the key match an allowed key? for _, allowedKey := range allowedKeys { if key == allowedKey { found = true break } } if !found { // does the key match an allowed pattern? for _, allowedPattern := range allowedPatterns { if allowedPattern.MatchString(key) { found = true break } } if !found { invalidKeys = append(invalidKeys, key) } } } } return invalidKeys }
go
func InvalidKeysInMap(m yaml.MapSlice, allowedKeys []string, allowedPatterns []*regexp.Regexp) []string { invalidKeys := make([]string, 0) for _, item := range m { itemKey, ok := item.Key.(string) if ok { key := itemKey found := false // does the key match an allowed key? for _, allowedKey := range allowedKeys { if key == allowedKey { found = true break } } if !found { // does the key match an allowed pattern? for _, allowedPattern := range allowedPatterns { if allowedPattern.MatchString(key) { found = true break } } if !found { invalidKeys = append(invalidKeys, key) } } } } return invalidKeys }
[ "func", "InvalidKeysInMap", "(", "m", "yaml", ".", "MapSlice", ",", "allowedKeys", "[", "]", "string", ",", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", ")", "[", "]", "string", "{", "invalidKeys", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", "{", "itemKey", ",", "ok", ":=", "item", ".", "Key", ".", "(", "string", ")", "\n", "if", "ok", "{", "key", ":=", "itemKey", "\n", "found", ":=", "false", "\n", "// does the key match an allowed key?", "for", "_", ",", "allowedKey", ":=", "range", "allowedKeys", "{", "if", "key", "==", "allowedKey", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "// does the key match an allowed pattern?", "for", "_", ",", "allowedPattern", ":=", "range", "allowedPatterns", "{", "if", "allowedPattern", ".", "MatchString", "(", "key", ")", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "invalidKeys", "=", "append", "(", "invalidKeys", ",", "key", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "invalidKeys", "\n", "}" ]
// InvalidKeysInMap returns keys in a map that don't match a list of allowed keys and patterns.
[ "InvalidKeysInMap", "returns", "keys", "in", "a", "map", "that", "don", "t", "match", "a", "list", "of", "allowed", "keys", "and", "patterns", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L98-L127
18,538
googleapis/gnostic
compiler/helpers.go
StringArrayContainsValue
func StringArrayContainsValue(array []string, value string) bool { for _, item := range array { if item == value { return true } } return false }
go
func StringArrayContainsValue(array []string, value string) bool { for _, item := range array { if item == value { return true } } return false }
[ "func", "StringArrayContainsValue", "(", "array", "[", "]", "string", ",", "value", "string", ")", "bool", "{", "for", "_", ",", "item", ":=", "range", "array", "{", "if", "item", "==", "value", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// StringArrayContainsValue returns true if a string array contains a specified value.
[ "StringArrayContainsValue", "returns", "true", "if", "a", "string", "array", "contains", "a", "specified", "value", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L167-L174
18,539
googleapis/gnostic
compiler/helpers.go
StringArrayContainsValues
func StringArrayContainsValues(array []string, values []string) bool { for _, value := range values { if !StringArrayContainsValue(array, value) { return false } } return true }
go
func StringArrayContainsValues(array []string, values []string) bool { for _, value := range values { if !StringArrayContainsValue(array, value) { return false } } return true }
[ "func", "StringArrayContainsValues", "(", "array", "[", "]", "string", ",", "values", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "value", ":=", "range", "values", "{", "if", "!", "StringArrayContainsValue", "(", "array", ",", "value", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// StringArrayContainsValues returns true if a string array contains all of a list of specified values.
[ "StringArrayContainsValues", "returns", "true", "if", "a", "string", "array", "contains", "all", "of", "a", "list", "of", "specified", "values", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L177-L184
18,540
googleapis/gnostic
compiler/helpers.go
StringValue
func StringValue(item interface{}) (value string, ok bool) { value, ok = item.(string) if ok { return value, ok } intValue, ok := item.(int) if ok { return strconv.Itoa(intValue), true } return "", false }
go
func StringValue(item interface{}) (value string, ok bool) { value, ok = item.(string) if ok { return value, ok } intValue, ok := item.(int) if ok { return strconv.Itoa(intValue), true } return "", false }
[ "func", "StringValue", "(", "item", "interface", "{", "}", ")", "(", "value", "string", ",", "ok", "bool", ")", "{", "value", ",", "ok", "=", "item", ".", "(", "string", ")", "\n", "if", "ok", "{", "return", "value", ",", "ok", "\n", "}", "\n", "intValue", ",", "ok", ":=", "item", ".", "(", "int", ")", "\n", "if", "ok", "{", "return", "strconv", ".", "Itoa", "(", "intValue", ")", ",", "true", "\n", "}", "\n", "return", "\"", "\"", ",", "false", "\n", "}" ]
// StringValue returns the string value of an item.
[ "StringValue", "returns", "the", "string", "value", "of", "an", "item", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/helpers.go#L187-L197
18,541
googleapis/gnostic
generate-gnostic/types.go
NewTypeRequest
func NewTypeRequest(name string, propertyName string, schema *jsonschema.Schema) *TypeRequest { return &TypeRequest{Name: name, PropertyName: propertyName, Schema: schema} }
go
func NewTypeRequest(name string, propertyName string, schema *jsonschema.Schema) *TypeRequest { return &TypeRequest{Name: name, PropertyName: propertyName, Schema: schema} }
[ "func", "NewTypeRequest", "(", "name", "string", ",", "propertyName", "string", ",", "schema", "*", "jsonschema", ".", "Schema", ")", "*", "TypeRequest", "{", "return", "&", "TypeRequest", "{", "Name", ":", "name", ",", "PropertyName", ":", "propertyName", ",", "Schema", ":", "schema", "}", "\n", "}" ]
// NewTypeRequest creates a TypeRequest.
[ "NewTypeRequest", "creates", "a", "TypeRequest", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/types.go#L35-L37
18,542
googleapis/gnostic
generate-gnostic/types.go
NewTypePropertyWithNameAndType
func NewTypePropertyWithNameAndType(name string, typeName string) *TypeProperty { return &TypeProperty{Name: name, Type: typeName} }
go
func NewTypePropertyWithNameAndType(name string, typeName string) *TypeProperty { return &TypeProperty{Name: name, Type: typeName} }
[ "func", "NewTypePropertyWithNameAndType", "(", "name", "string", ",", "typeName", "string", ")", "*", "TypeProperty", "{", "return", "&", "TypeProperty", "{", "Name", ":", "name", ",", "Type", ":", "typeName", "}", "\n", "}" ]
// NewTypePropertyWithNameAndType creates a TypeProperty
[ "NewTypePropertyWithNameAndType", "creates", "a", "TypeProperty" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/types.go#L70-L72
18,543
googleapis/gnostic
generate-gnostic/types.go
NewTypePropertyWithNameTypeAndPattern
func NewTypePropertyWithNameTypeAndPattern(name string, typeName string, pattern string) *TypeProperty { return &TypeProperty{Name: name, Type: typeName, Pattern: pattern} }
go
func NewTypePropertyWithNameTypeAndPattern(name string, typeName string, pattern string) *TypeProperty { return &TypeProperty{Name: name, Type: typeName, Pattern: pattern} }
[ "func", "NewTypePropertyWithNameTypeAndPattern", "(", "name", "string", ",", "typeName", "string", ",", "pattern", "string", ")", "*", "TypeProperty", "{", "return", "&", "TypeProperty", "{", "Name", ":", "name", ",", "Type", ":", "typeName", ",", "Pattern", ":", "pattern", "}", "\n", "}" ]
// NewTypePropertyWithNameTypeAndPattern creates a TypeProperty
[ "NewTypePropertyWithNameTypeAndPattern", "creates", "a", "TypeProperty" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/types.go#L75-L77
18,544
googleapis/gnostic
generate-gnostic/types.go
FieldName
func (typeProperty *TypeProperty) FieldName() string { propertyName := typeProperty.Name if propertyName == "$ref" { return "XRef" } return strings.Title(snakeCaseToCamelCase(propertyName)) }
go
func (typeProperty *TypeProperty) FieldName() string { propertyName := typeProperty.Name if propertyName == "$ref" { return "XRef" } return strings.Title(snakeCaseToCamelCase(propertyName)) }
[ "func", "(", "typeProperty", "*", "TypeProperty", ")", "FieldName", "(", ")", "string", "{", "propertyName", ":=", "typeProperty", ".", "Name", "\n", "if", "propertyName", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "strings", ".", "Title", "(", "snakeCaseToCamelCase", "(", "propertyName", ")", ")", "\n", "}" ]
// FieldName returns the message field name to use for a property.
[ "FieldName", "returns", "the", "message", "field", "name", "to", "use", "for", "a", "property", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/generate-gnostic/types.go#L80-L86
18,545
googleapis/gnostic
plugins/gnostic-analyze/summarize/main.go
walker
func walker(p string, info os.FileInfo, err error) error { basename := path.Base(p) if basename != "summary.json" { return nil } data, err := ioutil.ReadFile(p) if err != nil { return err } var s statistics.DocumentStatistics err = json.Unmarshal(data, &s) if err != nil { return err } stats = append(stats, s) return nil }
go
func walker(p string, info os.FileInfo, err error) error { basename := path.Base(p) if basename != "summary.json" { return nil } data, err := ioutil.ReadFile(p) if err != nil { return err } var s statistics.DocumentStatistics err = json.Unmarshal(data, &s) if err != nil { return err } stats = append(stats, s) return nil }
[ "func", "walker", "(", "p", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "basename", ":=", "path", ".", "Base", "(", "p", ")", "\n", "if", "basename", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "s", "statistics", ".", "DocumentStatistics", "\n", "err", "=", "json", ".", "Unmarshal", "(", "data", ",", "&", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "stats", "=", "append", "(", "stats", ",", "s", ")", "\n", "return", "nil", "\n", "}" ]
// walker is called for each summary file found.
[ "walker", "is", "called", "for", "each", "summary", "file", "found", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/plugins/gnostic-analyze/summarize/main.go#L34-L50
18,546
googleapis/gnostic
plugins/gnostic-analyze/main.go
sendAndExitIfError
func sendAndExitIfError(err error, response *plugins.Response) { if err != nil { response.Errors = append(response.Errors, err.Error()) sendAndExit(response) } }
go
func sendAndExitIfError(err error, response *plugins.Response) { if err != nil { response.Errors = append(response.Errors, err.Error()) sendAndExit(response) } }
[ "func", "sendAndExitIfError", "(", "err", "error", ",", "response", "*", "plugins", ".", "Response", ")", "{", "if", "err", "!=", "nil", "{", "response", ".", "Errors", "=", "append", "(", "response", ".", "Errors", ",", "err", ".", "Error", "(", ")", ")", "\n", "sendAndExit", "(", "response", ")", "\n", "}", "\n", "}" ]
// Record an error, then serialize and return a response.
[ "Record", "an", "error", "then", "serialize", "and", "return", "a", "response", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/plugins/gnostic-analyze/main.go#L42-L47
18,547
googleapis/gnostic
plugins/gnostic-analyze/main.go
sendAndExit
func sendAndExit(response *plugins.Response) { responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) }
go
func sendAndExit(response *plugins.Response) { responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) }
[ "func", "sendAndExit", "(", "response", "*", "plugins", ".", "Response", ")", "{", "responseBytes", ",", "_", ":=", "proto", ".", "Marshal", "(", "response", ")", "\n", "os", ".", "Stdout", ".", "Write", "(", "responseBytes", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}" ]
// Serialize and return a response.
[ "Serialize", "and", "return", "a", "response", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/plugins/gnostic-analyze/main.go#L50-L54
18,548
googleapis/gnostic
jsonschema/models.go
NewSchemaNumberWithInteger
func NewSchemaNumberWithInteger(i int64) *SchemaNumber { result := &SchemaNumber{} result.Integer = &i return result }
go
func NewSchemaNumberWithInteger(i int64) *SchemaNumber { result := &SchemaNumber{} result.Integer = &i return result }
[ "func", "NewSchemaNumberWithInteger", "(", "i", "int64", ")", "*", "SchemaNumber", "{", "result", ":=", "&", "SchemaNumber", "{", "}", "\n", "result", ".", "Integer", "=", "&", "i", "\n", "return", "result", "\n", "}" ]
// NewSchemaNumberWithInteger creates and returns a new object
[ "NewSchemaNumberWithInteger", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L86-L90
18,549
googleapis/gnostic
jsonschema/models.go
NewSchemaNumberWithFloat
func NewSchemaNumberWithFloat(f float64) *SchemaNumber { result := &SchemaNumber{} result.Float = &f return result }
go
func NewSchemaNumberWithFloat(f float64) *SchemaNumber { result := &SchemaNumber{} result.Float = &f return result }
[ "func", "NewSchemaNumberWithFloat", "(", "f", "float64", ")", "*", "SchemaNumber", "{", "result", ":=", "&", "SchemaNumber", "{", "}", "\n", "result", ".", "Float", "=", "&", "f", "\n", "return", "result", "\n", "}" ]
// NewSchemaNumberWithFloat creates and returns a new object
[ "NewSchemaNumberWithFloat", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L93-L97
18,550
googleapis/gnostic
jsonschema/models.go
NewSchemaOrBooleanWithSchema
func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean { result := &SchemaOrBoolean{} result.Schema = s return result }
go
func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean { result := &SchemaOrBoolean{} result.Schema = s return result }
[ "func", "NewSchemaOrBooleanWithSchema", "(", "s", "*", "Schema", ")", "*", "SchemaOrBoolean", "{", "result", ":=", "&", "SchemaOrBoolean", "{", "}", "\n", "result", ".", "Schema", "=", "s", "\n", "return", "result", "\n", "}" ]
// NewSchemaOrBooleanWithSchema creates and returns a new object
[ "NewSchemaOrBooleanWithSchema", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L106-L110
18,551
googleapis/gnostic
jsonschema/models.go
NewSchemaOrBooleanWithBoolean
func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean { result := &SchemaOrBoolean{} result.Boolean = &b return result }
go
func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean { result := &SchemaOrBoolean{} result.Boolean = &b return result }
[ "func", "NewSchemaOrBooleanWithBoolean", "(", "b", "bool", ")", "*", "SchemaOrBoolean", "{", "result", ":=", "&", "SchemaOrBoolean", "{", "}", "\n", "result", ".", "Boolean", "=", "&", "b", "\n", "return", "result", "\n", "}" ]
// NewSchemaOrBooleanWithBoolean creates and returns a new object
[ "NewSchemaOrBooleanWithBoolean", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L113-L117
18,552
googleapis/gnostic
jsonschema/models.go
NewStringOrStringArrayWithString
func NewStringOrStringArrayWithString(s string) *StringOrStringArray { result := &StringOrStringArray{} result.String = &s return result }
go
func NewStringOrStringArrayWithString(s string) *StringOrStringArray { result := &StringOrStringArray{} result.String = &s return result }
[ "func", "NewStringOrStringArrayWithString", "(", "s", "string", ")", "*", "StringOrStringArray", "{", "result", ":=", "&", "StringOrStringArray", "{", "}", "\n", "result", ".", "String", "=", "&", "s", "\n", "return", "result", "\n", "}" ]
// NewStringOrStringArrayWithString creates and returns a new object
[ "NewStringOrStringArrayWithString", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L127-L131
18,553
googleapis/gnostic
jsonschema/models.go
NewStringOrStringArrayWithStringArray
func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray { result := &StringOrStringArray{} result.StringArray = &a return result }
go
func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray { result := &StringOrStringArray{} result.StringArray = &a return result }
[ "func", "NewStringOrStringArrayWithStringArray", "(", "a", "[", "]", "string", ")", "*", "StringOrStringArray", "{", "result", ":=", "&", "StringOrStringArray", "{", "}", "\n", "result", ".", "StringArray", "=", "&", "a", "\n", "return", "result", "\n", "}" ]
// NewStringOrStringArrayWithStringArray creates and returns a new object
[ "NewStringOrStringArrayWithStringArray", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L134-L138
18,554
googleapis/gnostic
jsonschema/models.go
NewSchemaOrSchemaArrayWithSchema
func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray { result := &SchemaOrSchemaArray{} result.Schema = s return result }
go
func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray { result := &SchemaOrSchemaArray{} result.Schema = s return result }
[ "func", "NewSchemaOrSchemaArrayWithSchema", "(", "s", "*", "Schema", ")", "*", "SchemaOrSchemaArray", "{", "result", ":=", "&", "SchemaOrSchemaArray", "{", "}", "\n", "result", ".", "Schema", "=", "s", "\n", "return", "result", "\n", "}" ]
// NewSchemaOrSchemaArrayWithSchema creates and returns a new object
[ "NewSchemaOrSchemaArrayWithSchema", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L155-L159
18,555
googleapis/gnostic
jsonschema/models.go
NewSchemaOrSchemaArrayWithSchemaArray
func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray { result := &SchemaOrSchemaArray{} result.SchemaArray = &a return result }
go
func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray { result := &SchemaOrSchemaArray{} result.SchemaArray = &a return result }
[ "func", "NewSchemaOrSchemaArrayWithSchemaArray", "(", "a", "[", "]", "*", "Schema", ")", "*", "SchemaOrSchemaArray", "{", "result", ":=", "&", "SchemaOrSchemaArray", "{", "}", "\n", "result", ".", "SchemaArray", "=", "&", "a", "\n", "return", "result", "\n", "}" ]
// NewSchemaOrSchemaArrayWithSchemaArray creates and returns a new object
[ "NewSchemaOrSchemaArrayWithSchemaArray", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L162-L166
18,556
googleapis/gnostic
jsonschema/models.go
NewNamedSchema
func NewNamedSchema(name string, value *Schema) *NamedSchema { return &NamedSchema{Name: name, Value: value} }
go
func NewNamedSchema(name string, value *Schema) *NamedSchema { return &NamedSchema{Name: name, Value: value} }
[ "func", "NewNamedSchema", "(", "name", "string", ",", "value", "*", "Schema", ")", "*", "NamedSchema", "{", "return", "&", "NamedSchema", "{", "Name", ":", "name", ",", "Value", ":", "value", "}", "\n", "}" ]
// NewNamedSchema creates and returns a new object
[ "NewNamedSchema", "creates", "and", "returns", "a", "new", "object" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L183-L185
18,557
googleapis/gnostic
jsonschema/models.go
namedSchemaArrayElementWithName
func namedSchemaArrayElementWithName(array *[]*NamedSchema, name string) *Schema { if array == nil { return nil } for _, pair := range *array { if pair.Name == name { return pair.Value } } return nil }
go
func namedSchemaArrayElementWithName(array *[]*NamedSchema, name string) *Schema { if array == nil { return nil } for _, pair := range *array { if pair.Name == name { return pair.Value } } return nil }
[ "func", "namedSchemaArrayElementWithName", "(", "array", "*", "[", "]", "*", "NamedSchema", ",", "name", "string", ")", "*", "Schema", "{", "if", "array", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "pair", ":=", "range", "*", "array", "{", "if", "pair", ".", "Name", "==", "name", "{", "return", "pair", ".", "Value", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Access named subschemas by name
[ "Access", "named", "subschemas", "by", "name" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L196-L206
18,558
googleapis/gnostic
jsonschema/models.go
PropertyWithName
func (s *Schema) PropertyWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.Properties, name) }
go
func (s *Schema) PropertyWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.Properties, name) }
[ "func", "(", "s", "*", "Schema", ")", "PropertyWithName", "(", "name", "string", ")", "*", "Schema", "{", "return", "namedSchemaArrayElementWithName", "(", "s", ".", "Properties", ",", "name", ")", "\n", "}" ]
// PropertyWithName returns the selected element.
[ "PropertyWithName", "returns", "the", "selected", "element", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L209-L211
18,559
googleapis/gnostic
jsonschema/models.go
PatternPropertyWithName
func (s *Schema) PatternPropertyWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.PatternProperties, name) }
go
func (s *Schema) PatternPropertyWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.PatternProperties, name) }
[ "func", "(", "s", "*", "Schema", ")", "PatternPropertyWithName", "(", "name", "string", ")", "*", "Schema", "{", "return", "namedSchemaArrayElementWithName", "(", "s", ".", "PatternProperties", ",", "name", ")", "\n", "}" ]
// PatternPropertyWithName returns the selected element.
[ "PatternPropertyWithName", "returns", "the", "selected", "element", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L214-L216
18,560
googleapis/gnostic
jsonschema/models.go
DefinitionWithName
func (s *Schema) DefinitionWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.Definitions, name) }
go
func (s *Schema) DefinitionWithName(name string) *Schema { return namedSchemaArrayElementWithName(s.Definitions, name) }
[ "func", "(", "s", "*", "Schema", ")", "DefinitionWithName", "(", "name", "string", ")", "*", "Schema", "{", "return", "namedSchemaArrayElementWithName", "(", "s", ".", "Definitions", ",", "name", ")", "\n", "}" ]
// DefinitionWithName returns the selected element.
[ "DefinitionWithName", "returns", "the", "selected", "element", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L219-L221
18,561
googleapis/gnostic
jsonschema/models.go
AddProperty
func (s *Schema) AddProperty(name string, property *Schema) { *s.Properties = append(*s.Properties, NewNamedSchema(name, property)) }
go
func (s *Schema) AddProperty(name string, property *Schema) { *s.Properties = append(*s.Properties, NewNamedSchema(name, property)) }
[ "func", "(", "s", "*", "Schema", ")", "AddProperty", "(", "name", "string", ",", "property", "*", "Schema", ")", "{", "*", "s", ".", "Properties", "=", "append", "(", "*", "s", ".", "Properties", ",", "NewNamedSchema", "(", "name", ",", "property", ")", ")", "\n", "}" ]
// AddProperty adds a named property.
[ "AddProperty", "adds", "a", "named", "property", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/jsonschema/models.go#L224-L226
18,562
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
lowerFirst
func lowerFirst(s string) string { if s == "" { return "" } r, n := utf8.DecodeRuneInString(s) return string(unicode.ToLower(r)) + s[n:] }
go
func lowerFirst(s string) string { if s == "" { return "" } r, n := utf8.DecodeRuneInString(s) return string(unicode.ToLower(r)) + s[n:] }
[ "func", "lowerFirst", "(", "s", "string", ")", "string", "{", "if", "s", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "r", ",", "n", ":=", "utf8", ".", "DecodeRuneInString", "(", "s", ")", "\n", "return", "string", "(", "unicode", ".", "ToLower", "(", "r", ")", ")", "+", "s", "[", "n", ":", "]", "\n", "}" ]
// convert the first character of a string to lower case
[ "convert", "the", "first", "character", "of", "a", "string", "to", "lower", "case" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L36-L42
18,563
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
ReadSection
func ReadSection(text string, level int) (section *Section) { titlePattern := regexp.MustCompile("^" + strings.Repeat("#", level) + " .*$") subtitlePattern := regexp.MustCompile("^" + strings.Repeat("#", level+1) + " .*$") section = &Section{Level: level, Text: text} lines := strings.Split(string(text), "\n") subsection := "" for i, line := range lines { if i == 0 && titlePattern.Match([]byte(line)) { section.Title = line } else if subtitlePattern.Match([]byte(line)) { // we've found a subsection title. // if there's a subsection that we've already been reading, save it if len(subsection) != 0 { child := ReadSection(subsection, level+1) section.Children = append(section.Children, child) } // start a new subsection subsection = line + "\n" } else { // add to the subsection we've been reading subsection += line + "\n" } } // if this section has subsections, save the last one if len(section.Children) > 0 { child := ReadSection(subsection, level+1) section.Children = append(section.Children, child) } return }
go
func ReadSection(text string, level int) (section *Section) { titlePattern := regexp.MustCompile("^" + strings.Repeat("#", level) + " .*$") subtitlePattern := regexp.MustCompile("^" + strings.Repeat("#", level+1) + " .*$") section = &Section{Level: level, Text: text} lines := strings.Split(string(text), "\n") subsection := "" for i, line := range lines { if i == 0 && titlePattern.Match([]byte(line)) { section.Title = line } else if subtitlePattern.Match([]byte(line)) { // we've found a subsection title. // if there's a subsection that we've already been reading, save it if len(subsection) != 0 { child := ReadSection(subsection, level+1) section.Children = append(section.Children, child) } // start a new subsection subsection = line + "\n" } else { // add to the subsection we've been reading subsection += line + "\n" } } // if this section has subsections, save the last one if len(section.Children) > 0 { child := ReadSection(subsection, level+1) section.Children = append(section.Children, child) } return }
[ "func", "ReadSection", "(", "text", "string", ",", "level", "int", ")", "(", "section", "*", "Section", ")", "{", "titlePattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", "+", "strings", ".", "Repeat", "(", "\"", "\"", ",", "level", ")", "+", "\"", "\"", ")", "\n", "subtitlePattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", "+", "strings", ".", "Repeat", "(", "\"", "\"", ",", "level", "+", "1", ")", "+", "\"", "\"", ")", "\n\n", "section", "=", "&", "Section", "{", "Level", ":", "level", ",", "Text", ":", "text", "}", "\n", "lines", ":=", "strings", ".", "Split", "(", "string", "(", "text", ")", ",", "\"", "\\n", "\"", ")", "\n", "subsection", ":=", "\"", "\"", "\n", "for", "i", ",", "line", ":=", "range", "lines", "{", "if", "i", "==", "0", "&&", "titlePattern", ".", "Match", "(", "[", "]", "byte", "(", "line", ")", ")", "{", "section", ".", "Title", "=", "line", "\n", "}", "else", "if", "subtitlePattern", ".", "Match", "(", "[", "]", "byte", "(", "line", ")", ")", "{", "// we've found a subsection title.", "// if there's a subsection that we've already been reading, save it", "if", "len", "(", "subsection", ")", "!=", "0", "{", "child", ":=", "ReadSection", "(", "subsection", ",", "level", "+", "1", ")", "\n", "section", ".", "Children", "=", "append", "(", "section", ".", "Children", ",", "child", ")", "\n", "}", "\n", "// start a new subsection", "subsection", "=", "line", "+", "\"", "\\n", "\"", "\n", "}", "else", "{", "// add to the subsection we've been reading", "subsection", "+=", "line", "+", "\"", "\\n", "\"", "\n", "}", "\n", "}", "\n", "// if this section has subsections, save the last one", "if", "len", "(", "section", ".", "Children", ")", ">", "0", "{", "child", ":=", "ReadSection", "(", "subsection", ",", "level", "+", "1", ")", "\n", "section", ".", "Children", "=", "append", "(", "section", ".", "Children", ",", "child", ")", "\n", "}", "\n", "return", "\n", "}" ]
// ReadSection reads a section of the OpenAPI Specification, recursively dividing it into subsections
[ "ReadSection", "reads", "a", "section", "of", "the", "OpenAPI", "Specification", "recursively", "dividing", "it", "into", "subsections" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L53-L83
18,564
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
Display
func (s *Section) Display(section string) { if len(s.Children) == 0 { //fmt.Printf("%s\n", s.Text) } else { for i, child := range s.Children { var subsection string if section == "" { subsection = fmt.Sprintf("%d", i) } else { subsection = fmt.Sprintf("%s.%d", section, i) } fmt.Printf("%-12s %s\n", subsection, child.NiceTitle()) child.Display(subsection) } } }
go
func (s *Section) Display(section string) { if len(s.Children) == 0 { //fmt.Printf("%s\n", s.Text) } else { for i, child := range s.Children { var subsection string if section == "" { subsection = fmt.Sprintf("%d", i) } else { subsection = fmt.Sprintf("%s.%d", section, i) } fmt.Printf("%-12s %s\n", subsection, child.NiceTitle()) child.Display(subsection) } } }
[ "func", "(", "s", "*", "Section", ")", "Display", "(", "section", "string", ")", "{", "if", "len", "(", "s", ".", "Children", ")", "==", "0", "{", "//fmt.Printf(\"%s\\n\", s.Text)", "}", "else", "{", "for", "i", ",", "child", ":=", "range", "s", ".", "Children", "{", "var", "subsection", "string", "\n", "if", "section", "==", "\"", "\"", "{", "subsection", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "i", ")", "\n", "}", "else", "{", "subsection", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "section", ",", "i", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "subsection", ",", "child", ".", "NiceTitle", "(", ")", ")", "\n", "child", ".", "Display", "(", "subsection", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Display recursively displays a section of the specification.
[ "Display", "recursively", "displays", "a", "section", "of", "the", "specification", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L86-L101
18,565
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
stripLink
func stripLink(input string) (output string) { stringPattern := regexp.MustCompile("^(.*)$") stringWithLinkPattern := regexp.MustCompile("^<a .*</a>(.*)$") if matches := stringWithLinkPattern.FindSubmatch([]byte(input)); matches != nil { return string(matches[1]) } else if matches := stringPattern.FindSubmatch([]byte(input)); matches != nil { return string(matches[1]) } else { return input } }
go
func stripLink(input string) (output string) { stringPattern := regexp.MustCompile("^(.*)$") stringWithLinkPattern := regexp.MustCompile("^<a .*</a>(.*)$") if matches := stringWithLinkPattern.FindSubmatch([]byte(input)); matches != nil { return string(matches[1]) } else if matches := stringPattern.FindSubmatch([]byte(input)); matches != nil { return string(matches[1]) } else { return input } }
[ "func", "stripLink", "(", "input", "string", ")", "(", "output", "string", ")", "{", "stringPattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n", "stringWithLinkPattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n", "if", "matches", ":=", "stringWithLinkPattern", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "input", ")", ")", ";", "matches", "!=", "nil", "{", "return", "string", "(", "matches", "[", "1", "]", ")", "\n", "}", "else", "if", "matches", ":=", "stringPattern", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "input", ")", ")", ";", "matches", "!=", "nil", "{", "return", "string", "(", "matches", "[", "1", "]", ")", "\n", "}", "else", "{", "return", "input", "\n", "}", "\n", "}" ]
// remove a link from a string, leaving only the text that follows it // if there is no link, just return the string
[ "remove", "a", "link", "from", "a", "string", "leaving", "only", "the", "text", "that", "follows", "it", "if", "there", "is", "no", "link", "just", "return", "the", "string" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L105-L115
18,566
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
parseFixedFields
func parseFixedFields(input string, schemaObject *SchemaObject) { lines := strings.Split(input, "\n") for _, line := range lines { // replace escaped bars with "OR", assuming these are used to describe union types line = strings.Replace(line, " \\| ", " OR ", -1) // split the table on the remaining bars parts := strings.Split(line, "|") if len(parts) > 1 { fieldName := strings.Trim(stripLink(parts[0]), " ") if fieldName != "Field Name" && fieldName != "---" { if len(parts) == 3 || len(parts) == 4 { // this is what we expect } else { log.Printf("ERROR: %+v", parts) } typeName := parts[1] typeName = strings.Replace(typeName, "{expression}", "Expression", -1) typeName = strings.Trim(typeName, " ") typeName = strings.Replace(typeName, "`", "", -1) typeName = removeMarkdownLinks(typeName) typeName = strings.Replace(typeName, " ", "", -1) typeName = strings.Replace(typeName, "Object", "", -1) isArray := false if typeName[0] == '[' && typeName[len(typeName)-1] == ']' { typeName = typeName[1 : len(typeName)-1] isArray = true } isMap := false mapPattern := regexp.MustCompile("^Mapstring,\\[(.*)\\]$") if matches := mapPattern.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } else { // match map[string,<typename>] mapPattern2 := regexp.MustCompile("^Map\\[string,(.+)\\]$") if matches := mapPattern2.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } } description := strings.Trim(parts[len(parts)-1], " ") description = removeMarkdownLinks(description) description = strings.Replace(description, "\n", " ", -1) requiredLabel1 := "**Required.** " requiredLabel2 := "**REQUIRED**." if strings.Contains(description, requiredLabel1) || strings.Contains(description, requiredLabel2) { // only include required values if their "Validity" is "Any" or if no validity is specified valid := true if len(parts) == 4 { validity := parts[2] if strings.Contains(validity, "Any") { valid = true } else { valid = false } } if valid { schemaObject.RequiredFields = append(schemaObject.RequiredFields, fieldName) } description = strings.Replace(description, requiredLabel1, "", -1) description = strings.Replace(description, requiredLabel2, "", -1) } schemaField := SchemaObjectField{ Name: fieldName, Type: typeName, IsArray: isArray, IsMap: isMap, Description: description, } schemaObject.FixedFields = append(schemaObject.FixedFields, schemaField) } } } }
go
func parseFixedFields(input string, schemaObject *SchemaObject) { lines := strings.Split(input, "\n") for _, line := range lines { // replace escaped bars with "OR", assuming these are used to describe union types line = strings.Replace(line, " \\| ", " OR ", -1) // split the table on the remaining bars parts := strings.Split(line, "|") if len(parts) > 1 { fieldName := strings.Trim(stripLink(parts[0]), " ") if fieldName != "Field Name" && fieldName != "---" { if len(parts) == 3 || len(parts) == 4 { // this is what we expect } else { log.Printf("ERROR: %+v", parts) } typeName := parts[1] typeName = strings.Replace(typeName, "{expression}", "Expression", -1) typeName = strings.Trim(typeName, " ") typeName = strings.Replace(typeName, "`", "", -1) typeName = removeMarkdownLinks(typeName) typeName = strings.Replace(typeName, " ", "", -1) typeName = strings.Replace(typeName, "Object", "", -1) isArray := false if typeName[0] == '[' && typeName[len(typeName)-1] == ']' { typeName = typeName[1 : len(typeName)-1] isArray = true } isMap := false mapPattern := regexp.MustCompile("^Mapstring,\\[(.*)\\]$") if matches := mapPattern.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } else { // match map[string,<typename>] mapPattern2 := regexp.MustCompile("^Map\\[string,(.+)\\]$") if matches := mapPattern2.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } } description := strings.Trim(parts[len(parts)-1], " ") description = removeMarkdownLinks(description) description = strings.Replace(description, "\n", " ", -1) requiredLabel1 := "**Required.** " requiredLabel2 := "**REQUIRED**." if strings.Contains(description, requiredLabel1) || strings.Contains(description, requiredLabel2) { // only include required values if their "Validity" is "Any" or if no validity is specified valid := true if len(parts) == 4 { validity := parts[2] if strings.Contains(validity, "Any") { valid = true } else { valid = false } } if valid { schemaObject.RequiredFields = append(schemaObject.RequiredFields, fieldName) } description = strings.Replace(description, requiredLabel1, "", -1) description = strings.Replace(description, requiredLabel2, "", -1) } schemaField := SchemaObjectField{ Name: fieldName, Type: typeName, IsArray: isArray, IsMap: isMap, Description: description, } schemaObject.FixedFields = append(schemaObject.FixedFields, schemaField) } } } }
[ "func", "parseFixedFields", "(", "input", "string", ",", "schemaObject", "*", "SchemaObject", ")", "{", "lines", ":=", "strings", ".", "Split", "(", "input", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "// replace escaped bars with \"OR\", assuming these are used to describe union types", "line", "=", "strings", ".", "Replace", "(", "line", ",", "\"", "\\\\", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "// split the table on the remaining bars", "parts", ":=", "strings", ".", "Split", "(", "line", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">", "1", "{", "fieldName", ":=", "strings", ".", "Trim", "(", "stripLink", "(", "parts", "[", "0", "]", ")", ",", "\"", "\"", ")", "\n", "if", "fieldName", "!=", "\"", "\"", "&&", "fieldName", "!=", "\"", "\"", "{", "if", "len", "(", "parts", ")", "==", "3", "||", "len", "(", "parts", ")", "==", "4", "{", "// this is what we expect", "}", "else", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "parts", ")", "\n", "}", "\n\n", "typeName", ":=", "parts", "[", "1", "]", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "strings", ".", "Trim", "(", "typeName", ",", "\"", "\"", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "removeMarkdownLinks", "(", "typeName", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "isArray", ":=", "false", "\n", "if", "typeName", "[", "0", "]", "==", "'['", "&&", "typeName", "[", "len", "(", "typeName", ")", "-", "1", "]", "==", "']'", "{", "typeName", "=", "typeName", "[", "1", ":", "len", "(", "typeName", ")", "-", "1", "]", "\n", "isArray", "=", "true", "\n", "}", "\n", "isMap", ":=", "false", "\n", "mapPattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "if", "matches", ":=", "mapPattern", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "typeName", ")", ")", ";", "matches", "!=", "nil", "{", "typeName", "=", "string", "(", "matches", "[", "1", "]", ")", "\n", "isMap", "=", "true", "\n", "}", "else", "{", "// match map[string,<typename>]", "mapPattern2", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "if", "matches", ":=", "mapPattern2", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "typeName", ")", ")", ";", "matches", "!=", "nil", "{", "typeName", "=", "string", "(", "matches", "[", "1", "]", ")", "\n", "isMap", "=", "true", "\n", "}", "\n", "}", "\n", "description", ":=", "strings", ".", "Trim", "(", "parts", "[", "len", "(", "parts", ")", "-", "1", "]", ",", "\"", "\"", ")", "\n", "description", "=", "removeMarkdownLinks", "(", "description", ")", "\n", "description", "=", "strings", ".", "Replace", "(", "description", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "requiredLabel1", ":=", "\"", "\"", "\n", "requiredLabel2", ":=", "\"", "\"", "\n", "if", "strings", ".", "Contains", "(", "description", ",", "requiredLabel1", ")", "||", "strings", ".", "Contains", "(", "description", ",", "requiredLabel2", ")", "{", "// only include required values if their \"Validity\" is \"Any\" or if no validity is specified", "valid", ":=", "true", "\n", "if", "len", "(", "parts", ")", "==", "4", "{", "validity", ":=", "parts", "[", "2", "]", "\n", "if", "strings", ".", "Contains", "(", "validity", ",", "\"", "\"", ")", "{", "valid", "=", "true", "\n", "}", "else", "{", "valid", "=", "false", "\n", "}", "\n", "}", "\n", "if", "valid", "{", "schemaObject", ".", "RequiredFields", "=", "append", "(", "schemaObject", ".", "RequiredFields", ",", "fieldName", ")", "\n", "}", "\n", "description", "=", "strings", ".", "Replace", "(", "description", ",", "requiredLabel1", ",", "\"", "\"", ",", "-", "1", ")", "\n", "description", "=", "strings", ".", "Replace", "(", "description", ",", "requiredLabel2", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}", "\n", "schemaField", ":=", "SchemaObjectField", "{", "Name", ":", "fieldName", ",", "Type", ":", "typeName", ",", "IsArray", ":", "isArray", ",", "IsMap", ":", "isMap", ",", "Description", ":", "description", ",", "}", "\n", "schemaObject", ".", "FixedFields", "=", "append", "(", "schemaObject", ".", "FixedFields", ",", "schemaField", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// extract the fixed fields from a table in a section
[ "extract", "the", "fixed", "fields", "from", "a", "table", "in", "a", "section" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L138-L217
18,567
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
parsePatternedFields
func parsePatternedFields(input string, schemaObject *SchemaObject) { lines := strings.Split(input, "\n") for _, line := range lines { line = strings.Replace(line, " \\| ", " OR ", -1) parts := strings.Split(line, "|") if len(parts) > 1 { fieldName := strings.Trim(stripLink(parts[0]), " ") fieldName = removeMarkdownLinks(fieldName) if fieldName == "HTTP Status Code" { fieldName = "^([0-9X]{3})$" } if fieldName != "Field Pattern" && fieldName != "---" { typeName := parts[1] typeName = strings.Trim(typeName, " ") typeName = strings.Replace(typeName, "`", "", -1) typeName = removeMarkdownLinks(typeName) typeName = strings.Replace(typeName, " ", "", -1) typeName = strings.Replace(typeName, "Object", "", -1) typeName = strings.Replace(typeName, "{expression}", "Expression", -1) isArray := false if typeName[0] == '[' && typeName[len(typeName)-1] == ']' { typeName = typeName[1 : len(typeName)-1] isArray = true } isMap := false mapPattern := regexp.MustCompile("^Mapstring,\\[(.*)\\]$") if matches := mapPattern.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } description := strings.Trim(parts[len(parts)-1], " ") description = removeMarkdownLinks(description) description = strings.Replace(description, "\n", " ", -1) schemaField := SchemaObjectField{ Name: fieldName, Type: typeName, IsArray: isArray, IsMap: isMap, Description: description, } schemaObject.PatternedFields = append(schemaObject.PatternedFields, schemaField) } } } }
go
func parsePatternedFields(input string, schemaObject *SchemaObject) { lines := strings.Split(input, "\n") for _, line := range lines { line = strings.Replace(line, " \\| ", " OR ", -1) parts := strings.Split(line, "|") if len(parts) > 1 { fieldName := strings.Trim(stripLink(parts[0]), " ") fieldName = removeMarkdownLinks(fieldName) if fieldName == "HTTP Status Code" { fieldName = "^([0-9X]{3})$" } if fieldName != "Field Pattern" && fieldName != "---" { typeName := parts[1] typeName = strings.Trim(typeName, " ") typeName = strings.Replace(typeName, "`", "", -1) typeName = removeMarkdownLinks(typeName) typeName = strings.Replace(typeName, " ", "", -1) typeName = strings.Replace(typeName, "Object", "", -1) typeName = strings.Replace(typeName, "{expression}", "Expression", -1) isArray := false if typeName[0] == '[' && typeName[len(typeName)-1] == ']' { typeName = typeName[1 : len(typeName)-1] isArray = true } isMap := false mapPattern := regexp.MustCompile("^Mapstring,\\[(.*)\\]$") if matches := mapPattern.FindSubmatch([]byte(typeName)); matches != nil { typeName = string(matches[1]) isMap = true } description := strings.Trim(parts[len(parts)-1], " ") description = removeMarkdownLinks(description) description = strings.Replace(description, "\n", " ", -1) schemaField := SchemaObjectField{ Name: fieldName, Type: typeName, IsArray: isArray, IsMap: isMap, Description: description, } schemaObject.PatternedFields = append(schemaObject.PatternedFields, schemaField) } } } }
[ "func", "parsePatternedFields", "(", "input", "string", ",", "schemaObject", "*", "SchemaObject", ")", "{", "lines", ":=", "strings", ".", "Split", "(", "input", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "line", ":=", "range", "lines", "{", "line", "=", "strings", ".", "Replace", "(", "line", ",", "\"", "\\\\", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "parts", ":=", "strings", ".", "Split", "(", "line", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", ">", "1", "{", "fieldName", ":=", "strings", ".", "Trim", "(", "stripLink", "(", "parts", "[", "0", "]", ")", ",", "\"", "\"", ")", "\n", "fieldName", "=", "removeMarkdownLinks", "(", "fieldName", ")", "\n", "if", "fieldName", "==", "\"", "\"", "{", "fieldName", "=", "\"", "\"", "\n", "}", "\n", "if", "fieldName", "!=", "\"", "\"", "&&", "fieldName", "!=", "\"", "\"", "{", "typeName", ":=", "parts", "[", "1", "]", "\n", "typeName", "=", "strings", ".", "Trim", "(", "typeName", ",", "\"", "\"", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "removeMarkdownLinks", "(", "typeName", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "typeName", "=", "strings", ".", "Replace", "(", "typeName", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "isArray", ":=", "false", "\n", "if", "typeName", "[", "0", "]", "==", "'['", "&&", "typeName", "[", "len", "(", "typeName", ")", "-", "1", "]", "==", "']'", "{", "typeName", "=", "typeName", "[", "1", ":", "len", "(", "typeName", ")", "-", "1", "]", "\n", "isArray", "=", "true", "\n", "}", "\n", "isMap", ":=", "false", "\n", "mapPattern", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "\n", "if", "matches", ":=", "mapPattern", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "typeName", ")", ")", ";", "matches", "!=", "nil", "{", "typeName", "=", "string", "(", "matches", "[", "1", "]", ")", "\n", "isMap", "=", "true", "\n", "}", "\n", "description", ":=", "strings", ".", "Trim", "(", "parts", "[", "len", "(", "parts", ")", "-", "1", "]", ",", "\"", "\"", ")", "\n", "description", "=", "removeMarkdownLinks", "(", "description", ")", "\n", "description", "=", "strings", ".", "Replace", "(", "description", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "schemaField", ":=", "SchemaObjectField", "{", "Name", ":", "fieldName", ",", "Type", ":", "typeName", ",", "IsArray", ":", "isArray", ",", "IsMap", ":", "isMap", ",", "Description", ":", "description", ",", "}", "\n", "schemaObject", ".", "PatternedFields", "=", "append", "(", "schemaObject", ".", "PatternedFields", ",", "schemaField", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// extract the patterned fields from a table in a section
[ "extract", "the", "patterned", "fields", "from", "a", "table", "in", "a", "section" ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L220-L267
18,568
googleapis/gnostic
OpenAPIv3/schema-generator/main.go
NewSchemaModel
func NewSchemaModel(filename string) (schemaModel *SchemaModel, err error) { b, err := ioutil.ReadFile("3.0.1.md") if err != nil { return nil, err } // divide the specification into sections document := ReadSection(string(b), 1) document.Display("") // read object names and their details specification := document.Children[4] // fragile! the section title is "Specification" schema := specification.Children[7] // fragile! the section title is "Schema" anchor := regexp.MustCompile("^#### <a name=\"(.*)Object\"") schemaObjects := make([]SchemaObject, 0) for _, section := range schema.Children { if matches := anchor.FindSubmatch([]byte(section.Title)); matches != nil { id := string(matches[1]) schemaObject := SchemaObject{ Name: section.NiceTitle(), ID: id, RequiredFields: nil, } if len(section.Children) > 0 { description := section.Children[0].Text description = removeMarkdownLinks(description) description = strings.Trim(description, " \t\n") description = strings.Replace(description, "\n", " ", -1) schemaObject.Description = description } // is the object extendable? if strings.Contains(section.Text, "Specification Extensions") { schemaObject.Extendable = true } // look for fixed fields for _, child := range section.Children { if child.NiceTitle() == "Fixed Fields" { parseFixedFields(child.Text, &schemaObject) } } // look for patterned fields for _, child := range section.Children { if child.NiceTitle() == "Patterned Fields" { parsePatternedFields(child.Text, &schemaObject) } } schemaObjects = append(schemaObjects, schemaObject) } } return &SchemaModel{Objects: schemaObjects}, nil }
go
func NewSchemaModel(filename string) (schemaModel *SchemaModel, err error) { b, err := ioutil.ReadFile("3.0.1.md") if err != nil { return nil, err } // divide the specification into sections document := ReadSection(string(b), 1) document.Display("") // read object names and their details specification := document.Children[4] // fragile! the section title is "Specification" schema := specification.Children[7] // fragile! the section title is "Schema" anchor := regexp.MustCompile("^#### <a name=\"(.*)Object\"") schemaObjects := make([]SchemaObject, 0) for _, section := range schema.Children { if matches := anchor.FindSubmatch([]byte(section.Title)); matches != nil { id := string(matches[1]) schemaObject := SchemaObject{ Name: section.NiceTitle(), ID: id, RequiredFields: nil, } if len(section.Children) > 0 { description := section.Children[0].Text description = removeMarkdownLinks(description) description = strings.Trim(description, " \t\n") description = strings.Replace(description, "\n", " ", -1) schemaObject.Description = description } // is the object extendable? if strings.Contains(section.Text, "Specification Extensions") { schemaObject.Extendable = true } // look for fixed fields for _, child := range section.Children { if child.NiceTitle() == "Fixed Fields" { parseFixedFields(child.Text, &schemaObject) } } // look for patterned fields for _, child := range section.Children { if child.NiceTitle() == "Patterned Fields" { parsePatternedFields(child.Text, &schemaObject) } } schemaObjects = append(schemaObjects, schemaObject) } } return &SchemaModel{Objects: schemaObjects}, nil }
[ "func", "NewSchemaModel", "(", "filename", "string", ")", "(", "schemaModel", "*", "SchemaModel", ",", "err", "error", ")", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// divide the specification into sections", "document", ":=", "ReadSection", "(", "string", "(", "b", ")", ",", "1", ")", "\n", "document", ".", "Display", "(", "\"", "\"", ")", "\n\n", "// read object names and their details", "specification", ":=", "document", ".", "Children", "[", "4", "]", "// fragile! the section title is \"Specification\"", "\n", "schema", ":=", "specification", ".", "Children", "[", "7", "]", "// fragile! the section title is \"Schema\"", "\n", "anchor", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\"", "\\\"", "\"", ")", "\n", "schemaObjects", ":=", "make", "(", "[", "]", "SchemaObject", ",", "0", ")", "\n", "for", "_", ",", "section", ":=", "range", "schema", ".", "Children", "{", "if", "matches", ":=", "anchor", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "section", ".", "Title", ")", ")", ";", "matches", "!=", "nil", "{", "id", ":=", "string", "(", "matches", "[", "1", "]", ")", "\n\n", "schemaObject", ":=", "SchemaObject", "{", "Name", ":", "section", ".", "NiceTitle", "(", ")", ",", "ID", ":", "id", ",", "RequiredFields", ":", "nil", ",", "}", "\n\n", "if", "len", "(", "section", ".", "Children", ")", ">", "0", "{", "description", ":=", "section", ".", "Children", "[", "0", "]", ".", "Text", "\n", "description", "=", "removeMarkdownLinks", "(", "description", ")", "\n", "description", "=", "strings", ".", "Trim", "(", "description", ",", "\"", "\\t", "\\n", "\"", ")", "\n", "description", "=", "strings", ".", "Replace", "(", "description", ",", "\"", "\\n", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "schemaObject", ".", "Description", "=", "description", "\n", "}", "\n\n", "// is the object extendable?", "if", "strings", ".", "Contains", "(", "section", ".", "Text", ",", "\"", "\"", ")", "{", "schemaObject", ".", "Extendable", "=", "true", "\n", "}", "\n\n", "// look for fixed fields", "for", "_", ",", "child", ":=", "range", "section", ".", "Children", "{", "if", "child", ".", "NiceTitle", "(", ")", "==", "\"", "\"", "{", "parseFixedFields", "(", "child", ".", "Text", ",", "&", "schemaObject", ")", "\n", "}", "\n", "}", "\n\n", "// look for patterned fields", "for", "_", ",", "child", ":=", "range", "section", ".", "Children", "{", "if", "child", ".", "NiceTitle", "(", ")", "==", "\"", "\"", "{", "parsePatternedFields", "(", "child", ".", "Text", ",", "&", "schemaObject", ")", "\n", "}", "\n", "}", "\n\n", "schemaObjects", "=", "append", "(", "schemaObjects", ",", "schemaObject", ")", "\n", "}", "\n", "}", "\n\n", "return", "&", "SchemaModel", "{", "Objects", ":", "schemaObjects", "}", ",", "nil", "\n", "}" ]
// NewSchemaModel returns a new SchemaModel.
[ "NewSchemaModel", "returns", "a", "new", "SchemaModel", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/OpenAPIv3/schema-generator/main.go#L304-L363
18,569
googleapis/gnostic
compiler/error.go
NewError
func NewError(context *Context, message string) *Error { return &Error{Context: context, Message: message} }
go
func NewError(context *Context, message string) *Error { return &Error{Context: context, Message: message} }
[ "func", "NewError", "(", "context", "*", "Context", ",", "message", "string", ")", "*", "Error", "{", "return", "&", "Error", "{", "Context", ":", "context", ",", "Message", ":", "message", "}", "\n", "}" ]
// NewError creates an Error.
[ "NewError", "creates", "an", "Error", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/error.go#L24-L26
18,570
googleapis/gnostic
compiler/error.go
Error
func (err *Error) Error() string { if err.Context == nil { return "ERROR " + err.Message } return "ERROR " + err.Context.Description() + " " + err.Message }
go
func (err *Error) Error() string { if err.Context == nil { return "ERROR " + err.Message } return "ERROR " + err.Context.Description() + " " + err.Message }
[ "func", "(", "err", "*", "Error", ")", "Error", "(", ")", "string", "{", "if", "err", ".", "Context", "==", "nil", "{", "return", "\"", "\"", "+", "err", ".", "Message", "\n", "}", "\n", "return", "\"", "\"", "+", "err", ".", "Context", ".", "Description", "(", ")", "+", "\"", "\"", "+", "err", ".", "Message", "\n", "}" ]
// Error returns the string value of an Error.
[ "Error", "returns", "the", "string", "value", "of", "an", "Error", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/error.go#L29-L34
18,571
googleapis/gnostic
compiler/error.go
NewErrorGroupOrNil
func NewErrorGroupOrNil(errors []error) error { if len(errors) == 0 { return nil } else if len(errors) == 1 { return errors[0] } else { return &ErrorGroup{Errors: errors} } }
go
func NewErrorGroupOrNil(errors []error) error { if len(errors) == 0 { return nil } else if len(errors) == 1 { return errors[0] } else { return &ErrorGroup{Errors: errors} } }
[ "func", "NewErrorGroupOrNil", "(", "errors", "[", "]", "error", ")", "error", "{", "if", "len", "(", "errors", ")", "==", "0", "{", "return", "nil", "\n", "}", "else", "if", "len", "(", "errors", ")", "==", "1", "{", "return", "errors", "[", "0", "]", "\n", "}", "else", "{", "return", "&", "ErrorGroup", "{", "Errors", ":", "errors", "}", "\n", "}", "\n", "}" ]
// NewErrorGroupOrNil returns a new ErrorGroup for a slice of errors or nil if the slice is empty.
[ "NewErrorGroupOrNil", "returns", "a", "new", "ErrorGroup", "for", "a", "slice", "of", "errors", "or", "nil", "if", "the", "slice", "is", "empty", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/compiler/error.go#L42-L50
18,572
googleapis/gnostic
gnostic.go
getOpenAPIVersionFromInfo
func getOpenAPIVersionFromInfo(info interface{}) int { m, ok := compiler.UnpackMap(info) if !ok { return SourceFormatUnknown } swagger, ok := compiler.MapValueForKey(m, "swagger").(string) if ok && strings.HasPrefix(swagger, "2.0") { return SourceFormatOpenAPI2 } openapi, ok := compiler.MapValueForKey(m, "openapi").(string) if ok && strings.HasPrefix(openapi, "3.0") { return SourceFormatOpenAPI3 } kind, ok := compiler.MapValueForKey(m, "kind").(string) if ok && kind == "discovery#restDescription" { return SourceFormatDiscovery } return SourceFormatUnknown }
go
func getOpenAPIVersionFromInfo(info interface{}) int { m, ok := compiler.UnpackMap(info) if !ok { return SourceFormatUnknown } swagger, ok := compiler.MapValueForKey(m, "swagger").(string) if ok && strings.HasPrefix(swagger, "2.0") { return SourceFormatOpenAPI2 } openapi, ok := compiler.MapValueForKey(m, "openapi").(string) if ok && strings.HasPrefix(openapi, "3.0") { return SourceFormatOpenAPI3 } kind, ok := compiler.MapValueForKey(m, "kind").(string) if ok && kind == "discovery#restDescription" { return SourceFormatDiscovery } return SourceFormatUnknown }
[ "func", "getOpenAPIVersionFromInfo", "(", "info", "interface", "{", "}", ")", "int", "{", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "info", ")", "\n", "if", "!", "ok", "{", "return", "SourceFormatUnknown", "\n", "}", "\n", "swagger", ",", "ok", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", ".", "(", "string", ")", "\n", "if", "ok", "&&", "strings", ".", "HasPrefix", "(", "swagger", ",", "\"", "\"", ")", "{", "return", "SourceFormatOpenAPI2", "\n", "}", "\n", "openapi", ",", "ok", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", ".", "(", "string", ")", "\n", "if", "ok", "&&", "strings", ".", "HasPrefix", "(", "openapi", ",", "\"", "\"", ")", "{", "return", "SourceFormatOpenAPI3", "\n", "}", "\n", "kind", ",", "ok", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", ".", "(", "string", ")", "\n", "if", "ok", "&&", "kind", "==", "\"", "\"", "{", "return", "SourceFormatDiscovery", "\n", "}", "\n", "return", "SourceFormatUnknown", "\n", "}" ]
// Determine the version of an OpenAPI description read from JSON or YAML.
[ "Determine", "the", "version", "of", "an", "OpenAPI", "description", "read", "from", "JSON", "or", "YAML", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L65-L83
18,573
googleapis/gnostic
gnostic.go
newGnostic
func newGnostic() *Gnostic { g := &Gnostic{} // Option fields initialize to their default values. g.usage = ` Usage: gnostic SOURCE [OPTIONS] SOURCE is the filename or URL of an API description. Options: --pb-out=PATH Write a binary proto to the specified location. --text-out=PATH Write a text proto to the specified location. --json-out=PATH Write a json API description to the specified location. --yaml-out=PATH Write a yaml API description to the specified location. --errors-out=PATH Write compilation errors to the specified location. --messages-out=PATH Write messages generated by plugins to the specified location. Messages from all plugin invocations are written to a single common file. --PLUGIN-out=PATH Run the plugin named gnostic-PLUGIN and write results to the specified location. --PLUGIN Run the plugin named gnostic-PLUGIN but don't write any results. Used for plugins that return messages only. PLUGIN must not match any other gnostic option. --x-EXTENSION Use the extension named gnostic-x-EXTENSION to process OpenAPI specification extensions. --resolve-refs Explicitly resolve $ref references. This could have problems with recursive definitions. --time-plugins Report plugin runtimes. ` // Initialize internal structures. g.pluginCalls = make([]*pluginCall, 0) g.extensionHandlers = make([]compiler.ExtensionHandler, 0) return g }
go
func newGnostic() *Gnostic { g := &Gnostic{} // Option fields initialize to their default values. g.usage = ` Usage: gnostic SOURCE [OPTIONS] SOURCE is the filename or URL of an API description. Options: --pb-out=PATH Write a binary proto to the specified location. --text-out=PATH Write a text proto to the specified location. --json-out=PATH Write a json API description to the specified location. --yaml-out=PATH Write a yaml API description to the specified location. --errors-out=PATH Write compilation errors to the specified location. --messages-out=PATH Write messages generated by plugins to the specified location. Messages from all plugin invocations are written to a single common file. --PLUGIN-out=PATH Run the plugin named gnostic-PLUGIN and write results to the specified location. --PLUGIN Run the plugin named gnostic-PLUGIN but don't write any results. Used for plugins that return messages only. PLUGIN must not match any other gnostic option. --x-EXTENSION Use the extension named gnostic-x-EXTENSION to process OpenAPI specification extensions. --resolve-refs Explicitly resolve $ref references. This could have problems with recursive definitions. --time-plugins Report plugin runtimes. ` // Initialize internal structures. g.pluginCalls = make([]*pluginCall, 0) g.extensionHandlers = make([]compiler.ExtensionHandler, 0) return g }
[ "func", "newGnostic", "(", ")", "*", "Gnostic", "{", "g", ":=", "&", "Gnostic", "{", "}", "\n", "// Option fields initialize to their default values.", "g", ".", "usage", "=", "`\nUsage: gnostic SOURCE [OPTIONS]\n SOURCE is the filename or URL of an API description.\nOptions:\n --pb-out=PATH Write a binary proto to the specified location.\n --text-out=PATH Write a text proto to the specified location.\n --json-out=PATH Write a json API description to the specified location.\n --yaml-out=PATH Write a yaml API description to the specified location.\n --errors-out=PATH Write compilation errors to the specified location.\n --messages-out=PATH Write messages generated by plugins to the specified\n location. Messages from all plugin invocations are\n written to a single common file.\n --PLUGIN-out=PATH Run the plugin named gnostic-PLUGIN and write results\n to the specified location.\n --PLUGIN Run the plugin named gnostic-PLUGIN but don't write any\n results. Used for plugins that return messages only.\n PLUGIN must not match any other gnostic option.\n --x-EXTENSION Use the extension named gnostic-x-EXTENSION\n to process OpenAPI specification extensions.\n --resolve-refs Explicitly resolve $ref references.\n This could have problems with recursive definitions.\n --time-plugins Report plugin runtimes.\n`", "\n", "// Initialize internal structures.", "g", ".", "pluginCalls", "=", "make", "(", "[", "]", "*", "pluginCall", ",", "0", ")", "\n", "g", ".", "extensionHandlers", "=", "make", "(", "[", "]", "compiler", ".", "ExtensionHandler", ",", "0", ")", "\n", "return", "g", "\n", "}" ]
// Initialize a structure to store global application state.
[ "Initialize", "a", "structure", "to", "store", "global", "application", "state", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L266-L296
18,574
googleapis/gnostic
gnostic.go
readOptions
func (g *Gnostic) readOptions() { // plugin processing matches patterns of the form "--PLUGIN-out=PATH" and "--PLUGIN_out=PATH" pluginRegex := regexp.MustCompile("--(.+)[-_]out=(.+)") // extension processing matches patterns of the form "--x-EXTENSION" extensionRegex := regexp.MustCompile("--x-(.+)") for i, arg := range os.Args { if i == 0 { continue // skip the tool name } var m [][]byte if m = pluginRegex.FindSubmatch([]byte(arg)); m != nil { pluginName := string(m[1]) invocation := string(m[2]) switch pluginName { case "pb": g.binaryOutputPath = invocation case "text": g.textOutputPath = invocation case "json": g.jsonOutputPath = invocation case "yaml": g.yamlOutputPath = invocation case "errors": g.errorOutputPath = invocation case "messages": g.messageOutputPath = invocation default: p := &pluginCall{Name: pluginName, Invocation: invocation} g.pluginCalls = append(g.pluginCalls, p) } } else if m = extensionRegex.FindSubmatch([]byte(arg)); m != nil { extensionName := string(m[1]) extensionHandler := compiler.ExtensionHandler{Name: extensionPrefix + extensionName} g.extensionHandlers = append(g.extensionHandlers, extensionHandler) } else if arg == "--resolve-refs" { g.resolveReferences = true } else if arg == "--time-plugins" { g.timePlugins = true } else if arg[0] == '-' && arg[1] == '-' { // try letting the option specify a plugin with no output files (or unwanted output files) // this is useful for calling plugins like linters that only return messages p := &pluginCall{Name: arg[2:len(arg)], Invocation: "!"} g.pluginCalls = append(g.pluginCalls, p) } else if arg[0] == '-' { fmt.Fprintf(os.Stderr, "Unknown option: %s.\n%s\n", arg, g.usage) os.Exit(-1) } else { g.sourceName = arg } } }
go
func (g *Gnostic) readOptions() { // plugin processing matches patterns of the form "--PLUGIN-out=PATH" and "--PLUGIN_out=PATH" pluginRegex := regexp.MustCompile("--(.+)[-_]out=(.+)") // extension processing matches patterns of the form "--x-EXTENSION" extensionRegex := regexp.MustCompile("--x-(.+)") for i, arg := range os.Args { if i == 0 { continue // skip the tool name } var m [][]byte if m = pluginRegex.FindSubmatch([]byte(arg)); m != nil { pluginName := string(m[1]) invocation := string(m[2]) switch pluginName { case "pb": g.binaryOutputPath = invocation case "text": g.textOutputPath = invocation case "json": g.jsonOutputPath = invocation case "yaml": g.yamlOutputPath = invocation case "errors": g.errorOutputPath = invocation case "messages": g.messageOutputPath = invocation default: p := &pluginCall{Name: pluginName, Invocation: invocation} g.pluginCalls = append(g.pluginCalls, p) } } else if m = extensionRegex.FindSubmatch([]byte(arg)); m != nil { extensionName := string(m[1]) extensionHandler := compiler.ExtensionHandler{Name: extensionPrefix + extensionName} g.extensionHandlers = append(g.extensionHandlers, extensionHandler) } else if arg == "--resolve-refs" { g.resolveReferences = true } else if arg == "--time-plugins" { g.timePlugins = true } else if arg[0] == '-' && arg[1] == '-' { // try letting the option specify a plugin with no output files (or unwanted output files) // this is useful for calling plugins like linters that only return messages p := &pluginCall{Name: arg[2:len(arg)], Invocation: "!"} g.pluginCalls = append(g.pluginCalls, p) } else if arg[0] == '-' { fmt.Fprintf(os.Stderr, "Unknown option: %s.\n%s\n", arg, g.usage) os.Exit(-1) } else { g.sourceName = arg } } }
[ "func", "(", "g", "*", "Gnostic", ")", "readOptions", "(", ")", "{", "// plugin processing matches patterns of the form \"--PLUGIN-out=PATH\" and \"--PLUGIN_out=PATH\"", "pluginRegex", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n\n", "// extension processing matches patterns of the form \"--x-EXTENSION\"", "extensionRegex", ":=", "regexp", ".", "MustCompile", "(", "\"", "\"", ")", "\n\n", "for", "i", ",", "arg", ":=", "range", "os", ".", "Args", "{", "if", "i", "==", "0", "{", "continue", "// skip the tool name", "\n", "}", "\n", "var", "m", "[", "]", "[", "]", "byte", "\n", "if", "m", "=", "pluginRegex", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "arg", ")", ")", ";", "m", "!=", "nil", "{", "pluginName", ":=", "string", "(", "m", "[", "1", "]", ")", "\n", "invocation", ":=", "string", "(", "m", "[", "2", "]", ")", "\n", "switch", "pluginName", "{", "case", "\"", "\"", ":", "g", ".", "binaryOutputPath", "=", "invocation", "\n", "case", "\"", "\"", ":", "g", ".", "textOutputPath", "=", "invocation", "\n", "case", "\"", "\"", ":", "g", ".", "jsonOutputPath", "=", "invocation", "\n", "case", "\"", "\"", ":", "g", ".", "yamlOutputPath", "=", "invocation", "\n", "case", "\"", "\"", ":", "g", ".", "errorOutputPath", "=", "invocation", "\n", "case", "\"", "\"", ":", "g", ".", "messageOutputPath", "=", "invocation", "\n", "default", ":", "p", ":=", "&", "pluginCall", "{", "Name", ":", "pluginName", ",", "Invocation", ":", "invocation", "}", "\n", "g", ".", "pluginCalls", "=", "append", "(", "g", ".", "pluginCalls", ",", "p", ")", "\n", "}", "\n", "}", "else", "if", "m", "=", "extensionRegex", ".", "FindSubmatch", "(", "[", "]", "byte", "(", "arg", ")", ")", ";", "m", "!=", "nil", "{", "extensionName", ":=", "string", "(", "m", "[", "1", "]", ")", "\n", "extensionHandler", ":=", "compiler", ".", "ExtensionHandler", "{", "Name", ":", "extensionPrefix", "+", "extensionName", "}", "\n", "g", ".", "extensionHandlers", "=", "append", "(", "g", ".", "extensionHandlers", ",", "extensionHandler", ")", "\n", "}", "else", "if", "arg", "==", "\"", "\"", "{", "g", ".", "resolveReferences", "=", "true", "\n", "}", "else", "if", "arg", "==", "\"", "\"", "{", "g", ".", "timePlugins", "=", "true", "\n", "}", "else", "if", "arg", "[", "0", "]", "==", "'-'", "&&", "arg", "[", "1", "]", "==", "'-'", "{", "// try letting the option specify a plugin with no output files (or unwanted output files)", "// this is useful for calling plugins like linters that only return messages", "p", ":=", "&", "pluginCall", "{", "Name", ":", "arg", "[", "2", ":", "len", "(", "arg", ")", "]", ",", "Invocation", ":", "\"", "\"", "}", "\n", "g", ".", "pluginCalls", "=", "append", "(", "g", ".", "pluginCalls", ",", "p", ")", "\n", "}", "else", "if", "arg", "[", "0", "]", "==", "'-'", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\\n", "\"", ",", "arg", ",", "g", ".", "usage", ")", "\n", "os", ".", "Exit", "(", "-", "1", ")", "\n", "}", "else", "{", "g", ".", "sourceName", "=", "arg", "\n", "}", "\n", "}", "\n", "}" ]
// Parse command-line options.
[ "Parse", "command", "-", "line", "options", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L299-L351
18,575
googleapis/gnostic
gnostic.go
validateOptions
func (g *Gnostic) validateOptions() { if g.binaryOutputPath == "" && g.textOutputPath == "" && g.yamlOutputPath == "" && g.jsonOutputPath == "" && g.errorOutputPath == "" && len(g.pluginCalls) == 0 { fmt.Fprintf(os.Stderr, "Missing output directives.\n%s\n", g.usage) os.Exit(-1) } if g.sourceName == "" { fmt.Fprintf(os.Stderr, "No input specified.\n%s\n", g.usage) os.Exit(-1) } // If we get here and the error output is unspecified, write errors to stderr. if g.errorOutputPath == "" { g.errorOutputPath = "=" } }
go
func (g *Gnostic) validateOptions() { if g.binaryOutputPath == "" && g.textOutputPath == "" && g.yamlOutputPath == "" && g.jsonOutputPath == "" && g.errorOutputPath == "" && len(g.pluginCalls) == 0 { fmt.Fprintf(os.Stderr, "Missing output directives.\n%s\n", g.usage) os.Exit(-1) } if g.sourceName == "" { fmt.Fprintf(os.Stderr, "No input specified.\n%s\n", g.usage) os.Exit(-1) } // If we get here and the error output is unspecified, write errors to stderr. if g.errorOutputPath == "" { g.errorOutputPath = "=" } }
[ "func", "(", "g", "*", "Gnostic", ")", "validateOptions", "(", ")", "{", "if", "g", ".", "binaryOutputPath", "==", "\"", "\"", "&&", "g", ".", "textOutputPath", "==", "\"", "\"", "&&", "g", ".", "yamlOutputPath", "==", "\"", "\"", "&&", "g", ".", "jsonOutputPath", "==", "\"", "\"", "&&", "g", ".", "errorOutputPath", "==", "\"", "\"", "&&", "len", "(", "g", ".", "pluginCalls", ")", "==", "0", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\\n", "\"", ",", "g", ".", "usage", ")", "\n", "os", ".", "Exit", "(", "-", "1", ")", "\n", "}", "\n", "if", "g", ".", "sourceName", "==", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\\n", "\"", ",", "g", ".", "usage", ")", "\n", "os", ".", "Exit", "(", "-", "1", ")", "\n", "}", "\n", "// If we get here and the error output is unspecified, write errors to stderr.", "if", "g", ".", "errorOutputPath", "==", "\"", "\"", "{", "g", ".", "errorOutputPath", "=", "\"", "\"", "\n", "}", "\n", "}" ]
// Validate command-line options.
[ "Validate", "command", "-", "line", "options", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L354-L372
18,576
googleapis/gnostic
gnostic.go
errorBytes
func (g *Gnostic) errorBytes(err error) []byte { return []byte("Errors reading " + g.sourceName + "\n" + err.Error()) }
go
func (g *Gnostic) errorBytes(err error) []byte { return []byte("Errors reading " + g.sourceName + "\n" + err.Error()) }
[ "func", "(", "g", "*", "Gnostic", ")", "errorBytes", "(", "err", "error", ")", "[", "]", "byte", "{", "return", "[", "]", "byte", "(", "\"", "\"", "+", "g", ".", "sourceName", "+", "\"", "\\n", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}" ]
// Generate an error message to be written to stderr or a file.
[ "Generate", "an", "error", "message", "to", "be", "written", "to", "stderr", "or", "a", "file", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L375-L377
18,577
googleapis/gnostic
gnostic.go
readOpenAPIText
func (g *Gnostic) readOpenAPIText(bytes []byte) (message proto.Message, err error) { info, err := compiler.ReadInfoFromBytes(g.sourceName, bytes) if err != nil { return nil, err } // Determine the OpenAPI version. g.sourceFormat = getOpenAPIVersionFromInfo(info) if g.sourceFormat == SourceFormatUnknown { return nil, errors.New("unable to identify OpenAPI version") } // Compile to the proto model. if g.sourceFormat == SourceFormatOpenAPI2 { document, err := openapi_v2.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } else if g.sourceFormat == SourceFormatOpenAPI3 { document, err := openapi_v3.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } else { document, err := discovery_v1.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } return message, err }
go
func (g *Gnostic) readOpenAPIText(bytes []byte) (message proto.Message, err error) { info, err := compiler.ReadInfoFromBytes(g.sourceName, bytes) if err != nil { return nil, err } // Determine the OpenAPI version. g.sourceFormat = getOpenAPIVersionFromInfo(info) if g.sourceFormat == SourceFormatUnknown { return nil, errors.New("unable to identify OpenAPI version") } // Compile to the proto model. if g.sourceFormat == SourceFormatOpenAPI2 { document, err := openapi_v2.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } else if g.sourceFormat == SourceFormatOpenAPI3 { document, err := openapi_v3.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } else { document, err := discovery_v1.NewDocument(info, compiler.NewContextWithExtensions("$root", nil, &g.extensionHandlers)) if err != nil { return nil, err } message = document } return message, err }
[ "func", "(", "g", "*", "Gnostic", ")", "readOpenAPIText", "(", "bytes", "[", "]", "byte", ")", "(", "message", "proto", ".", "Message", ",", "err", "error", ")", "{", "info", ",", "err", ":=", "compiler", ".", "ReadInfoFromBytes", "(", "g", ".", "sourceName", ",", "bytes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Determine the OpenAPI version.", "g", ".", "sourceFormat", "=", "getOpenAPIVersionFromInfo", "(", "info", ")", "\n", "if", "g", ".", "sourceFormat", "==", "SourceFormatUnknown", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "// Compile to the proto model.", "if", "g", ".", "sourceFormat", "==", "SourceFormatOpenAPI2", "{", "document", ",", "err", ":=", "openapi_v2", ".", "NewDocument", "(", "info", ",", "compiler", ".", "NewContextWithExtensions", "(", "\"", "\"", ",", "nil", ",", "&", "g", ".", "extensionHandlers", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "message", "=", "document", "\n", "}", "else", "if", "g", ".", "sourceFormat", "==", "SourceFormatOpenAPI3", "{", "document", ",", "err", ":=", "openapi_v3", ".", "NewDocument", "(", "info", ",", "compiler", ".", "NewContextWithExtensions", "(", "\"", "\"", ",", "nil", ",", "&", "g", ".", "extensionHandlers", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "message", "=", "document", "\n", "}", "else", "{", "document", ",", "err", ":=", "discovery_v1", ".", "NewDocument", "(", "info", ",", "compiler", ".", "NewContextWithExtensions", "(", "\"", "\"", ",", "nil", ",", "&", "g", ".", "extensionHandlers", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "message", "=", "document", "\n", "}", "\n", "return", "message", ",", "err", "\n", "}" ]
// Read an OpenAPI description from YAML or JSON.
[ "Read", "an", "OpenAPI", "description", "from", "YAML", "or", "JSON", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L380-L411
18,578
googleapis/gnostic
gnostic.go
readOpenAPIBinary
func (g *Gnostic) readOpenAPIBinary(data []byte) (message proto.Message, err error) { // try to read an OpenAPI v3 document documentV3 := &openapi_v3.Document{} err = proto.Unmarshal(data, documentV3) if err == nil && strings.HasPrefix(documentV3.Openapi, "3.0") { g.sourceFormat = SourceFormatOpenAPI3 return documentV3, nil } // if that failed, try to read an OpenAPI v2 document documentV2 := &openapi_v2.Document{} err = proto.Unmarshal(data, documentV2) if err == nil && strings.HasPrefix(documentV2.Swagger, "2.0") { g.sourceFormat = SourceFormatOpenAPI2 return documentV2, nil } // if that failed, try to read a Discovery Format document discoveryDocument := &discovery_v1.Document{} err = proto.Unmarshal(data, discoveryDocument) if err == nil { // && strings.HasPrefix(documentV2.Swagger, "2.0") { g.sourceFormat = SourceFormatDiscovery return discoveryDocument, nil } return nil, err }
go
func (g *Gnostic) readOpenAPIBinary(data []byte) (message proto.Message, err error) { // try to read an OpenAPI v3 document documentV3 := &openapi_v3.Document{} err = proto.Unmarshal(data, documentV3) if err == nil && strings.HasPrefix(documentV3.Openapi, "3.0") { g.sourceFormat = SourceFormatOpenAPI3 return documentV3, nil } // if that failed, try to read an OpenAPI v2 document documentV2 := &openapi_v2.Document{} err = proto.Unmarshal(data, documentV2) if err == nil && strings.HasPrefix(documentV2.Swagger, "2.0") { g.sourceFormat = SourceFormatOpenAPI2 return documentV2, nil } // if that failed, try to read a Discovery Format document discoveryDocument := &discovery_v1.Document{} err = proto.Unmarshal(data, discoveryDocument) if err == nil { // && strings.HasPrefix(documentV2.Swagger, "2.0") { g.sourceFormat = SourceFormatDiscovery return discoveryDocument, nil } return nil, err }
[ "func", "(", "g", "*", "Gnostic", ")", "readOpenAPIBinary", "(", "data", "[", "]", "byte", ")", "(", "message", "proto", ".", "Message", ",", "err", "error", ")", "{", "// try to read an OpenAPI v3 document", "documentV3", ":=", "&", "openapi_v3", ".", "Document", "{", "}", "\n", "err", "=", "proto", ".", "Unmarshal", "(", "data", ",", "documentV3", ")", "\n", "if", "err", "==", "nil", "&&", "strings", ".", "HasPrefix", "(", "documentV3", ".", "Openapi", ",", "\"", "\"", ")", "{", "g", ".", "sourceFormat", "=", "SourceFormatOpenAPI3", "\n", "return", "documentV3", ",", "nil", "\n", "}", "\n", "// if that failed, try to read an OpenAPI v2 document", "documentV2", ":=", "&", "openapi_v2", ".", "Document", "{", "}", "\n", "err", "=", "proto", ".", "Unmarshal", "(", "data", ",", "documentV2", ")", "\n", "if", "err", "==", "nil", "&&", "strings", ".", "HasPrefix", "(", "documentV2", ".", "Swagger", ",", "\"", "\"", ")", "{", "g", ".", "sourceFormat", "=", "SourceFormatOpenAPI2", "\n", "return", "documentV2", ",", "nil", "\n", "}", "\n", "// if that failed, try to read a Discovery Format document", "discoveryDocument", ":=", "&", "discovery_v1", ".", "Document", "{", "}", "\n", "err", "=", "proto", ".", "Unmarshal", "(", "data", ",", "discoveryDocument", ")", "\n", "if", "err", "==", "nil", "{", "// && strings.HasPrefix(documentV2.Swagger, \"2.0\") {", "g", ".", "sourceFormat", "=", "SourceFormatDiscovery", "\n", "return", "discoveryDocument", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}" ]
// Read an OpenAPI binary file.
[ "Read", "an", "OpenAPI", "binary", "file", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L414-L437
18,579
googleapis/gnostic
gnostic.go
writeBinaryOutput
func (g *Gnostic) writeBinaryOutput(message proto.Message) { protoBytes, err := proto.Marshal(message) if err != nil { writeFile(g.errorOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) } else { writeFile(g.binaryOutputPath, protoBytes, g.sourceName, "pb") } }
go
func (g *Gnostic) writeBinaryOutput(message proto.Message) { protoBytes, err := proto.Marshal(message) if err != nil { writeFile(g.errorOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) } else { writeFile(g.binaryOutputPath, protoBytes, g.sourceName, "pb") } }
[ "func", "(", "g", "*", "Gnostic", ")", "writeBinaryOutput", "(", "message", "proto", ".", "Message", ")", "{", "protoBytes", ",", "err", ":=", "proto", ".", "Marshal", "(", "message", ")", "\n", "if", "err", "!=", "nil", "{", "writeFile", "(", "g", ".", "errorOutputPath", ",", "g", ".", "errorBytes", "(", "err", ")", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "defer", "os", ".", "Exit", "(", "-", "1", ")", "\n", "}", "else", "{", "writeFile", "(", "g", ".", "binaryOutputPath", ",", "protoBytes", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Write a binary pb representation.
[ "Write", "a", "binary", "pb", "representation", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L440-L448
18,580
googleapis/gnostic
gnostic.go
writeTextOutput
func (g *Gnostic) writeTextOutput(message proto.Message) { bytes := []byte(proto.MarshalTextString(message)) writeFile(g.textOutputPath, bytes, g.sourceName, "text") }
go
func (g *Gnostic) writeTextOutput(message proto.Message) { bytes := []byte(proto.MarshalTextString(message)) writeFile(g.textOutputPath, bytes, g.sourceName, "text") }
[ "func", "(", "g", "*", "Gnostic", ")", "writeTextOutput", "(", "message", "proto", ".", "Message", ")", "{", "bytes", ":=", "[", "]", "byte", "(", "proto", ".", "MarshalTextString", "(", "message", ")", ")", "\n", "writeFile", "(", "g", ".", "textOutputPath", ",", "bytes", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "}" ]
// Write a text pb representation.
[ "Write", "a", "text", "pb", "representation", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L451-L454
18,581
googleapis/gnostic
gnostic.go
writeMessagesOutput
func (g *Gnostic) writeMessagesOutput(message proto.Message) { protoBytes, err := proto.Marshal(message) if err != nil { writeFile(g.messageOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) } else { writeFile(g.messageOutputPath, protoBytes, g.sourceName, "messages.pb") } }
go
func (g *Gnostic) writeMessagesOutput(message proto.Message) { protoBytes, err := proto.Marshal(message) if err != nil { writeFile(g.messageOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) } else { writeFile(g.messageOutputPath, protoBytes, g.sourceName, "messages.pb") } }
[ "func", "(", "g", "*", "Gnostic", ")", "writeMessagesOutput", "(", "message", "proto", ".", "Message", ")", "{", "protoBytes", ",", "err", ":=", "proto", ".", "Marshal", "(", "message", ")", "\n", "if", "err", "!=", "nil", "{", "writeFile", "(", "g", ".", "messageOutputPath", ",", "g", ".", "errorBytes", "(", "err", ")", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "defer", "os", ".", "Exit", "(", "-", "1", ")", "\n", "}", "else", "{", "writeFile", "(", "g", ".", "messageOutputPath", ",", "protoBytes", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Write messages.
[ "Write", "messages", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L510-L518
18,582
googleapis/gnostic
gnostic.go
performActions
func (g *Gnostic) performActions(message proto.Message) (err error) { // Optionally resolve internal references. if g.resolveReferences { if g.sourceFormat == SourceFormatOpenAPI2 { document := message.(*openapi_v2.Document) _, err = document.ResolveReferences(g.sourceName) } else if g.sourceFormat == SourceFormatOpenAPI3 { document := message.(*openapi_v3.Document) _, err = document.ResolveReferences(g.sourceName) } if err != nil { return err } } // Optionally write proto in binary format. if g.binaryOutputPath != "" { g.writeBinaryOutput(message) } // Optionally write proto in text format. if g.textOutputPath != "" { g.writeTextOutput(message) } // Optionally write document in yaml and/or json formats. if g.yamlOutputPath != "" || g.jsonOutputPath != "" { g.writeJSONYAMLOutput(message) } // Call all specified plugins. messages := make([]*plugins.Message, 0) for _, p := range g.pluginCalls { pluginMessages, err := p.perform(message, g.sourceFormat, g.sourceName, g.timePlugins) if err != nil { writeFile(g.errorOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) // run all plugins, even when some have errors } messages = append(messages, pluginMessages...) } if g.messageOutputPath != "" { g.writeMessagesOutput(&plugins.Messages{Messages: messages}) } else { // Print any messages from the plugins if len(messages) > 0 { for _, message := range messages { fmt.Printf("%+v\n", message) } } } return nil }
go
func (g *Gnostic) performActions(message proto.Message) (err error) { // Optionally resolve internal references. if g.resolveReferences { if g.sourceFormat == SourceFormatOpenAPI2 { document := message.(*openapi_v2.Document) _, err = document.ResolveReferences(g.sourceName) } else if g.sourceFormat == SourceFormatOpenAPI3 { document := message.(*openapi_v3.Document) _, err = document.ResolveReferences(g.sourceName) } if err != nil { return err } } // Optionally write proto in binary format. if g.binaryOutputPath != "" { g.writeBinaryOutput(message) } // Optionally write proto in text format. if g.textOutputPath != "" { g.writeTextOutput(message) } // Optionally write document in yaml and/or json formats. if g.yamlOutputPath != "" || g.jsonOutputPath != "" { g.writeJSONYAMLOutput(message) } // Call all specified plugins. messages := make([]*plugins.Message, 0) for _, p := range g.pluginCalls { pluginMessages, err := p.perform(message, g.sourceFormat, g.sourceName, g.timePlugins) if err != nil { writeFile(g.errorOutputPath, g.errorBytes(err), g.sourceName, "errors") defer os.Exit(-1) // run all plugins, even when some have errors } messages = append(messages, pluginMessages...) } if g.messageOutputPath != "" { g.writeMessagesOutput(&plugins.Messages{Messages: messages}) } else { // Print any messages from the plugins if len(messages) > 0 { for _, message := range messages { fmt.Printf("%+v\n", message) } } } return nil }
[ "func", "(", "g", "*", "Gnostic", ")", "performActions", "(", "message", "proto", ".", "Message", ")", "(", "err", "error", ")", "{", "// Optionally resolve internal references.", "if", "g", ".", "resolveReferences", "{", "if", "g", ".", "sourceFormat", "==", "SourceFormatOpenAPI2", "{", "document", ":=", "message", ".", "(", "*", "openapi_v2", ".", "Document", ")", "\n", "_", ",", "err", "=", "document", ".", "ResolveReferences", "(", "g", ".", "sourceName", ")", "\n", "}", "else", "if", "g", ".", "sourceFormat", "==", "SourceFormatOpenAPI3", "{", "document", ":=", "message", ".", "(", "*", "openapi_v3", ".", "Document", ")", "\n", "_", ",", "err", "=", "document", ".", "ResolveReferences", "(", "g", ".", "sourceName", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// Optionally write proto in binary format.", "if", "g", ".", "binaryOutputPath", "!=", "\"", "\"", "{", "g", ".", "writeBinaryOutput", "(", "message", ")", "\n", "}", "\n", "// Optionally write proto in text format.", "if", "g", ".", "textOutputPath", "!=", "\"", "\"", "{", "g", ".", "writeTextOutput", "(", "message", ")", "\n", "}", "\n", "// Optionally write document in yaml and/or json formats.", "if", "g", ".", "yamlOutputPath", "!=", "\"", "\"", "||", "g", ".", "jsonOutputPath", "!=", "\"", "\"", "{", "g", ".", "writeJSONYAMLOutput", "(", "message", ")", "\n", "}", "\n", "// Call all specified plugins.", "messages", ":=", "make", "(", "[", "]", "*", "plugins", ".", "Message", ",", "0", ")", "\n", "for", "_", ",", "p", ":=", "range", "g", ".", "pluginCalls", "{", "pluginMessages", ",", "err", ":=", "p", ".", "perform", "(", "message", ",", "g", ".", "sourceFormat", ",", "g", ".", "sourceName", ",", "g", ".", "timePlugins", ")", "\n", "if", "err", "!=", "nil", "{", "writeFile", "(", "g", ".", "errorOutputPath", ",", "g", ".", "errorBytes", "(", "err", ")", ",", "g", ".", "sourceName", ",", "\"", "\"", ")", "\n", "defer", "os", ".", "Exit", "(", "-", "1", ")", "// run all plugins, even when some have errors", "\n", "}", "\n", "messages", "=", "append", "(", "messages", ",", "pluginMessages", "...", ")", "\n", "}", "\n", "if", "g", ".", "messageOutputPath", "!=", "\"", "\"", "{", "g", ".", "writeMessagesOutput", "(", "&", "plugins", ".", "Messages", "{", "Messages", ":", "messages", "}", ")", "\n", "}", "else", "{", "// Print any messages from the plugins", "if", "len", "(", "messages", ")", ">", "0", "{", "for", "_", ",", "message", ":=", "range", "messages", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "message", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Perform all actions specified in the command-line options.
[ "Perform", "all", "actions", "specified", "in", "the", "command", "-", "line", "options", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/gnostic.go#L521-L568
18,583
googleapis/gnostic
extensions/extensions.go
ProcessExtension
func ProcessExtension(handleExtension extensionHandler) { response := &ExtensionHandlerResponse{} forInputYamlFromOpenapic( func(version string, extensionName string, yamlInput string) { var newObject proto.Message var err error handled, newObject, err := handleExtension(extensionName, yamlInput) if !handled { responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } // If we reach here, then the extension is handled response.Handled = true if err != nil { response.Error = append(response.Error, err.Error()) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } response.Value, err = ptypes.MarshalAny(newObject) if err != nil { response.Error = append(response.Error, err.Error()) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } }) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) }
go
func ProcessExtension(handleExtension extensionHandler) { response := &ExtensionHandlerResponse{} forInputYamlFromOpenapic( func(version string, extensionName string, yamlInput string) { var newObject proto.Message var err error handled, newObject, err := handleExtension(extensionName, yamlInput) if !handled { responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } // If we reach here, then the extension is handled response.Handled = true if err != nil { response.Error = append(response.Error, err.Error()) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } response.Value, err = ptypes.MarshalAny(newObject) if err != nil { response.Error = append(response.Error, err.Error()) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) os.Exit(0) } }) responseBytes, _ := proto.Marshal(response) os.Stdout.Write(responseBytes) }
[ "func", "ProcessExtension", "(", "handleExtension", "extensionHandler", ")", "{", "response", ":=", "&", "ExtensionHandlerResponse", "{", "}", "\n", "forInputYamlFromOpenapic", "(", "func", "(", "version", "string", ",", "extensionName", "string", ",", "yamlInput", "string", ")", "{", "var", "newObject", "proto", ".", "Message", "\n", "var", "err", "error", "\n\n", "handled", ",", "newObject", ",", "err", ":=", "handleExtension", "(", "extensionName", ",", "yamlInput", ")", "\n", "if", "!", "handled", "{", "responseBytes", ",", "_", ":=", "proto", ".", "Marshal", "(", "response", ")", "\n", "os", ".", "Stdout", ".", "Write", "(", "responseBytes", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "\n\n", "// If we reach here, then the extension is handled", "response", ".", "Handled", "=", "true", "\n", "if", "err", "!=", "nil", "{", "response", ".", "Error", "=", "append", "(", "response", ".", "Error", ",", "err", ".", "Error", "(", ")", ")", "\n", "responseBytes", ",", "_", ":=", "proto", ".", "Marshal", "(", "response", ")", "\n", "os", ".", "Stdout", ".", "Write", "(", "responseBytes", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "\n", "response", ".", "Value", ",", "err", "=", "ptypes", ".", "MarshalAny", "(", "newObject", ")", "\n", "if", "err", "!=", "nil", "{", "response", ".", "Error", "=", "append", "(", "response", ".", "Error", ",", "err", ".", "Error", "(", ")", ")", "\n", "responseBytes", ",", "_", ":=", "proto", ".", "Marshal", "(", "response", ")", "\n", "os", ".", "Stdout", ".", "Write", "(", "responseBytes", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "\n", "}", ")", "\n\n", "responseBytes", ",", "_", ":=", "proto", ".", "Marshal", "(", "response", ")", "\n", "os", ".", "Stdout", ".", "Write", "(", "responseBytes", ")", "\n", "}" ]
// ProcessExtension calles the handler for a specified extension.
[ "ProcessExtension", "calles", "the", "handler", "for", "a", "specified", "extension", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/extensions/extensions.go#L49-L82
18,584
googleapis/gnostic
discovery/discovery.go
NewAnnotations
func NewAnnotations(in interface{}, context *compiler.Context) (*Annotations, error) { errors := make([]error, 0) x := &Annotations{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"required"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // repeated string required = 1; v1 := compiler.MapValueForKey(m, "required") if v1 != nil { v, ok := v1.([]interface{}) if ok { x.Required = compiler.ConvertInterfaceArrayToStringArray(v) } else { message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewAnnotations(in interface{}, context *compiler.Context) (*Annotations, error) { errors := make([]error, 0) x := &Annotations{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"required"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // repeated string required = 1; v1 := compiler.MapValueForKey(m, "required") if v1 != nil { v, ok := v1.([]interface{}) if ok { x.Required = compiler.ConvertInterfaceArrayToStringArray(v) } else { message := fmt.Sprintf("has unexpected value for required: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewAnnotations", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Annotations", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Annotations", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// repeated string required = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "v", ",", "ok", ":=", "v1", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "if", "ok", "{", "x", ".", "Required", "=", "compiler", ".", "ConvertInterfaceArrayToStringArray", "(", "v", ")", "\n", "}", "else", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v1", ",", "v1", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewAnnotations creates an object of type Annotations if possible, returning an error if not.
[ "NewAnnotations", "creates", "an", "object", "of", "type", "Annotations", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L33-L61
18,585
googleapis/gnostic
discovery/discovery.go
NewAny
func NewAny(in interface{}, context *compiler.Context) (*Any, error) { errors := make([]error, 0) x := &Any{} bytes, _ := yaml.Marshal(in) x.Yaml = string(bytes) return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewAny(in interface{}, context *compiler.Context) (*Any, error) { errors := make([]error, 0) x := &Any{} bytes, _ := yaml.Marshal(in) x.Yaml = string(bytes) return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewAny", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Any", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Any", "{", "}", "\n", "bytes", ",", "_", ":=", "yaml", ".", "Marshal", "(", "in", ")", "\n", "x", ".", "Yaml", "=", "string", "(", "bytes", ")", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewAny creates an object of type Any if possible, returning an error if not.
[ "NewAny", "creates", "an", "object", "of", "type", "Any", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L64-L70
18,586
googleapis/gnostic
discovery/discovery.go
NewAuth
func NewAuth(in interface{}, context *compiler.Context) (*Auth, error) { errors := make([]error, 0) x := &Auth{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"oauth2"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Oauth2 oauth2 = 1; v1 := compiler.MapValueForKey(m, "oauth2") if v1 != nil { var err error x.Oauth2, err = NewOauth2(v1, compiler.NewContext("oauth2", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewAuth(in interface{}, context *compiler.Context) (*Auth, error) { errors := make([]error, 0) x := &Auth{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"oauth2"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Oauth2 oauth2 = 1; v1 := compiler.MapValueForKey(m, "oauth2") if v1 != nil { var err error x.Oauth2, err = NewOauth2(v1, compiler.NewContext("oauth2", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewAuth", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Auth", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Auth", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// Oauth2 oauth2 = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Oauth2", ",", "err", "=", "NewOauth2", "(", "v1", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewAuth creates an object of type Auth if possible, returning an error if not.
[ "NewAuth", "creates", "an", "object", "of", "type", "Auth", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L73-L99
18,587
googleapis/gnostic
discovery/discovery.go
NewMediaUpload
func NewMediaUpload(in interface{}, context *compiler.Context) (*MediaUpload, error) { errors := make([]error, 0) x := &MediaUpload{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"accept", "maxSize", "protocols", "supportsSubscription"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // repeated string accept = 1; v1 := compiler.MapValueForKey(m, "accept") if v1 != nil { v, ok := v1.([]interface{}) if ok { x.Accept = compiler.ConvertInterfaceArrayToStringArray(v) } else { message := fmt.Sprintf("has unexpected value for accept: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } // string max_size = 2; v2 := compiler.MapValueForKey(m, "maxSize") if v2 != nil { x.MaxSize, ok = v2.(string) if !ok { message := fmt.Sprintf("has unexpected value for maxSize: %+v (%T)", v2, v2) errors = append(errors, compiler.NewError(context, message)) } } // Protocols protocols = 3; v3 := compiler.MapValueForKey(m, "protocols") if v3 != nil { var err error x.Protocols, err = NewProtocols(v3, compiler.NewContext("protocols", context)) if err != nil { errors = append(errors, err) } } // bool supports_subscription = 4; v4 := compiler.MapValueForKey(m, "supportsSubscription") if v4 != nil { x.SupportsSubscription, ok = v4.(bool) if !ok { message := fmt.Sprintf("has unexpected value for supportsSubscription: %+v (%T)", v4, v4) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewMediaUpload(in interface{}, context *compiler.Context) (*MediaUpload, error) { errors := make([]error, 0) x := &MediaUpload{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"accept", "maxSize", "protocols", "supportsSubscription"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // repeated string accept = 1; v1 := compiler.MapValueForKey(m, "accept") if v1 != nil { v, ok := v1.([]interface{}) if ok { x.Accept = compiler.ConvertInterfaceArrayToStringArray(v) } else { message := fmt.Sprintf("has unexpected value for accept: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } // string max_size = 2; v2 := compiler.MapValueForKey(m, "maxSize") if v2 != nil { x.MaxSize, ok = v2.(string) if !ok { message := fmt.Sprintf("has unexpected value for maxSize: %+v (%T)", v2, v2) errors = append(errors, compiler.NewError(context, message)) } } // Protocols protocols = 3; v3 := compiler.MapValueForKey(m, "protocols") if v3 != nil { var err error x.Protocols, err = NewProtocols(v3, compiler.NewContext("protocols", context)) if err != nil { errors = append(errors, err) } } // bool supports_subscription = 4; v4 := compiler.MapValueForKey(m, "supportsSubscription") if v4 != nil { x.SupportsSubscription, ok = v4.(bool) if !ok { message := fmt.Sprintf("has unexpected value for supportsSubscription: %+v (%T)", v4, v4) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewMediaUpload", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "MediaUpload", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "MediaUpload", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// repeated string accept = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "v", ",", "ok", ":=", "v1", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "if", "ok", "{", "x", ".", "Accept", "=", "compiler", ".", "ConvertInterfaceArrayToStringArray", "(", "v", ")", "\n", "}", "else", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v1", ",", "v1", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "// string max_size = 2;", "v2", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v2", "!=", "nil", "{", "x", ".", "MaxSize", ",", "ok", "=", "v2", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v2", ",", "v2", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "// Protocols protocols = 3;", "v3", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v3", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Protocols", ",", "err", "=", "NewProtocols", "(", "v3", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "// bool supports_subscription = 4;", "v4", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v4", "!=", "nil", "{", "x", ".", "SupportsSubscription", ",", "ok", "=", "v4", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v4", ",", "v4", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewMediaUpload creates an object of type MediaUpload if possible, returning an error if not.
[ "NewMediaUpload", "creates", "an", "object", "of", "type", "MediaUpload", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L446-L501
18,588
googleapis/gnostic
discovery/discovery.go
NewMethods
func NewMethods(in interface{}, context *compiler.Context) (*Methods, error) { errors := make([]error, 0) x := &Methods{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedMethod additional_properties = 1; // MAP: Method x.AdditionalProperties = make([]*NamedMethod, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedMethod{} pair.Name = k var err error pair.Value, err = NewMethod(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewMethods(in interface{}, context *compiler.Context) (*Methods, error) { errors := make([]error, 0) x := &Methods{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedMethod additional_properties = 1; // MAP: Method x.AdditionalProperties = make([]*NamedMethod, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedMethod{} pair.Name = k var err error pair.Value, err = NewMethod(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewMethods", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Methods", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Methods", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "// repeated NamedMethod additional_properties = 1;", "// MAP: Method", "x", ".", "AdditionalProperties", "=", "make", "(", "[", "]", "*", "NamedMethod", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", "{", "k", ",", "ok", ":=", "compiler", ".", "StringValue", "(", "item", ".", "Key", ")", "\n", "if", "ok", "{", "v", ":=", "item", ".", "Value", "\n", "pair", ":=", "&", "NamedMethod", "{", "}", "\n", "pair", ".", "Name", "=", "k", "\n", "var", "err", "error", "\n", "pair", ".", "Value", ",", "err", "=", "NewMethod", "(", "v", ",", "compiler", ".", "NewContext", "(", "k", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "x", ".", "AdditionalProperties", "=", "append", "(", "x", ".", "AdditionalProperties", ",", "pair", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewMethods creates an object of type Methods if possible, returning an error if not.
[ "NewMethods", "creates", "an", "object", "of", "type", "Methods", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L672-L699
18,589
googleapis/gnostic
discovery/discovery.go
NewProtocols
func NewProtocols(in interface{}, context *compiler.Context) (*Protocols, error) { errors := make([]error, 0) x := &Protocols{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"resumable", "simple"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Simple simple = 1; v1 := compiler.MapValueForKey(m, "simple") if v1 != nil { var err error x.Simple, err = NewSimple(v1, compiler.NewContext("simple", context)) if err != nil { errors = append(errors, err) } } // Resumable resumable = 2; v2 := compiler.MapValueForKey(m, "resumable") if v2 != nil { var err error x.Resumable, err = NewResumable(v2, compiler.NewContext("resumable", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewProtocols(in interface{}, context *compiler.Context) (*Protocols, error) { errors := make([]error, 0) x := &Protocols{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"resumable", "simple"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Simple simple = 1; v1 := compiler.MapValueForKey(m, "simple") if v1 != nil { var err error x.Simple, err = NewSimple(v1, compiler.NewContext("simple", context)) if err != nil { errors = append(errors, err) } } // Resumable resumable = 2; v2 := compiler.MapValueForKey(m, "resumable") if v2 != nil { var err error x.Resumable, err = NewResumable(v2, compiler.NewContext("resumable", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewProtocols", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Protocols", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Protocols", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// Simple simple = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Simple", ",", "err", "=", "NewSimple", "(", "v1", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "// Resumable resumable = 2;", "v2", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v2", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Resumable", ",", "err", "=", "NewResumable", "(", "v2", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewProtocols creates an object of type Protocols if possible, returning an error if not.
[ "NewProtocols", "creates", "an", "object", "of", "type", "Protocols", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1137-L1172
18,590
googleapis/gnostic
discovery/discovery.go
NewResource
func NewResource(in interface{}, context *compiler.Context) (*Resource, error) { errors := make([]error, 0) x := &Resource{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"methods", "resources"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Methods methods = 1; v1 := compiler.MapValueForKey(m, "methods") if v1 != nil { var err error x.Methods, err = NewMethods(v1, compiler.NewContext("methods", context)) if err != nil { errors = append(errors, err) } } // Resources resources = 2; v2 := compiler.MapValueForKey(m, "resources") if v2 != nil { var err error x.Resources, err = NewResources(v2, compiler.NewContext("resources", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewResource(in interface{}, context *compiler.Context) (*Resource, error) { errors := make([]error, 0) x := &Resource{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"methods", "resources"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // Methods methods = 1; v1 := compiler.MapValueForKey(m, "methods") if v1 != nil { var err error x.Methods, err = NewMethods(v1, compiler.NewContext("methods", context)) if err != nil { errors = append(errors, err) } } // Resources resources = 2; v2 := compiler.MapValueForKey(m, "resources") if v2 != nil { var err error x.Resources, err = NewResources(v2, compiler.NewContext("resources", context)) if err != nil { errors = append(errors, err) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewResource", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Resource", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Resource", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// Methods methods = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Methods", ",", "err", "=", "NewMethods", "(", "v1", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "// Resources resources = 2;", "v2", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v2", "!=", "nil", "{", "var", "err", "error", "\n", "x", ".", "Resources", ",", "err", "=", "NewResources", "(", "v2", ",", "compiler", ".", "NewContext", "(", "\"", "\"", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewResource creates an object of type Resource if possible, returning an error if not.
[ "NewResource", "creates", "an", "object", "of", "type", "Resource", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1213-L1248
18,591
googleapis/gnostic
discovery/discovery.go
NewResources
func NewResources(in interface{}, context *compiler.Context) (*Resources, error) { errors := make([]error, 0) x := &Resources{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedResource additional_properties = 1; // MAP: Resource x.AdditionalProperties = make([]*NamedResource, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedResource{} pair.Name = k var err error pair.Value, err = NewResource(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewResources(in interface{}, context *compiler.Context) (*Resources, error) { errors := make([]error, 0) x := &Resources{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedResource additional_properties = 1; // MAP: Resource x.AdditionalProperties = make([]*NamedResource, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedResource{} pair.Name = k var err error pair.Value, err = NewResource(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewResources", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Resources", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Resources", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "// repeated NamedResource additional_properties = 1;", "// MAP: Resource", "x", ".", "AdditionalProperties", "=", "make", "(", "[", "]", "*", "NamedResource", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", "{", "k", ",", "ok", ":=", "compiler", ".", "StringValue", "(", "item", ".", "Key", ")", "\n", "if", "ok", "{", "v", ":=", "item", ".", "Value", "\n", "pair", ":=", "&", "NamedResource", "{", "}", "\n", "pair", ".", "Name", "=", "k", "\n", "var", "err", "error", "\n", "pair", ".", "Value", ",", "err", "=", "NewResource", "(", "v", ",", "compiler", ".", "NewContext", "(", "k", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "x", ".", "AdditionalProperties", "=", "append", "(", "x", ".", "AdditionalProperties", ",", "pair", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewResources creates an object of type Resources if possible, returning an error if not.
[ "NewResources", "creates", "an", "object", "of", "type", "Resources", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1251-L1278
18,592
googleapis/gnostic
discovery/discovery.go
NewScopes
func NewScopes(in interface{}, context *compiler.Context) (*Scopes, error) { errors := make([]error, 0) x := &Scopes{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedScope additional_properties = 1; // MAP: Scope x.AdditionalProperties = make([]*NamedScope, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedScope{} pair.Name = k var err error pair.Value, err = NewScope(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewScopes(in interface{}, context *compiler.Context) (*Scopes, error) { errors := make([]error, 0) x := &Scopes{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { // repeated NamedScope additional_properties = 1; // MAP: Scope x.AdditionalProperties = make([]*NamedScope, 0) for _, item := range m { k, ok := compiler.StringValue(item.Key) if ok { v := item.Value pair := &NamedScope{} pair.Name = k var err error pair.Value, err = NewScope(v, compiler.NewContext(k, context)) if err != nil { errors = append(errors, err) } x.AdditionalProperties = append(x.AdditionalProperties, pair) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewScopes", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Scopes", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Scopes", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "// repeated NamedScope additional_properties = 1;", "// MAP: Scope", "x", ".", "AdditionalProperties", "=", "make", "(", "[", "]", "*", "NamedScope", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", "{", "k", ",", "ok", ":=", "compiler", ".", "StringValue", "(", "item", ".", "Key", ")", "\n", "if", "ok", "{", "v", ":=", "item", ".", "Value", "\n", "pair", ":=", "&", "NamedScope", "{", "}", "\n", "pair", ".", "Name", "=", "k", "\n", "var", "err", "error", "\n", "pair", ".", "Value", ",", "err", "=", "NewScope", "(", "v", ",", "compiler", ".", "NewContext", "(", "k", ",", "context", ")", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "x", ".", "AdditionalProperties", "=", "append", "(", "x", ".", "AdditionalProperties", ",", "pair", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewScopes creates an object of type Scopes if possible, returning an error if not.
[ "NewScopes", "creates", "an", "object", "of", "type", "Scopes", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1602-L1629
18,593
googleapis/gnostic
discovery/discovery.go
NewSimple
func NewSimple(in interface{}, context *compiler.Context) (*Simple, error) { errors := make([]error, 0) x := &Simple{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"multipart", "path"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // bool multipart = 1; v1 := compiler.MapValueForKey(m, "multipart") if v1 != nil { x.Multipart, ok = v1.(bool) if !ok { message := fmt.Sprintf("has unexpected value for multipart: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } // string path = 2; v2 := compiler.MapValueForKey(m, "path") if v2 != nil { x.Path, ok = v2.(string) if !ok { message := fmt.Sprintf("has unexpected value for path: %+v (%T)", v2, v2) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewSimple(in interface{}, context *compiler.Context) (*Simple, error) { errors := make([]error, 0) x := &Simple{} m, ok := compiler.UnpackMap(in) if !ok { message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { allowedKeys := []string{"multipart", "path"} var allowedPatterns []*regexp.Regexp invalidKeys := compiler.InvalidKeysInMap(m, allowedKeys, allowedPatterns) if len(invalidKeys) > 0 { message := fmt.Sprintf("has invalid %s: %+v", compiler.PluralProperties(len(invalidKeys)), strings.Join(invalidKeys, ", ")) errors = append(errors, compiler.NewError(context, message)) } // bool multipart = 1; v1 := compiler.MapValueForKey(m, "multipart") if v1 != nil { x.Multipart, ok = v1.(bool) if !ok { message := fmt.Sprintf("has unexpected value for multipart: %+v (%T)", v1, v1) errors = append(errors, compiler.NewError(context, message)) } } // string path = 2; v2 := compiler.MapValueForKey(m, "path") if v2 != nil { x.Path, ok = v2.(string) if !ok { message := fmt.Sprintf("has unexpected value for path: %+v (%T)", v2, v2) errors = append(errors, compiler.NewError(context, message)) } } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewSimple", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "Simple", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "Simple", "{", "}", "\n", "m", ",", "ok", ":=", "compiler", ".", "UnpackMap", "(", "in", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "allowedKeys", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "\n", "var", "allowedPatterns", "[", "]", "*", "regexp", ".", "Regexp", "\n", "invalidKeys", ":=", "compiler", ".", "InvalidKeysInMap", "(", "m", ",", "allowedKeys", ",", "allowedPatterns", ")", "\n", "if", "len", "(", "invalidKeys", ")", ">", "0", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "compiler", ".", "PluralProperties", "(", "len", "(", "invalidKeys", ")", ")", ",", "strings", ".", "Join", "(", "invalidKeys", ",", "\"", "\"", ")", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "// bool multipart = 1;", "v1", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v1", "!=", "nil", "{", "x", ".", "Multipart", ",", "ok", "=", "v1", ".", "(", "bool", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v1", ",", "v1", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "// string path = 2;", "v2", ":=", "compiler", ".", "MapValueForKey", "(", "m", ",", "\"", "\"", ")", "\n", "if", "v2", "!=", "nil", "{", "x", ".", "Path", ",", "ok", "=", "v2", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v2", ",", "v2", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewSimple creates an object of type Simple if possible, returning an error if not.
[ "NewSimple", "creates", "an", "object", "of", "type", "Simple", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1632-L1667
18,594
googleapis/gnostic
discovery/discovery.go
NewStringArray
func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, error) { errors := make([]error, 0) x := &StringArray{} a, ok := in.([]interface{}) if !ok { message := fmt.Sprintf("has unexpected value for StringArray: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { x.Value = make([]string, 0) for _, s := range a { x.Value = append(x.Value, s.(string)) } } return x, compiler.NewErrorGroupOrNil(errors) }
go
func NewStringArray(in interface{}, context *compiler.Context) (*StringArray, error) { errors := make([]error, 0) x := &StringArray{} a, ok := in.([]interface{}) if !ok { message := fmt.Sprintf("has unexpected value for StringArray: %+v (%T)", in, in) errors = append(errors, compiler.NewError(context, message)) } else { x.Value = make([]string, 0) for _, s := range a { x.Value = append(x.Value, s.(string)) } } return x, compiler.NewErrorGroupOrNil(errors) }
[ "func", "NewStringArray", "(", "in", "interface", "{", "}", ",", "context", "*", "compiler", ".", "Context", ")", "(", "*", "StringArray", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "x", ":=", "&", "StringArray", "{", "}", "\n", "a", ",", "ok", ":=", "in", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "if", "!", "ok", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "in", ",", "in", ")", "\n", "errors", "=", "append", "(", "errors", ",", "compiler", ".", "NewError", "(", "context", ",", "message", ")", ")", "\n", "}", "else", "{", "x", ".", "Value", "=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "s", ":=", "range", "a", "{", "x", ".", "Value", "=", "append", "(", "x", ".", "Value", ",", "s", ".", "(", "string", ")", ")", "\n", "}", "\n", "}", "\n", "return", "x", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// NewStringArray creates an object of type StringArray if possible, returning an error if not.
[ "NewStringArray", "creates", "an", "object", "of", "type", "StringArray", "if", "possible", "returning", "an", "error", "if", "not", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1670-L1684
18,595
googleapis/gnostic
discovery/discovery.go
ResolveReferences
func (m *MediaUpload) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Protocols != nil { _, err := m.Protocols.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
go
func (m *MediaUpload) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Protocols != nil { _, err := m.Protocols.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
[ "func", "(", "m", "*", "MediaUpload", ")", "ResolveReferences", "(", "root", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "if", "m", ".", "Protocols", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Protocols", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// ResolveReferences resolves references found inside MediaUpload objects.
[ "ResolveReferences", "resolves", "references", "found", "inside", "MediaUpload", "objects", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1759-L1768
18,596
googleapis/gnostic
discovery/discovery.go
ResolveReferences
func (m *Method) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Parameters != nil { _, err := m.Parameters.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Request != nil { _, err := m.Request.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Response != nil { _, err := m.Response.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.MediaUpload != nil { _, err := m.MediaUpload.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
go
func (m *Method) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Parameters != nil { _, err := m.Parameters.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Request != nil { _, err := m.Request.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Response != nil { _, err := m.Response.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.MediaUpload != nil { _, err := m.MediaUpload.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
[ "func", "(", "m", "*", "Method", ")", "ResolveReferences", "(", "root", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "if", "m", ".", "Parameters", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Parameters", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "m", ".", "Request", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Request", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "m", ".", "Response", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Response", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "m", ".", "MediaUpload", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "MediaUpload", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// ResolveReferences resolves references found inside Method objects.
[ "ResolveReferences", "resolves", "references", "found", "inside", "Method", "objects", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1771-L1798
18,597
googleapis/gnostic
discovery/discovery.go
ResolveReferences
func (m *Methods) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) for _, item := range m.AdditionalProperties { if item != nil { _, err := item.ResolveReferences(root) if err != nil { errors = append(errors, err) } } } return nil, compiler.NewErrorGroupOrNil(errors) }
go
func (m *Methods) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) for _, item := range m.AdditionalProperties { if item != nil { _, err := item.ResolveReferences(root) if err != nil { errors = append(errors, err) } } } return nil, compiler.NewErrorGroupOrNil(errors) }
[ "func", "(", "m", "*", "Methods", ")", "ResolveReferences", "(", "root", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "for", "_", ",", "item", ":=", "range", "m", ".", "AdditionalProperties", "{", "if", "item", "!=", "nil", "{", "_", ",", "err", ":=", "item", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// ResolveReferences resolves references found inside Methods objects.
[ "ResolveReferences", "resolves", "references", "found", "inside", "Methods", "objects", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1801-L1812
18,598
googleapis/gnostic
discovery/discovery.go
ResolveReferences
func (m *NamedMethod) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Value != nil { _, err := m.Value.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
go
func (m *NamedMethod) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Value != nil { _, err := m.Value.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
[ "func", "(", "m", "*", "NamedMethod", ")", "ResolveReferences", "(", "root", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "if", "m", ".", "Value", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Value", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// ResolveReferences resolves references found inside NamedMethod objects.
[ "ResolveReferences", "resolves", "references", "found", "inside", "NamedMethod", "objects", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1815-L1824
18,599
googleapis/gnostic
discovery/discovery.go
ResolveReferences
func (m *Protocols) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Simple != nil { _, err := m.Simple.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Resumable != nil { _, err := m.Resumable.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
go
func (m *Protocols) ResolveReferences(root string) (interface{}, error) { errors := make([]error, 0) if m.Simple != nil { _, err := m.Simple.ResolveReferences(root) if err != nil { errors = append(errors, err) } } if m.Resumable != nil { _, err := m.Resumable.ResolveReferences(root) if err != nil { errors = append(errors, err) } } return nil, compiler.NewErrorGroupOrNil(errors) }
[ "func", "(", "m", "*", "Protocols", ")", "ResolveReferences", "(", "root", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "errors", ":=", "make", "(", "[", "]", "error", ",", "0", ")", "\n", "if", "m", ".", "Simple", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Simple", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "m", ".", "Resumable", "!=", "nil", "{", "_", ",", "err", ":=", "m", ".", "Resumable", ".", "ResolveReferences", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "errors", "=", "append", "(", "errors", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "compiler", ".", "NewErrorGroupOrNil", "(", "errors", ")", "\n", "}" ]
// ResolveReferences resolves references found inside Protocols objects.
[ "ResolveReferences", "resolves", "references", "found", "inside", "Protocols", "objects", "." ]
909070f02b666e4e9adf7eda93c304a8ba2a8063
https://github.com/googleapis/gnostic/blob/909070f02b666e4e9adf7eda93c304a8ba2a8063/discovery/discovery.go#L1945-L1960