Improve OpenAPI schema

- Removes unneeded wrapping in examples
- Adds `:format` attributes
This commit is contained in:
Egor Kislitsyn 2020-04-21 23:30:24 +04:00
parent ed3974af24
commit f0238d010a
No known key found for this signature in database
GPG key ID: 1B49CB15B71E7805
12 changed files with 225 additions and 233 deletions

View file

@ -17,8 +17,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
type: :object, type: :object,
properties: %{ properties: %{
acct: %Schema{type: :string}, acct: %Schema{type: :string},
avatar_static: %Schema{type: :string}, avatar_static: %Schema{type: :string, format: :uri},
avatar: %Schema{type: :string}, avatar: %Schema{type: :string, format: :uri},
bot: %Schema{type: :boolean}, bot: %Schema{type: :boolean},
created_at: %Schema{type: :string, format: "date-time"}, created_at: %Schema{type: :string, format: "date-time"},
display_name: %Schema{type: :string}, display_name: %Schema{type: :string},
@ -27,13 +27,13 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
follow_requests_count: %Schema{type: :integer}, follow_requests_count: %Schema{type: :integer},
followers_count: %Schema{type: :integer}, followers_count: %Schema{type: :integer},
following_count: %Schema{type: :integer}, following_count: %Schema{type: :integer},
header_static: %Schema{type: :string}, header_static: %Schema{type: :string, format: :uri},
header: %Schema{type: :string}, header: %Schema{type: :string, format: :uri},
id: %Schema{type: :string}, id: %Schema{type: :string},
locked: %Schema{type: :boolean}, locked: %Schema{type: :boolean},
note: %Schema{type: :string}, note: %Schema{type: :string, format: :html},
statuses_count: %Schema{type: :integer}, statuses_count: %Schema{type: :integer},
url: %Schema{type: :string}, url: %Schema{type: :string, format: :uri},
username: %Schema{type: :string}, username: %Schema{type: :string},
pleroma: %Schema{ pleroma: %Schema{
type: :object, type: :object,
@ -104,7 +104,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
} }
}, },
example: %{ example: %{
"JSON" => %{
"acct" => "foobar", "acct" => "foobar",
"avatar" => "https://mypleroma.com/images/avi.png", "avatar" => "https://mypleroma.com/images/avi.png",
"avatar_static" => "https://mypleroma.com/images/avi.png", "avatar_static" => "https://mypleroma.com/images/avi.png",
@ -178,6 +177,5 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"url" => "https://mypleroma.com/users/foobar", "url" => "https://mypleroma.com/users/foobar",
"username" => "foobar" "username" => "foobar"
} }
}
}) })
end end

View file

@ -23,7 +23,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest do
"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
}, },
password: %Schema{type: :string, description: "The password to be used for login"}, password: %Schema{
type: :string,
description: "The password to be used for login",
format: :password
},
agreement: %Schema{ agreement: %Schema{
type: :boolean, type: :boolean,
description: description:

View file

@ -15,15 +15,13 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse do
token_type: %Schema{type: :string}, token_type: %Schema{type: :string},
access_token: %Schema{type: :string}, access_token: %Schema{type: :string},
scope: %Schema{type: :array, items: %Schema{type: :string}}, scope: %Schema{type: :array, items: %Schema{type: :string}},
created_at: %Schema{type: :integer} created_at: %Schema{type: :integer, format: :"date-time"}
}, },
example: %{ example: %{
"JSON" => %{
"access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk", "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
"created_at" => 1_585_918_714, "created_at" => 1_585_918_714,
"scope" => ["read", "write", "follow", "push"], "scope" => ["read", "write", "follow", "push"],
"token_type" => "Bearer" "token_type" => "Bearer"
} }
}
}) })
end end

View file

