in tensorflow/src/main/scala/magnolify/tensorflow/ExampleType.scala [136:158]
override protected def buildSchema(cm: CaseMapper): Schema = {
val sb = Schema.newBuilder()
getDoc(caseClass.annotations, caseClass.typeName.full).foreach(sb.setAnnotation)
caseClass.parameters.foldLeft(sb) { (b, p) =>
val fieldNane = cm.map(p.label)
val fieldSchema = p.typeclass.schema(cm)
val fieldFeatures = fieldSchema.getFeatureList.asScala.map { f =>
val fb = f.toBuilder
// if schema does not have a name (eg. primitive), use the fieldNane
// otherwise prepend to the feature name (eg. nested records)
val fieldKey = if (f.hasName) key(fieldNane, f.getName) else fieldNane
fb.setName(fieldKey)
// if field already has a doc, keep it
// otherwise use the parameter annotation
val fieldDoc = getDoc(p.annotations, s"${caseClass.typeName.full}#$fieldKey")
if (!f.hasAnnotation) fieldDoc.foreach(fb.setAnnotation)
fb.build()
}.asJava
b.addAllFeature(fieldFeatures)
b
}
sb.build()
}