0

Consider this simple program:

using System;
using YamlDotNet.RepresentationModel;

namespace TestYamlNode
{
    class Program
    {
        static void Main(string[] args)
        {
            var scalarNode = new YamlScalarNode("!yada");
            scalarNode.Style = YamlDotNet.Core.ScalarStyle.Plain;
            var serializer = new YamlDotNet.Serialization.Serializer();
            serializer.Serialize(Console.Out, scalarNode);

            scalarNode = new YamlScalarNode("yada");
            scalarNode.Style = YamlDotNet.Core.ScalarStyle.Plain;
            serializer.Serialize(Console.Out, scalarNode);
        }
    }
}

The oputput of the program is:

'!yada'

yada

Is there a way to tell YamlDotNet to not include single quotes in the output when it has characters like !, { etc. included in it? For some context, I'm processing a AWS SAM template that has a property that looks like this:

uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PetStorePetFunc.Arn}/invocations

TimMay
  • 1
  • 2

1 Answers1

0

OK - so after playing with this a bit, I realized that I asked what might be a dumb question. In my use case I'm trying to generate an output with the form:

uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PetStorePetFunc.Arn}/invocations

It looks like the correct way to do this is to use the Tag property on the YamlScalarNode: example:

var node = new YamlScalarNode("arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PetStorePetFunc.Arn}/invocations");
node.Tag = "!Sub";
TimMay
  • 1
  • 2