discord / discord-api-spec

OpenAPI specification for Discord APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve create message route

A5rocks opened this issue · comments

Currently, the create message route is... kinda sucky:

"properties": {
"files[0]": {
"type": "string",
"contentEncoding": "binary"
},
"files[1]": {
"type": "string",
"contentEncoding": "binary"
},
"files[2]": {
"type": "string",
"contentEncoding": "binary"
},
"files[3]": {
"type": "string",
"contentEncoding": "binary"
},
"files[4]": {
"type": "string",
"contentEncoding": "binary"
},
"files[5]": {
"type": "string",
"contentEncoding": "binary"
},
"files[6]": {
"type": "string",
"contentEncoding": "binary"
},
"files[7]": {
"type": "string",
"contentEncoding": "binary"
},
"files[8]": {
"type": "string",
"contentEncoding": "binary"
},
"files[9]": {
"type": "string",
"contentEncoding": "binary"
}
}

This could be better expressed as:

"patternProperties": {
  "^files\\[[0-9]+\\]$": {
    "type": "string",
    "contentEncoding": "binary"
  }
}

using patternProperties.

🤔 pretty sure the ID can be any snowflake as well

Yeah this uses a regex to say the number is any sequence of digits. I would use \d but that's not in the restricted subset of regex JSON schema recommends :(

This is a technical limitation needed to express that we don't accept unlimited uploads in a single request. (In general, for requests, I'd prefer that the spec expresses a subset rather than a superset of allowed inputs, if it can't be exactly precise).

How about using maxProperties then? IIRC you can only send the payload_json key for the form body (... maybe I'm misremembering?) so just set the max number of properties to the max amount of files + 1? (... or maybe without the +1?).

i think we currently accept body properties as form properties (but if payload_json is present, they all have to be in there instead)? i could be wrong as well

I checked, you're correct. Maybe there should be an oneOf where one branch allows only these fixed names and no payload_json, and the other branch allows any file numbers and only an extra payload_json field?

(I imagine "the other branch" is the significantly more common case; that's how I've implemented things before :P)