Page MenuHomePhabricator

Treat empty optional localized fields as missing during validation
Open, Needs TriagePublic

Description

Background

Some fields in the chart definition json are optional like subtitle. The subtitle field accepts localized string values like:

{
  "subtitle": {
    "de": "Bevölkerung im Jahr 2025",
    "en": "Population in 2025",
  }
}

If subtitle is an empty object, then there are validation errors but perhaps the chart validation could handle this more gracefully and treat the value as missing or empty.

In the ChartWizard project, I was seeing:

Parameter "subtitle" must be an object that maps valid language codes to single line strings no longer than 400 characters, without tabs or trailing spaces, e.g. { "en":"String in English", ... } when the chart definition json had "subtitle": {}

Proposed solution

In JCChartContent, add handling for optional localized fields, and consider normalizing so that when the chart definition has, "subtitle": {} then it can be omitted.

Event Timeline

Hi @aude ! Before I start working on this, could you clarify the intended scope? Should treating {} as missing apply only to subtitle, or to all optional localized fields in JCChartContent like title, legend, xAxis.title, yAxis.title, etc.? I want to keep the change appropriately scoped. Thanks!

Change #1308207 had a related patch set uploaded (by Zaidusyy; author: Zaidusyy):

[mediawiki/extensions/Chart@master] Treat empty localized fields as missing during validation

https://gerrit.wikimedia.org/r/1308207