[OpenAPI] Mark all not required request fields as nullable

This commit is contained in:
Egor Kislitsyn 2020-05-15 14:55:41 +04:00
parent 907acbf62b
commit e090191d03
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
8 changed files with 134 additions and 23 deletions

View File

@ -367,15 +367,18 @@ defp create_request do
title: "AccountCreateRequest", title: "AccountCreateRequest",
description: "POST body for creating an account", description: "POST body for creating an account",
type: :object, type: :object,
required: [:username, :password, :agreement],
properties: %{ properties: %{
reason: %Schema{ reason: %Schema{
type: :string, type: :string,
nullable: true,
description: description:
"Text that will be reviewed by moderators if registrations require manual approval" "Text that will be reviewed by moderators if registrations require manual approval"
}, },
username: %Schema{type: :string, description: "The desired username for the account"}, username: %Schema{type: :string, description: "The desired username for the account"},
email: %Schema{ email: %Schema{
type: :string, type: :string,
nullable: true,
description: description:
"The email address to be used for login. Required when `account_activation_required` is enabled.", "The email address to be used for login. Required when `account_activation_required` is enabled.",
format: :email format: :email
@ -392,23 +395,33 @@ defp create_request do
}, },
locale: %Schema{ locale: %Schema{
type: :string, type: :string,
nullable: true,
description: "The language of the confirmation email that will be sent" description: "The language of the confirmation email that will be sent"
}, },
# Pleroma-specific properties: # Pleroma-specific properties:
fullname: %Schema{type: :string, description: "Full name"}, fullname: %Schema{type: :string, nullable: true, description: "Full name"},
bio: %Schema{type: :string, description: "Bio", default: ""}, bio: %Schema{type: :string, description: "Bio", nullable: true, default: ""},
captcha_solution: %Schema{ captcha_solution: %Schema{
type: :string, type: :string,
nullable: true,
description: "Provider-specific captcha solution" description: "Provider-specific captcha solution"
}, },
captcha_token: %Schema{type: :string, description: "Provider-specific captcha token"}, captcha_token: %Schema{
captcha_answer_data: %Schema{type: :string, description: "Provider-specific captcha data"}, type: :string,
nullable: true,
description: "Provider-specific captcha token"
},
captcha_answer_data: %Schema{
type: :string,
nullable: true,
description: "Provider-specific captcha data"
},
token: %Schema{ token: %Schema{
type: :string, type: :string,
nullable: true,
description: "Invite token required when the registrations aren't public" description: "Invite token required when the registrations aren't public"
} }
}, },
required: [:username, :password, :agreement],
example: %{ example: %{
"username" => "cofe", "username" => "cofe",
"email" => "cofe@example.com", "email" => "cofe@example.com",
@ -447,28 +460,34 @@ defp update_creadentials_request do
properties: %{ properties: %{
bot: %Schema{ bot: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Whether the account has a bot flag." description: "Whether the account has a bot flag."
}, },
display_name: %Schema{ display_name: %Schema{
type: :string, type: :string,
nullable: true,
description: "The display name to use for the profile." description: "The display name to use for the profile."
}, },
note: %Schema{type: :string, description: "The account bio."}, note: %Schema{type: :string, description: "The account bio."},
avatar: %Schema{ avatar: %Schema{
type: :string, type: :string,
nullable: true,
description: "Avatar image encoded using multipart/form-data", description: "Avatar image encoded using multipart/form-data",
format: :binary format: :binary
}, },
header: %Schema{ header: %Schema{
type: :string, type: :string,
nullable: true,
description: "Header image encoded using multipart/form-data", description: "Header image encoded using multipart/form-data",
format: :binary format: :binary
}, },
locked: %Schema{ locked: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Whether manual approval of follow requests is required." description: "Whether manual approval of follow requests is required."
}, },
fields_attributes: %Schema{ fields_attributes: %Schema{
nullable: true,
oneOf: [ oneOf: [
%Schema{type: :array, items: attribute_field()}, %Schema{type: :array, items: attribute_field()},
%Schema{type: :object, additionalProperties: %Schema{type: attribute_field()}} %Schema{type: :object, additionalProperties: %Schema{type: attribute_field()}}
@ -488,47 +507,65 @@ defp update_creadentials_request do
# Pleroma-specific fields # Pleroma-specific fields
no_rich_text: %Schema{ no_rich_text: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "html tags are stripped from all statuses requested from the API" description: "html tags are stripped from all statuses requested from the API"
}, },
hide_followers: %Schema{type: :boolean, description: "user's followers will be hidden"}, hide_followers: %Schema{
hide_follows: %Schema{type: :boolean, description: "user's follows will be hidden"}, type: :boolean,
nullable: true,
description: "user's followers will be hidden"
},
hide_follows: %Schema{
type: :boolean,
nullable: true,
description: "user's follows will be hidden"
},
hide_followers_count: %Schema{ hide_followers_count: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "user's follower count will be hidden" description: "user's follower count will be hidden"
}, },
hide_follows_count: %Schema{ hide_follows_count: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "user's follow count will be hidden" description: "user's follow count will be hidden"
}, },
hide_favorites: %Schema{ hide_favorites: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "user's favorites timeline will be hidden" description: "user's favorites timeline will be hidden"
}, },
show_role: %Schema{ show_role: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "user's role (e.g admin, moderator) will be exposed to anyone in the description: "user's role (e.g admin, moderator) will be exposed to anyone in the
API" API"
}, },
default_scope: VisibilityScope, default_scope: VisibilityScope,
pleroma_settings_store: %Schema{ pleroma_settings_store: %Schema{
type: :object, type: :object,
nullable: true,
description: "Opaque user settings to be saved on the backend." description: "Opaque user settings to be saved on the backend."
}, },
skip_thread_containment: %Schema{ skip_thread_containment: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Skip filtering out broken threads" description: "Skip filtering out broken threads"
}, },
allow_following_move: %Schema{ allow_following_move: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Allows automatically follow moved following accounts" description: "Allows automatically follow moved following accounts"
}, },
pleroma_background_image: %Schema{ pleroma_background_image: %Schema{
type: :string, type: :string,
nullable: true,
description: "Sets the background image of the user.", description: "Sets the background image of the user.",
format: :binary format: :binary
}, },
discoverable: %Schema{ discoverable: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: description:
"Discovery of this account in search results and other services is allowed." "Discovery of this account in search results and other services is allowed."
}, },
@ -624,7 +661,7 @@ defp follow_by_uri_request do
description: "POST body for muting an account", description: "POST body for muting an account",
type: :object, type: :object,
properties: %{ properties: %{
uri: %Schema{type: :string, format: :uri} uri: %Schema{type: :string, nullable: true, format: :uri}
}, },
required: [:uri] required: [:uri]
} }
@ -638,6 +675,7 @@ defp mute_request do
properties: %{ properties: %{
notifications: %Schema{ notifications: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Mute notifications in addition to statuses? Defaults to true.", description: "Mute notifications in addition to statuses? Defaults to true.",
default: true default: true
} }

View File

@ -105,7 +105,11 @@ defp create_request do
description: "Space separated list of scopes", description: "Space separated list of scopes",
default: "read" default: "read"
}, },
website: %Schema{type: :string, description: "A URL to the homepage of your app"} website: %Schema{
type: :string,
nullable: true,
description: "A URL to the homepage of your app"
}
}, },
required: [:client_name, :redirect_uris], required: [:client_name, :redirect_uris],
example: %{ example: %{

View File

@ -199,12 +199,14 @@ defp update_request do
"Array of enumerable strings `home`, `notifications`, `public`, `thread`. At least one context must be specified." "Array of enumerable strings `home`, `notifications`, `public`, `thread`. At least one context must be specified."
}, },
irreversible: %Schema{ irreversible: %Schema{
type: :bolean, type: :boolean,
nullable: true,
description: description:
"Should the server irreversibly drop matching entities from home and notifications?" "Should the server irreversibly drop matching entities from home and notifications?"
}, },
whole_word: %Schema{ whole_word: %Schema{
type: :bolean, type: :boolean,
nullable: true,
description: "Consider word boundaries?", description: "Consider word boundaries?",
default: true default: true
} }

