Description
PR #374 removed mapping for Photo -> InputPhotoFileLocation
due to InputPhotoFileLocation
requires ThumbSize
field.
But gotdgen
can generate mapping like AsInputPhotoFileLocation(thumbSize string) *tg.InputPhotoFileLocation
, where thumbSize
passed by user.
References
mappableFields
returns possible As
mapping.
|
func mappableFields(constructor, to structDef) (constructorMapping, bool) { |
|
var r []fieldPair |
|
mapped := map[string]struct{}{} |
|
for _, a := range constructor.Fields { |
|
if a.Type == flagsType { |
|
continue |
|
} |
|
|
|
for _, b := range to.Fields { |
|
if b.Type == flagsType { |
|
continue |
|
} |
|
|
|
if a.SameType(b) && strings.Contains(b.Name, a.Name) { |
|
r = append(r, fieldPair{a, b}) |
|
mapped[b.Name] = struct{}{} |
|
} |
|
} |
|
} |
|
|
|
// Return false if we can't fill all fields. |
|
if len(mapped) != len(to.Fields) { |
|
for _, field := range to.Fields { |
|
if _, ok := mapped[field.Name]; !ok && !optionalField(to, field) { |
|
return constructorMapping{}, false |
|
} |
|
} |
|
} |
|
|
|
mapperName := to.Name |
|
// Mapping: User => InputUser, so mapperName = "Input" |
|
// Mapping: Document => InputDocumentFileLocation, so mapperName = "InputDocumentFileLocation" |
|
if strings.HasSuffix(to.Name, constructor.Name) { |
|
mapperName = strings.TrimSuffix(to.Name, constructor.Name) |
|
} |
|
|
|
mapping := constructorMapping{ |
|
Name: to.Name, |
|
Constructor: constructor.Name, |
|
Concrete: true, |
|
MapperName: mapperName, |
|
Fields: r, |
|
} |
|
|
|
return mapping, true |
|
} |