[#2456] OpenAPI: added `embed_relationships` param definition.

This commit is contained in:
Ivan Tashkinov 2020-05-12 20:55:01 +03:00
parent 63a1a82f38
commit bfb48e3db6
3 changed files with 73 additions and 59 deletions

View File

@ -47,6 +47,15 @@ def pagination_params do
] ]
end end
def embed_relationships_param do
Operation.parameter(
:embed_relationships,
:query,
:boolean,
"Embed relationships into accounts (Pleroma extension)"
)
end
def empty_object_response do def empty_object_response do
Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}}) Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
end end

View File

@ -156,7 +156,8 @@ def followers_operation do
description: description:
"Accounts which follow the given account, if network is not hidden by the account owner.", "Accounts which follow the given account, if network is not hidden by the account owner.",
parameters: parameters:
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(), [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++
pagination_params() ++ [embed_relationships_param()],
responses: %{ responses: %{
200 => Operation.response("Accounts", "application/json", array_of_accounts()) 200 => Operation.response("Accounts", "application/json", array_of_accounts())
} }
@ -172,7 +173,8 @@ def following_operation do
description: description:
"Accounts which the given account is following, if network is not hidden by the account owner.", "Accounts which the given account is following, if network is not hidden by the account owner.",
parameters: parameters:
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(), [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++
pagination_params() ++ [embed_relationships_param()],
responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())} responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
} }
end end

View File

@ -24,29 +24,30 @@ def account_search_operation do
tags: ["Search"], tags: ["Search"],
summary: "Search for matching accounts by username or display name", summary: "Search for matching accounts by username or display name",
operationId: "SearchController.account_search", operationId: "SearchController.account_search",
parameters: [ parameters:
Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", [
required: true Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
), required: true
Operation.parameter( ),
:limit, Operation.parameter(
:query, :limit,
%Schema{type: :integer, default: 40}, :query,
"Maximum number of results" %Schema{type: :integer, default: 40},
), "Maximum number of results"
Operation.parameter( ),
:resolve, Operation.parameter(
:query, :resolve,
%Schema{allOf: [BooleanLike], default: false}, :query,
"Attempt WebFinger lookup. Use this when `q` is an exact address." %Schema{allOf: [BooleanLike], default: false},
), "Attempt WebFinger lookup. Use this when `q` is an exact address."
Operation.parameter( ),
:following, Operation.parameter(
:query, :following,
%Schema{allOf: [BooleanLike], default: false}, :query,
"Only include accounts that the user is following" %Schema{allOf: [BooleanLike], default: false},
) "Only include accounts that the user is following"
], )
] ++ [embed_relationships_param()],
responses: %{ responses: %{
200 => 200 =>
Operation.response( Operation.response(
@ -65,40 +66,42 @@ def search_operation do
security: [%{"oAuth" => ["read:search"]}], security: [%{"oAuth" => ["read:search"]}],
operationId: "SearchController.search", operationId: "SearchController.search",
deprecated: true, deprecated: true,
parameters: [ parameters:
Operation.parameter( [
:account_id, Operation.parameter(
:query, :account_id,
FlakeID, :query,
"If provided, statuses returned will be authored only by this account" FlakeID,
), "If provided, statuses returned will be authored only by this account"
Operation.parameter( ),
:type, Operation.parameter(
:query, :type,
%Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, :query,
"Search type" %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
), "Search type"
Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true), ),
Operation.parameter( Operation.parameter(:q, :query, %Schema{type: :string}, "The search query",
:resolve, required: true
:query, ),
%Schema{allOf: [BooleanLike], default: false}, Operation.parameter(
"Attempt WebFinger lookup" :resolve,
), :query,
Operation.parameter( %Schema{allOf: [BooleanLike], default: false},
:following, "Attempt WebFinger lookup"
:query, ),
%Schema{allOf: [BooleanLike], default: false}, Operation.parameter(
"Only include accounts that the user is following" :following,
), :query,
Operation.parameter( %Schema{allOf: [BooleanLike], default: false},
:offset, "Only include accounts that the user is following"
:query, ),
%Schema{type: :integer}, Operation.parameter(
"Offset" :offset,
) :query,
| pagination_params() %Schema{type: :integer},
], "Offset"
)
] ++ pagination_params() ++ [embed_relationships_param()],
responses: %{ responses: %{
200 => Operation.response("Results", "application/json", results()) 200 => Operation.response("Results", "application/json", results())
} }