@ -13,12 +13,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountEmoji do
type: :object, type: :object,
properties: %{ properties: %{
shortcode: %Schema{type: :string}, shortcode: %Schema{type: :string},
url: %Schema{type: :string}, url: %Schema{type: :string, format: :uri},
static_url: %Schema{type: :string}, static_url: %Schema{type: :string, format: :uri},
visible_in_picker: %Schema{type: :boolean} visible_in_picker: %Schema{type: :boolean}
}, },
example: %{ example: %{
"JSON" => %{
"shortcode" => "fatyoshi", "shortcode" => "fatyoshi",
"url" => "url" =>
"https://files.mastodon.social/custom_emojis/images/000/023/920/original/e57ecb623faa0dc9.png", "https://files.mastodon.social/custom_emojis/images/000/023/920/original/e57ecb623faa0dc9.png",
@ -26,6 +25,5 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountEmoji do
"https://files.mastodon.social/custom_emojis/images/000/023/920/static/e57ecb623faa0dc9.png", "https://files.mastodon.social/custom_emojis/images/000/023/920/static/e57ecb623faa0dc9.png",
"visible_in_picker" => true "visible_in_picker" => true
} }
}
}) })
end end

View file

@ -13,16 +13,14 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountField do
type: :object, type: :object,
properties: %{ properties: %{
name: %Schema{type: :string}, name: %Schema{type: :string},
value: %Schema{type: :string}, value: %Schema{type: :string, format: :html},
verified_at: %Schema{type: :string, format: "date-time", nullable: true} verified_at: %Schema{type: :string, format: :"date-time", nullable: true}
}, },
example: %{ example: %{
"JSON" => %{
"name" => "Website", "name" => "Website",
"value" => "value" =>
"<a href=\"https://pleroma.com\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">pleroma.com</span><span class=\"invisible\"></span></a>", "<a href=\"https://pleroma.com\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">pleroma.com</span><span class=\"invisible\"></span></a>",
"verified_at" => "2019-08-29T04:14:55.571+00:00" "verified_at" => "2019-08-29T04:14:55.571+00:00"
} }
}
}) })
end end

View file

@ -17,10 +17,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountAttributeField do
}, },
required: [:name, :value], required: [:name, :value],
example: %{ example: %{
"JSON" => %{
"name" => "Website", "name" => "Website",
"value" => "https://pleroma.com" "value" => "https://pleroma.com"
} }
}
}) })
end end

View file

@ -11,7 +11,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountFollowsRequest 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} uri: %Schema{type: :string, format: :uri}
}, },
required: [:uri] required: [:uri]
}) })

View file

@ -26,7 +26,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
subscribing: %Schema{type: :boolean} subscribing: %Schema{type: :boolean}
}, },
example: %{ example: %{
"JSON" => %{
"blocked_by" => false, "blocked_by" => false,
"blocking" => false, "blocking" => false,
"domain_blocking" => false, "domain_blocking" => false,
@ -40,6 +39,5 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
"showing_reblogs" => true, "showing_reblogs" => true,
"subscribing" => false "subscribing" => false
} }
}
}) })
end end

View file

@ -21,7 +21,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AppCreateRequest do
type: :string, type: :string,
description: "Space separated list of scopes. If none is provided, defaults to `read`." description: "Space separated list of scopes. If none is provided, defaults to `read`."
}, },
website: %Schema{type: :string, description: "A URL to the homepage of your app"} website: %Schema{
type: :string,
description: "A URL to the homepage of your app",
format: :uri
}
}, },
required: [:client_name, :redirect_uris], required: [:client_name, :redirect_uris],
example: %{ example: %{

View file

@ -16,9 +16,9 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AppCreateResponse do
name: %Schema{type: :string}, name: %Schema{type: :string},
client_id: %Schema{type: :string}, client_id: %Schema{type: :string},
client_secret: %Schema{type: :string}, client_secret: %Schema{type: :string},
redirect_uri: %Schema{type: :string}, redirect_uri: %Schema{type: :string, format: :uri},
vapid_key: %Schema{type: :string}, vapid_key: %Schema{type: :string},
website: %Schema{type: :string, nullable: true} website: %Schema{type: :string, nullable: true, format: :uri}
}, },
example: %{ example: %{
"id" => "123", "id" => "123",

View file

@ -16,10 +16,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.List do
title: %Schema{type: :string} title: %Schema{type: :string}
}, },
example: %{ example: %{
"JSON" => %{
"id" => "123", "id" => "123",
"title" => "my list" "title" => "my list"
} }
}
}) })
end end

