slackapi / slack-api-specs

Open API specifications for platform products by Slack
MIT License
222 stars 64 forks source link

Block Kit support #18

Open seratch opened 5 years ago

seratch commented 5 years ago

Description

The documentation already supports Block Kit. However, the changes to parameters/response are not yet reflected in this repository. Do you have any plans to work on it in the short term? If I can do something for it, I am keen to be involved in it.

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])

episod commented 5 years ago

We want to offer full JSON schema (and a subset within our OpenAPI specs) for Block Kit but aren't yet ready to do so. In the meantime, the newest version of the spec on master includes a bare bones schema for blocks and includes the blocks parameter on methods that support them. Look for deeper support (including the difference between input and output blocks) in the future.

simonh1000 commented 4 years ago

it would be wonderful if you could open source the validation code in https://app.slack.com/block-kit-builder

x3ro commented 1 year ago

Curious to see that there hasn't been any notice on this for almost four years. As far as I can see, Block Kit is still the way to go for displaying UI in Slack, right? Having no way to validate it makes for fairly poor developer experience 😕

riffraff commented 1 year ago

it's quite hard to plan an integration and be sure it will work with real data without a schema, it would be great if you could publish it.

fab-mindflow commented 1 year ago

+1 It makes a lot of sense to add BlockKit JSON schema to OpenAPI specifications. Any news on this?

fab-mindflow commented 1 year ago

Btw, it looks like this JSON schema exists: https://gist.github.com/renatorib/1fb1a9bd71435b41bee602d15bc56899

Would it be possible to share this JSON schema officially?

delanni commented 1 year ago

The schema that's mentioned in the gist, and here by @fab-mindflow is incomplete, it cuts out after ~18k characters, so it's an invalid schema right now.

fab-mindflow commented 1 year ago

This was first open in 2019. Can someone at Slack take a look please?

lawrencegripper commented 1 year ago

Nudging this as it's super painful having to manually copy paste to the block builder website or only find out in a live system. I'd like to wrap my block generation client side in a unit test which validates the output against the JSON schema.

Given the tooling on the block kit builder has this to validate against I was hoping it's easy to publish :pray:

lawrencegripper commented 1 year ago

I'm not someone at slack but took a look!

TLDR: With some manual effort and the typescript type information I semi-auto generated the schema. Here it is for others to use. Note: It validates an array of blocks for input.

 [
    {
        "type": "header",
        "text": {
            "type": "plain_text",
            "text": "some message",
            "emoji": true
        }
     }
]

How?:

Talking with @itoys he suggested this approach using the typescript definitions for blocks to create a schema.

Doing that over this file gave me the definitions for the block types available :partying_face:

I then needed a top level definition for the to match the possible different block types, I did this with if-then syntax for json schema.

    "type": "object",
    "properties": {
      "type": {
        "enum": [
          "image",
          "context",
          "actions",
          "divider",
          "section",
          "input",
          "file",
          "header",
          "video",
          "rich_text"
        ]
      }
    },
    "required": [
      "type"
    ],
    "additionalProperties": true,
    "allOf": [
      {
        "if": {
          "properties": {
            "type": {
              "const": "image"
            }
          }
        },
        "then": {
          "$ref": "#/definitions/ImageBlock"
        }
      },
      {
        "if": {
          "properties": {
            "type": {
              "const": "context"
            }
          }
        },
        "then": {
          "$ref": "#/definitions/ContextBlock"
        }
      },
lawrencegripper commented 1 year ago

Thanks to @okeeffed for the typescript to json schema code and awesome blog 🙇‍♂️

okeeffed commented 1 year ago

Stoked that it managed to help out @lawrencegripper ❤️

davidcelis commented 1 year ago

That schema is unfortunately also incomplete; many of Slack's blocks have limits on how many elements can appear in a list (e.g. an upper limit of 100 options in a dropdown select's options field) or how long various strings can be (e.g. a 150 character limit for the text element in a header block) or even how many blocks a single definition is limited to.