Beispiel #1
0
func (g *Generator) generateDefinition(msg *descriptor.Message) *spec.Schema {
	s := new(spec.Schema)
	s.Title = msg.GetModelName()
	s.Properties = make(map[string]spec.Schema)
	s.Required = make([]string, 0)
	s.ExtraProps = make(map[string]interface{})

	// handle comments.
	if cmt := g.file.GetCommentText(msg.CommentPath); cmt != nil {
		s.Description = *cmt
	}

	// iterate over fields.
	for _, field := range msg.Fields {
		prop := g.generateProperty(field)

		if field.GetLabel() == godesc.FieldDescriptorProto_LABEL_REQUIRED {
			s.Required = append(s.Required, field.GetName())
		}

		s.Properties[field.GetName()] = *prop
	}

	// if msg.EnumType != nil {
	// 	s.ExtraProps["ext_enumType"] = msg.GetEnumType()
	// }
	// if msg.Extension != nil {
	// 	s.ExtraProps["ext_extension"] = msg.GetExtension()
	// }
	// if msg.ExtensionRange != nil {
	// 	s.ExtraProps["ext_extensionRange"] = msg.GetExtensionRange()
	// }
	// if msg.NestedType != nil {
	// 	s.ExtraProps["ext_nestedType"] = msg.GetNestedType()
	// }
	// if msg.OneofDecl != nil {
	// 	s.ExtraProps["ext_oneofDecl"] = msg.GetOneofDecl()
	// }
	// if msg.Options != nil {
	// 	s.ExtraProps["ext_options"] = msg.GetOptions()
	// }

	return s
}
Beispiel #2
0
func messageRef(m *descriptor.Message) spec.Ref {
	return spec.MustCreateRef("#/definitions/" + m.GetModelName())
}