microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.75k stars 550 forks source link

[JavaScript] toJSON() in 2.1.0 sets incorrect version (1.3) when another (1.2) is specified #4620

Closed darrenparkinson closed 4 years ago

darrenparkinson commented 4 years ago

Platform

Author or host

Author. Sending cards to Webex Teams, but the issue is before it gets there.

Version of SDK

Issue is between version 2.0.0 and 2.1.0 of the JavaScript sdk loaded from npm.

Details

I have some code using 2.0.0 (below) which provides output as expected from toJSON(). When 2.1.0 is used, toJSON() sends the latest version. This is alluded to in the release notes but I am specifying a version which is not being honoured.

The following code is from the documentation:

const Adaptive = require('adaptivecards');

function createCard() {
    let card = new Adaptive.AdaptiveCard();
    card.version = new Adaptive.Version(1, 2);
    let textBlock = new Adaptive.TextBlock();
    textBlock.text = "Hello World";
    card.addItem(textBlock);
    return card.toJSON();
}

console.log(createCard())

Version 2.0.0 renders the following:

{
  type: 'AdaptiveCard',
  '$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
  version: '1.2',
  body: [ { type: 'TextBlock', text: 'Hello World' } ]
}

Version 2.1.0 renders the following:

{
  type: 'AdaptiveCard',
  '$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
  version: '1.3',
  body: [ { type: 'TextBlock', text: 'Hello World' } ]
}

Version 1.3 is not supported on the host and so is failing.

shalinijoshi19 commented 4 years ago

@dclaux could you please take a look at this? Thanks

ghost commented 4 years ago

Hi @darrenparkinson. We have acknowledged this issue report. Please continue to follow this issue for updates/progress/questions.

dclaux commented 4 years ago

@darrenparkinson all AC SDKs always serialize to the latest supported schema version. Now that we have shipped support for AC schema 1.3, toJSON will always generate a card with its version set to 1.3 by default, that is by design. But since v2.0 of the JS SDK, you can now explicitly specify which version of the schema you want to serialize to, which is what you have to do here:

card.toJSON(new SerializationContext(Versions.v1_2));
ghost commented 4 years ago

:tada:AdaptiveCards@2020.08 has been released which fixes this issue.:tada:

Handy links: