slack-php-api icon indicating copy to clipboard operation
slack-php-api copied to clipboard

Required fields in `Objs*` classes should not be nullable

Open mpyw opened this issue 4 years ago • 1 comments

{
  "additionalProperties": false,
  "properties": {
    "attachments": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "fallback": {
            "type": "string"
          },
          "id": {
            "type": "integer"
          },
          "image_bytes": {
            "type": "integer"
          },
          "image_height": {
            "type": "integer"
          },
          "image_url": {
            "type": "string"
          },
          "image_width": {
            "type": "integer"
          }
        },
        "required": [
          "id"
        ],
        "type": "object"
      },
      "minItems": 1,
      "type": "array",
      "uniqueItems": true
    },
    "blocks": {
      "$ref": "#/definitions/blocks"
    },
    "bot_id": {
      "items": [
        {
          "$ref": "#/definitions/defs_bot_id"
        },
        {
          "title": "Nil bot_id set when display_as_bot is false",
          "type": "null"
        }
      ]
    },
    "bot_profile": {
      "$ref": "#/definitions/objs_bot_profile"
    },
    "client_msg_id": {
      "type": "string"
    },
    "comment": {
      "$ref": "#/definitions/objs_comment"
    },
    "display_as_bot": {
      "type": "boolean"
    },
    "file": {
      "$ref": "#/definitions/objs_file"
    },
    "files": {
      "items": {
        "$ref": "#/definitions/objs_file"
      },
      "minItems": 1,
      "type": "array",
      "uniqueItems": true
    },
    "icons": {
      "additionalProperties": false,
      "properties": {
        "emoji": {
          "type": "string"
        },
        "image_64": {
          "format": "uri",
          "type": "string"
        }
      },
      "type": "object"
    },
    "inviter": {
      "$ref": "#/definitions/defs_user_id"
    },
    "is_delayed_message": {
      "type": "boolean"
    },
    "is_intro": {
      "type": "boolean"
    },
    "is_starred": {
      "type": "boolean"
    },
    "last_read": {
      "$ref": "#/definitions/defs_ts"
    },
    "latest_reply": {
      "$ref": "#/definitions/defs_ts"
    },
    "name": {
      "type": "string"
    },
    "old_name": {
      "type": "string"
    },
    "parent_user_id": {
      "$ref": "#/definitions/defs_user_id"
    },
    "permalink": {
      "format": "uri",
      "type": "string"
    },
    "pinned_to": {
      "items": {
        "$ref": "#/definitions/defs_channel"
      },
      "type": "array"
    },
    "purpose": {
      "type": "string"
    },
    "reactions": {
      "items": {
        "$ref": "#/definitions/objs_reaction"
      },
      "type": "array"
    },
    "reply_count": {
      "type": "integer"
    },
    "reply_users": {
      "items": {
        "$ref": "#/definitions/defs_user_id"
      },
      "minItems": 1,
      "type": "array",
      "uniqueItems": true
    },
    "reply_users_count": {
      "type": "integer"
    },
    "source_team": {
      "$ref": "#/definitions/defs_workspace_id"
    },
    "subscribed": {
      "type": "boolean"
    },
    "subtype": {
      "type": "string"
    },
    "team": {
      "$ref": "#/definitions/defs_workspace_id"
    },
    "text": {
      "type": "string"
    },
    "thread_ts": {
      "$ref": "#/definitions/defs_ts"
    },
    "topic": {
      "type": "string"
    },
    "ts": {
      "$ref": "#/definitions/defs_ts"
    },
    "type": {
      "type": "string"
    },
    "unread_count": {
      "type": "integer"
    },
    "upload": {
      "type": "boolean"
    },
    "user": {
      "$ref": "#/definitions/defs_user_id"
    },
    "user_profile": {
      "$ref": "#/definitions/objs_user_profile_short"
    },
    "user_team": {
      "$ref": "#/definitions/defs_workspace_id"
    },
    "username": {
      "type": "string"
    }
  },
  "required": [
    "text",
    "type",
    "ts"
  ],
  "title": "Message object",
  "type": "object"
}

It shows that the following fields are required.

  • text
  • type
  • ts

But the implementations are like this:

public function getType(): ?string
{
    return $this->type;
}

public function getText(): ?string
{
    return $this->text;
}

public function getTs(): ?string
{
    return $this->ts;
}

I have a question:

  • Is it a restrictive specification of the Symfony Serializer Component? Do setters force its returning types to always contain null?
    • If so, do we have to always apply assertions like this?: assert(is_string($type = $message->getType()));

mpyw avatar Jan 24 '22 03:01 mpyw

Hello,

Sorry for the very late reply.

Did you manage to solve your issue?

lyrixx avatar Apr 19 '23 11:04 lyrixx