HubSpot / slack-client

An asynchronous HTTP client for Slack's web API
Apache License 2.0
114 stars 53 forks source link

Default to `false` for text styles #306

Closed motnyk closed 1 year ago

motnyk commented 1 year ago

We broke the serialization of TextStyleIF in https://github.com/HubSpot/slack-client/pull/304 because if Optional is empty we pass "code": null to Slack and it returns us response like this:

{
  "ok" : false,
  "error" : "invalid_blocks",
  "warning" : "missing_charset",
  "response_metadata" : {
    "messages" : [ "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/1/style/italic]", "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/1/style/strike]", "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/1/style/code]", "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/7/style/bold]", "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/7/style/italic]", "[ERROR] must be a boolean [json-pointer:/blocks/0/elements/0/elements/7/style/strike]" ],
    "warnings" : [ "missing_charset" ]
  }
}

We have to exclude the fields completely if Optional is empty or make them default to false. I think the latter option makes way more sense since Optional<Boolean> itself doesn't make a lot of sense and only complicates the interaction the code.