View File

@ -110,14 +110,16 @@ defp upsert_request do
properties: %{ properties: %{
notifications: %Schema{ notifications: %Schema{
type: :object, type: :object,
nullable: true,
properties: %{ properties: %{
last_read_id: %Schema{type: :string} last_read_id: %Schema{nullable: true, type: :string}
} }
}, },
home: %Schema{ home: %Schema{
type: :object, type: :object,
nullable: true,
properties: %{ properties: %{
last_read_id: %Schema{type: :string} last_read_id: %Schema{nullable: true, type: :string}
} }
} }
}, },

View File

@ -143,6 +143,7 @@ defp update_avatar_or_background_request do
type: :object, type: :object,
properties: %{ properties: %{
img: %Schema{ img: %Schema{
nullable: true,
type: :string, type: :string,
format: :binary, format: :binary,
description: "Image encoded using `multipart/form-data` or an empty string to clear" description: "Image encoded using `multipart/form-data` or an empty string to clear"
@ -158,6 +159,7 @@ defp update_banner_request do
properties: %{ properties: %{
banner: %Schema{ banner: %Schema{
type: :string, type: :string,
nullable: true,
format: :binary, format: :binary,
description: "Image encoded using `multipart/form-data` or an empty string to clear" description: "Image encoded using `multipart/form-data` or an empty string to clear"
} }

View File

@ -37,15 +37,18 @@ defp create_request do
account_id: %Schema{type: :string, description: "ID of the account to report"}, account_id: %Schema{type: :string, description: "ID of the account to report"},
status_ids: %Schema{ status_ids: %Schema{
type: :array, type: :array,
nullable: true,
items: %Schema{type: :string}, items: %Schema{type: :string},
description: "Array of Statuses to attach to the report, for context" description: "Array of Statuses to attach to the report, for context"
}, },
comment: %Schema{ comment: %Schema{
type: :string, type: :string,
nullable: true,
description: "Reason for the report" description: "Reason for the report"
}, },
forward: %Schema{ forward: %Schema{
type: :boolean, type: :boolean,
nullable: true,
default: false, default: false,
description: description:
"If the account is remote, should the report be forwarded to the remote admin?" "If the account is remote, should the report be forwarded to the remote admin?"

View File

@ -371,15 +371,18 @@ defp create_request do
properties: %{ properties: %{
status: %Schema{ status: %Schema{
type: :string, type: :string,
nullable: true,
description: description:
"Text content of the status. If `media_ids` is provided, this becomes optional. Attaching a `poll` is optional while `status` is provided." "Text content of the status. If `media_ids` is provided, this becomes optional. Attaching a `poll` is optional while `status` is provided."
}, },
media_ids: %Schema{ media_ids: %Schema{
nullable: true,
type: :array, type: :array,
items: %Schema{type: :string}, items: %Schema{type: :string},
description: "Array of Attachment ids to be attached as media." description: "Array of Attachment ids to be attached as media."
}, },
poll: %Schema{ poll: %Schema{
nullable: true,
type: :object, type: :object,
required: [:options], required: [:options],
properties: %{ properties: %{
@ -390,26 +393,35 @@ defp create_request do
}, },
expires_in: %Schema{ expires_in: %Schema{
type: :integer, type: :integer,
nullable: true,
description: description:
"Duration the poll should be open, in seconds. Must be provided with `poll[options]`" "Duration the poll should be open, in seconds. Must be provided with `poll[options]`"
}, },
multiple: %Schema{type: :boolean, description: "Allow multiple choices?"}, multiple: %Schema{
type: :boolean,
nullable: true,
description: "Allow multiple choices?"
},
hide_totals: %Schema{ hide_totals: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Hide vote counts until the poll ends?" description: "Hide vote counts until the poll ends?"
} }
} }
}, },
in_reply_to_id: %Schema{ in_reply_to_id: %Schema{
nullable: true,
allOf: [FlakeID], allOf: [FlakeID],
description: "ID of the status being replied to, if status is a reply" description: "ID of the status being replied to, if status is a reply"
}, },
sensitive: %Schema{ sensitive: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Mark status and attached media as sensitive?" description: "Mark status and attached media as sensitive?"
}, },
spoiler_text: %Schema{ spoiler_text: %Schema{
type: :string, type: :string,
nullable: true,
description: description:
"Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field." "Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field."
}, },
@ -420,25 +432,33 @@ defp create_request do
description: description:
"ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future." "ISO 8601 Datetime at which to schedule a status. Providing this paramter will cause ScheduledStatus to be returned instead of Status. Must be at least 5 minutes in the future."
}, },
language: %Schema{type: :string, description: "ISO 639 language code for this status."}, language: %Schema{
type: :string,
nullable: true,
description: "ISO 639 language code for this status."
},
# Pleroma-specific properties: # Pleroma-specific properties:
preview: %Schema{ preview: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: description:
"If set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example" "If set to `true` the post won't be actually posted, but the status entitiy would still be rendered back. This could be useful for previewing rich text/custom emoji, for example"
}, },
content_type: %Schema{ content_type: %Schema{
type: :string, type: :string,
nullable: true,
description: description:
"The MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint." "The MIME type of the status, it is transformed into HTML by the backend. You can get the list of the supported MIME types with the nodeinfo endpoint."
}, },
to: %Schema{ to: %Schema{
type: :array, type: :array,
nullable: true,
items: %Schema{type: :string}, items: %Schema{type: :string},
description: description:
"A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply" "A list of nicknames (like `lain@soykaf.club` or `lain` on the local server) that will be used to determine who is going to be addressed by this post. Using this will disable the implicit addressing by mentioned names in the `status` body, only the people in the `to` list will be addressed. The normal rules for for post visibility are not affected by this and will still apply"
}, },
visibility: %Schema{ visibility: %Schema{
nullable: true,
anyOf: [ anyOf: [
VisibilityScope, VisibilityScope,
%Schema{type: :string, description: "`list:LIST_ID`", example: "LIST:123"} %Schema{type: :string, description: "`list:LIST_ID`", example: "LIST:123"}
@ -447,11 +467,13 @@ defp create_request do
"Visibility of the posted status. Besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`" "Visibility of the posted status. Besides standard MastoAPI values (`direct`, `private`, `unlisted` or `public`) it can be used to address a List by setting it to `list:LIST_ID`"
}, },
expires_in: %Schema{ expires_in: %Schema{
nullable: true,
type: :integer, type: :integer,
description: description:
"The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour." "The number of seconds the posted activity should expire in. When a posted activity expires it will be deleted from the server, and a delete request for it will be federated. This needs to be longer than an hour."
}, },
in_reply_to_conversation_id: %Schema{ in_reply_to_conversation_id: %Schema{
nullable: true,
type: :string, type: :string,
description: description:
"Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`." "Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`."

View File

@ -109,19 +109,38 @@ defp create_request do
required: [:endpoint, :keys] required: [:endpoint, :keys]
}, },
data: %Schema{ data: %Schema{
nullable: true,
type: :object, type: :object,
properties: %{ properties: %{
alerts: %Schema{ alerts: %Schema{
nullable: true,
type: :object, type: :object,
properties: %{ properties: %{
follow: %Schema{type: :boolean, description: "Receive follow notifications?"}, follow: %Schema{
type: :boolean,
nullable: true,
description: "Receive follow notifications?"
},
favourite: %Schema{ favourite: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Receive favourite notifications?" description: "Receive favourite notifications?"
}, },
reblog: %Schema{type: :boolean, description: "Receive reblog notifications?"}, reblog: %Schema{
mention: %Schema{type: :boolean, description: "Receive mention notifications?"}, type: :boolean,
poll: %Schema{type: :boolean, description: "Receive poll notifications?"} nullable: true,
description: "Receive reblog notifications?"
},
mention: %Schema{
type: :boolean,
nullable: true,
description: "Receive mention notifications?"
},
poll: %Schema{
type: :boolean,
nullable: true,
description: "Receive poll notifications?"
}
} }
} }
} }
@ -154,19 +173,38 @@ defp update_request do
type: :object, type: :object,
properties: %{ properties: %{
data: %Schema{ data: %Schema{
nullable: true,
type: :object, type: :object,
properties: %{ properties: %{
alerts: %Schema{ alerts: %Schema{
nullable: true,
type: :object, type: :object,
properties: %{ properties: %{
follow: %Schema{type: :boolean, description: "Receive follow notifications?"}, follow: %Schema{
type: :boolean,
nullable: true,
description: "Receive follow notifications?"
},
favourite: %Schema{ favourite: %Schema{
type: :boolean, type: :boolean,
nullable: true,
description: "Receive favourite notifications?" description: "Receive favourite notifications?"
}, },
reblog: %Schema{type: :boolean, description: "Receive reblog notifications?"}, reblog: %Schema{
mention: %Schema{type: :boolean, description: "Receive mention notifications?"}, type: :boolean,
poll: %Schema{type: :boolean, description: "Receive poll notifications?"} nullable: true,
description: "Receive reblog notifications?"
},
mention: %Schema{
type: :boolean,
nullable: true,
description: "Receive mention notifications?"
},
poll: %Schema{
type: :boolean,
nullable: true,
description: "Receive poll notifications?"
}
} }
} }
} }