Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template warnings only consist of invalid '$when' conditions #9074

Open
sbaluja opened this issue Dec 17, 2024 · 2 comments
Open

Template warnings only consist of invalid '$when' conditions #9074

sbaluja opened this issue Dec 17, 2024 · 2 comments

Comments

@sbaluja
Copy link

sbaluja commented Dec 17, 2024

Problem

The behavior of the Template.getLastTemplateExpansionWarnings() function differs from other SDKs, such as the .NET WPF SDK. Currently, the list of warnings returned contains only warnings related to $when conditions, with no other types of warnings being included.

Upon reviewing the source code, it appears that the templateExpansionWarnings array is only populated for invalid $when conditions. However, the description for this array states that it "stores any warnings that occurred while expanding the template," which does not align with the current implementation.

Expected behavior

To resolve this, either the list of warnings should be expanded to include other types of warnings, or the behavior should be documented to clarify that only $when conditions are currently reported. As it stands, the current implementation is misleading.

@Meghana-MSFT
Copy link

@sbaluja - Could you please share more details on how you are calling this function. Please share small piece of code sample and any documentation you are referring to.

@sbaluja
Copy link
Author

sbaluja commented Dec 18, 2024

@Meghana-MSFT

Consider the following Adaptive Card JSON with an invalid property for size (Valid values: "small", "default", "medium", "large", "extraLarge"):

{
    "type": "AdaptiveCard",
    "body": [{
            "type": "TextBlock",
            "size": "big",
            "weight": "bolder",
            "text": "Sample Title"
        },
        {
            "type": "ColumnSet",
            "columns": [{
                    "type": "Column",
                    "items": [{
                        "type": "Image",
                        "style": "Person",
                        "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
                        "size": "Small"
                    }],
                    "width": "auto"
                },
                {
                    "type": "Column",
                    "items": [{
                            "type": "TextBlock",
                            "weight": "Bolder",
                            "text": "Matt Hidinger",
                            "wrap": true
                        },
                        {
                            "type": "TextBlock",
                            "spacing": "None",
                            "text": "Created {{DATE(2017-02-14T06:08:39Z,SHORT)}}",
                            "isSubtle": true,
                            "wrap": true
                        }
                    ],
                    "width": "stretch"
                }
            ]
        },
        {
            "type": "TextBlock",
            "text": "Sample Description",
            "wrap": true
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5"
}

The following code within the C# WPF SDK generates an AdaptiveCardParsedResult object where cardJson is the above JSON:

AdaptiveCardTemplate template = new AdaptiveCardTemplate(cardJson);
var cardJson = template.Expand();
var parsedCard = AdaptiveCard.FromJson(cardJson);

The property parsedCard.Warnings appropriately contains a single AdaptiveWarning, with a message about the invalid 'big' property:

Value "big" could not be converted to "AdaptiveCards.AdaptiveTextSize", using the default value of "Default"

However, the Javascript SDK does not behave this way, with the same JSON

const template = new Template(payloadJSON);
const payload = template.expand({});

The function template.getLastTemplateExpansionWarnings() which is meant to return the internal private string array templateExpansionWarnings, is empty and does not contain a warning for the invalid property value, despite it also using the default value instead.

I've looked through the source code for when the templateExpansionWarnings array is added to, and it seems to be only for invalid $when conditions. As a result, the array only contains warnings for invalid $when conditions, despite the function declaration of getLastTemplateExpansionWarnings() containing a comment for returning an array with all warnings:

    /**
     * Getter method for the array of warning strings
     * @returns An array storing any warnings that occurred while expanding the template
     */
    public getLastTemplateExpansionWarnings(): string[] {
        return this.templateExpansionWarnings;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants