in packages/typespec-go/src/tcgcadapter/types.ts [888:941]
export function adaptXMLInfo(decorators: Array<tcgc.DecoratorInfo>, field?: go.ModelField): go.XMLInfo | undefined {
// if there are no decorators and this isn't a slice
// type in a model field then do nothing
if (decorators.length === 0 && (!field || (!go.isSliceType(field.type)))) {
return undefined;
}
const xmlInfo = new go.XMLInfo();
if (field && go.isSliceType(field.type)) {
// for tsp, arrays are wrapped by default
xmlInfo.wraps = go.getTypeDeclaration(field.type.elementType);
}
const handleName = (decorator: tcgc.DecoratorInfo): void => {
if (field) {
xmlInfo.name = <string>decorator.arguments['name'];
} else {
// when applied to a model, it means the model's XML element
// node has a different name than the model.
xmlInfo.wrapper = <string>decorator.arguments['name'];
}
};
for (const decorator of decorators) {
switch (decorator.name) {
case 'TypeSpec.@encodedName':
if (decorator.arguments['mimeType'] === 'application/xml') {
handleName(decorator);
}
break;
case 'TypeSpec.Xml.@attribute':
xmlInfo.attribute = true;
break;
case 'TypeSpec.Xml.@name':
handleName(decorator);
break;
case 'TypeSpec.Xml.@unwrapped':
// unwrapped can only be applied fields
if (field) {
if (go.isPrimitiveType(field.type) && field.type.typeName === 'string') {
// an unwrapped string means it's text
xmlInfo.text = true;
} else if (go.isSliceType(field.type)) {
// unwrapped slice. default to using the serialized name
xmlInfo.wraps = undefined;
xmlInfo.name = field.serializedName;
}
}
break;
}
}
return xmlInfo;
}