RenaudLN commented on issue #16427:
URL: https://github.com/apache/echarts/issues/16427#issuecomment-4394629464

   Here's my attempt at creating a json schema from the blob
   
   ```py
   def generate_echarts_json_schema():
       """Generate a JSON schema for ECharts `option`."""
       raw = 
requests.get("https://raw.githubusercontent.com/apache/echarts-website/refs/heads/asf-site/en/documents/option.json";).json()
   
       def _strip(node: object, parent_key: str | None = None) -> object:
           if isinstance(node, dict):
               result = {}
               for k, v in node.items():
                   if k in ("description", "uiControl"):
                       continue
                   if k == "type":
                       if parent_key == "properties" and isinstance(v, dict) 
and "default" in v:
                           # Use const for discriminated union in 
properties.type
                           default_val = v["default"]
                           result[k] = {"const": default_val.strip("'") if 
isinstance(default_val, str) else default_val}
                       elif v == 'Color' or v == ['Color']:
                           # Use format for colors (requires `webcolors` to be 
installed)
                           result['type'] = 'string'
                           result['format'] = 'color'
                       elif isinstance(v, str):
                           result[k] = v.lower()
                       elif isinstance(v, list):
                           result[k] = [item.lower() if isinstance(item, str) 
else item for item in v]
                       else:
                           result[k] = _strip(v, k)
                   elif k == "items" and parent_key == "data":
                       # Missing simplified items options
                       result[k] = {
                           "anyOf": [
                               {"type": ["string", "number"]},
                               _strip(v, k),
                           ]
                       }
                   elif k == "default":
                       if isinstance(v, str):
                           result[k] = v.strip("'")
                       else:
                           result[k] = v
                   else:
                       result[k] = _strip(v, k)
               return result
           if isinstance(node, list):
               return [_strip(item, parent_key) for item in node]
           return node
   
       schema = _strip(raw)
       return schema
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to