Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required fields in Objs* classes should not be nullable #141

Open
mpyw opened this issue Jan 24, 2022 · 1 comment
Open

Required fields in Objs* classes should not be nullable #141

mpyw opened this issue Jan 24, 2022 · 1 comment

Comments

@mpyw
Copy link
Contributor

mpyw commented Jan 24, 2022

{
  "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()));
@lyrixx
Copy link
Member

lyrixx commented Apr 19, 2023

Hello,

Sorry for the very late reply.

Did you manage to solve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants