discord-api-spec icon indicating copy to clipboard operation
discord-api-spec copied to clipboard

Improve create message route

Open A5rocks opened this issue 1 year ago • 6 comments

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

https://github.com/discord/discord-api-spec/blob/bab7bf1988b7a49fb8f45fae936126122d0a25e4/specs/openapi.json#L4496-L4537

This could be better expressed as:

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

using patternProperties.

A5rocks avatar Aug 02 '23 21:08 A5rocks

🤔 pretty sure the ID can be any snowflake as well

IanMitchell avatar Aug 02 '23 21:08 IanMitchell

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 :(

A5rocks avatar Aug 02 '23 21:08 A5rocks

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).

infinitestory avatar Aug 02 '23 22:08 infinitestory

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?).

A5rocks avatar Aug 02 '23 23:08 A5rocks

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

infinitestory avatar Aug 02 '23 23:08 infinitestory

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)

A5rocks avatar Aug 03 '23 01:08 A5rocks