本文整理汇总了Golang中limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor.Path方法的典型用法代码示例。如果您正苦于以下问题:Golang Descriptor.Path方法的具体用法?Golang Descriptor.Path怎么用?Golang Descriptor.Path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类limbo/services/protobuf/protoc-gen-gogo/generator.Descriptor
的用法示例。
在下文中一共展示了Descriptor.Path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: messageToSchema
func (g *jsonschema) messageToSchema(file *generator.FileDescriptor, desc *generator.Descriptor) (interface{}, []string) {
typeName := file.GetPackage() + "." + strings.Join(desc.TypeName(), ".")
typeName = strings.TrimPrefix(typeName, ".")
title := desc.TypeName()[len(desc.TypeName())-1]
var (
dependencies []string
properties = make(map[string]interface{})
requiredProperties []string
)
for i, field := range desc.GetField() {
if field.OneofIndex != nil {
continue
}
f, dep := g.fieldToSchema(field)
if f == nil {
continue
}
if limbo.IsRequiredProperty(field) {
requiredProperties = append(requiredProperties, getJSONName(field))
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
comment = strings.TrimSpace(comment)
if comment != "" {
f["description"] = comment
}
}
properties[getJSONName(field)] = f
if dep != "" {
dependencies = append(dependencies, dep)
}
}
schema := map[string]interface{}{
"type": "object",
"properties": properties,
}
if len(requiredProperties) > 0 {
schema["required"] = requiredProperties
}
if len(desc.OneofDecl) > 0 {
allOffDefs := make([]interface{}, 0, 1+len(desc.OneofDecl))
oneOfDefs := make([][]interface{}, len(desc.OneofDecl))
for i, field := range desc.GetField() {
if field.OneofIndex == nil {
continue
}
oneofIndex := *field.OneofIndex
f, dep := g.fieldToSchema(field)
if f == nil {
continue
}
if field.IsRepeated() {
f = map[string]interface{}{
"type": "array",
"items": f,
}
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 2, i))
comment = strings.TrimSpace(comment)
if comment != "" {
f["description"] = comment
}
}
def := map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
getJSONName(field): f,
},
"required": []string{getJSONName(field)},
}
oneOfDefs[oneofIndex] = append(oneOfDefs[oneofIndex], def)
if dep != "" {
dependencies = append(dependencies, dep)
}
}
allOffDefs = append(allOffDefs, schema)
for i, defs := range oneOfDefs {
def := map[string]interface{}{
"oneOf": defs,
}
{
comment := g.gen.Comments(fmt.Sprintf("%s,%d,%d", desc.Path(), 8, i))
comment = strings.TrimSpace(comment)
//.........这里部分代码省略.........