View file

@ -21,7 +21,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :object, type: :object,
properties: %{ properties: %{
name: %Schema{type: :string}, name: %Schema{type: :string},
website: %Schema{type: :string, nullable: true} website: %Schema{type: :string, nullable: true, format: :uri}
} }
}, },
bookmarked: %Schema{type: :boolean}, bookmarked: %Schema{type: :boolean},
@ -29,16 +29,16 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :object, type: :object,
nullable: true, nullable: true,
properties: %{ properties: %{
type: %Schema{type: :string}, type: %Schema{type: :string, enum: ["link", "photo", "video", "rich"]},
provider_name: %Schema{type: :string}, provider_name: %Schema{type: :string, nullable: true},
provider_url: %Schema{type: :string}, provider_url: %Schema{type: :string, format: :uri},
url: %Schema{type: :string}, url: %Schema{type: :string, format: :uri},
image: %Schema{type: :string}, image: %Schema{type: :string, nullable: true, format: :uri},
title: %Schema{type: :string}, title: %Schema{type: :string},
description: %Schema{type: :string} description: %Schema{type: :string}
} }
}, },
content: %Schema{type: :string}, content: %Schema{type: :string, format: :html},
created_at: %Schema{type: :string, format: "date-time"}, created_at: %Schema{type: :string, format: "date-time"},
emojis: %Schema{type: :array, items: AccountEmoji}, emojis: %Schema{type: :array, items: AccountEmoji},
favourited: %Schema{type: :boolean}, favourited: %Schema{type: :boolean},
@ -53,10 +53,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :object, type: :object,
properties: %{ properties: %{
id: %Schema{type: :string}, id: %Schema{type: :string},
url: %Schema{type: :string}, url: %Schema{type: :string, format: :uri},
remote_url: %Schema{type: :string}, remote_url: %Schema{type: :string, format: :uri},
preview_url: %Schema{type: :string}, preview_url: %Schema{type: :string, format: :uri},
text_url: %Schema{type: :string}, text_url: %Schema{type: :string, format: :uri},
description: %Schema{type: :string}, description: %Schema{type: :string},
type: %Schema{type: :string, enum: ["image", "video", "audio", "unknown"]}, type: %Schema{type: :string, enum: ["image", "video", "audio", "unknown"]},
pleroma: %Schema{ pleroma: %Schema{
@ -74,7 +74,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
id: %Schema{type: :string}, id: %Schema{type: :string},
acct: %Schema{type: :string}, acct: %Schema{type: :string},
username: %Schema{type: :string}, username: %Schema{type: :string},
url: %Schema{type: :string} url: %Schema{type: :string, format: :uri}
} }
} }
}, },
@ -120,16 +120,15 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
type: :object, type: :object,
properties: %{ properties: %{
name: %Schema{type: :string}, name: %Schema{type: :string},
url: %Schema{type: :string} url: %Schema{type: :string, format: :uri}
} }
} }
}, },
uri: %Schema{type: :string}, uri: %Schema{type: :string, format: :uri},
url: %Schema{type: :string}, url: %Schema{type: :string, nullable: true, format: :uri},
visibility: VisibilityScope visibility: VisibilityScope
}, },
example: %{ example: %{
"JSON" => %{
"account" => %{ "account" => %{
"acct" => "nick6", "acct" => "nick6",
"avatar" => "http://localhost:4001/images/avi.png", "avatar" => "http://localhost:4001/images/avi.png",
@ -222,6 +221,5 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
"url" => "http://localhost:4001/notice/9toJCu5YZW7O7gfvH6", "url" => "http://localhost:4001/notice/9toJCu5YZW7O7gfvH6",
"visibility" => "private" "visibility" => "private"
} }
}
}) })
end end