[JS][Authoring] Custom fields based on `Image` not being serialised
See original GitHub issueTarget Application
Twist.com (our own renderer)
Problem Description
I have created a custom component that extends the Image
class, the class itself is fairly simple, it’s literally just:
export class Imageist extends Image {
static readonly JsonTypeName = 'Image'
static readonly aspectRatioProperty = new NumProperty(Versions.v1_0, 'aspectRatio')
@property(Imageist.aspectRatioProperty)
aspectRatio?: number
getJsonTypeName(): string {
return Imageist.JsonTypeName
}
}
When I try and use this new field in my application, it doesn’t get serialised. Calling getSchema()
on it doesn’t show the new field at all and I’m unsure why.
I have created a few custom components with additional fields in exactly the same way and all of them have worked without an issue. An example is one based on TextInput
export class TextInputist extends TextInput {
static readonly JsonTypeName = 'Input.Text'
static readonly rowsProperty = new NumProperty(Versions.v1_0, 'rows')
static readonly inputStyleProperty = new StringProperty(Versions.v1_0, 'inputStyle')
@property(TextInputist.rowsProperty)
rows?: number
@property(TextInputist.inputStyleProperty)
inputStyle?: InputStyle
getJsonTypeName(): string {
return TextInputist.JsonTypeName
}
}
The new fields here (rows
and inputStyle
) get serialised just fine without having to do anything except use them. I’ve actually created custom versions of AdaptiveCard
, TextInput
, and ChoiceSetInput
all with additional fields, and none of them have had an issue when it comes to being serialised.
I wonder whether it has anything to do with the fact none of the others I’ve done had a base class that overrode the populateSchema
function? I actually did try this, and added my own override that explictly adds the aspectRatioProperty
to the schema, but it still gets ignored.
Expected Outcome
I was expecting the new fields to be serialised in the same way as other new components I’ve written.
Actual Outcome
The new fields don’t appear in the schema and so aren’t serialised.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
@scottlovegrove technically, you shouldn’t have to override
getSchemaKey
, that’s why I didn’t document it explicitly. By default,getSchemaKey
returns the same value asgetJsonTypeName
. But the assumption is that most of the time, any given JSON type name will be used by a single class. Your (perfectly valid) implementation ofImageist
uses the same JSON type name as the built-inImage
, and so it has the same schema key, which is why in that “special” case you need to overridegetSchemaKey
.THanks @dclaux that fixed it 👍🏻 Is that something I missed somewhere in the docs? Looking at this I can’t see any mention of that function. This is basically where I started with our new components.