Skip to content

A platform for community discussion. Free, open, simple.

DEV: Update api doc specs for post actions (#35428)

Blake Ericksonfaefa28792ce
diff --git a/spec/requests/api/posts_spec.rb b/spec/requests/api/posts_spec.rb
index dc2ec2c0ae9..16fad584e05 100644
--- a/spec/requests/api/posts_spec.rb
+++ b/spec/requests/api/posts_spec.rb
@@ -254,198 +254,20 @@ RSpec.describe "posts" do
parameter name: "Api-Key", in: :header, type: :string, required: true
parameter name: "Api-Username", in: :header, type: :string, required: true
- parameter name: :post_body,
- in: :body,
- schema: {
- type: :object,
- properties: {
- id: {
- type: :integer,
- },
- post_action_type_id: {
- type: :integer,
- },
- flag_topic: {
- type: :boolean,
- },
- },
- required: %w[id post_action_type_id],
- }
+ expected_request_schema = load_spec_schema("post_action_request")
+ parameter name: :params, in: :body, schema: expected_request_schema
produces "application/json"
response "200", "post updated" do
- schema type: :object,
- properties: {
- id: {
- type: :integer,
- },
- name: {
- type: :string,
- },
- username: {
- type: :string,
- },
- avatar_template: {
- type: :string,
- },
- created_at: {
- type: :string,
- },
- cooked: {
- type: :string,
- },
- post_number: {
- type: :integer,
- },
- post_type: {
- type: :integer,
- },
- updated_at: {
- type: :string,
- },
- reply_count: {
- type: :integer,
- },
- reply_to_post_number: {
- type: %i[string null],
- },
- quote_count: {
- type: :integer,
- },
- incoming_link_count: {
- type: :integer,
- },
- reads: {
- type: :integer,
- },
- readers_count: {
- type: :integer,
- },
- score: {
- type: :number,
- },
- yours: {
- type: :boolean,
- },
- topic_id: {
- type: :integer,
- },
- topic_slug: {
- type: :string,
- },
- display_username: {
- type: :string,
- },
- primary_group_name: {
- type: %i[string null],
- },
- flair_name: {
- type: %i[string null],
- },
- flair_url: {
- type: %i[string null],
- },
- flair_bg_color: {
- type: %i[string null],
- },
- flair_color: {
- type: %i[string null],
- },
- version: {
- type: :integer,
- },
- can_edit: {
- type: :boolean,
- },
- can_delete: {
- type: :boolean,
- },
- can_recover: {
- type: :boolean,
- },
- can_wiki: {
- type: :boolean,
- },
- user_title: {
- type: %i[string null],
- },
- actions_summary: {
- type: :array,
- items: {
- type: :object,
- properties: {
- id: {
- type: :integer,
- },
- count: {
- type: :integer,
- },
- acted: {
- type: :boolean,
- },
- can_undo: {
- type: :boolean,
- },
- },
- },
- },
- moderator: {
- type: :boolean,
- },
- admin: {
- type: :boolean,
- },
- staff: {
- type: :boolean,
- },
- user_id: {
- type: :integer,
- },
- hidden: {
- type: :boolean,
- },
- trust_level: {
- type: :integer,
- },
- deleted_at: {
- type: %i[string null],
- },
- user_deleted: {
- type: :boolean,
- },
- edit_reason: {
- type: %i[string null],
- },
- can_view_edit_history: {
- type: :boolean,
- },
- wiki: {
- type: :boolean,
- },
- notice: {
- type: :object,
- },
- notice_created_by_user: {
- type: %i[object null],
- },
- reviewable_id: {
- type: %i[integer null],
- },
- reviewable_score_count: {
- type: :integer,
- },
- reviewable_score_pending_count: {
- type: :integer,
- },
- }
+ expected_response_schema = load_spec_schema("post_action_response")
+ schema expected_response_schema
let(:id) { Fabricate(:post).id }
- let(:post_body) { { id: id, post_action_type_id: 2 } }
+ let(:params) { { id: id, post_action_type_id: 2 } }
- run_test! do |response|
- data = JSON.parse(response.body)
- expect(data["actions_summary"][0]["id"]).to eq(2)
- expect(data["actions_summary"][0]["count"]).to eq(1)
+ it_behaves_like "a JSON endpoint", 200 do
+ let(:expected_response_schema) { expected_response_schema }
+ let(:expected_request_schema) { expected_request_schema }
end
end
end
diff --git a/spec/requests/api/schemas/json/post_action_request.json b/spec/requests/api/schemas/json/post_action_request.json
new file mode 100644
index 00000000000..2016da20c85
--- /dev/null
+++ b/spec/requests/api/schemas/json/post_action_request.json
@@ -0,0 +1,21 @@
+{
+ "additionalProperties": false,
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "The ID of the post to perform the action on"
+ },
+ "post_action_type_id": {
+ "type": "integer",
+ "description": "The ID of the post action type (e.g., 2 for like)"
+ },
+ "flag_topic": {
+ "type": "boolean",
+ "description": "Whether to flag the entire topic"
+ }
+ },
+ "required": [
+ "id",
+ "post_action_type_id"
+ ]
+}
\ No newline at end of file
diff --git a/spec/requests/api/schemas/json/post_action_response.json b/spec/requests/api/schemas/json/post_action_response.json
new file mode 100644
index 00000000000..6b09729f3b6
--- /dev/null
+++ b/spec/requests/api/schemas/json/post_action_response.json
@@ -0,0 +1,326 @@
+{
+ "additionalProperties": true,
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "The ID of the post"
+ },
+ "name": {
+ "type": "string",
+ "description": "The name of the post author"
+ },
+ "username": {
+ "type": "string",
+ "description": "The username of the post author"
+ },
+ "avatar_template": {
+ "type": "string",
+ "description": "Template for the author's avatar URL"
+ },
+ "created_at": {
+ "type": "string",
+ "description": "When the post was created"
+ },
+ "cooked": {
+ "type": "string",
+ "description": "The HTML content of the post"
+ },
+ "post_number": {
+ "type": "integer",
+ "description": "The post number within the topic"
+ },
+ "post_type": {
+ "type": "integer",
+ "description": "The type of post"
+ },
+ "posts_count": {
+ "type": "integer",
+ "description": "Total posts count for the user"
+ },
+ "updated_at": {
+ "type": "string",
+ "description": "When the post was last updated"
+ },
+ "reply_count": {
+ "type": "integer",
+ "description": "Number of replies to this post"
+ },
+ "reply_to_post_number": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Post number this post is replying to"
+ },
+ "quote_count": {
+ "type": "integer",
+ "description": "Number of times this post has been quoted"
+ },
+ "incoming_link_count": {
+ "type": "integer",
+ "description": "Number of incoming links to this post"
+ },
+ "reads": {
+ "type": "integer",
+ "description": "Number of reads"
+ },
+ "readers_count": {
+ "type": "integer",
+ "description": "Number of readers"
+ },
+ "score": {
+ "type": "number",
+ "description": "Post score"
+ },
+ "yours": {
+ "type": "boolean",
+ "description": "Whether this post belongs to the current user"
+ },
+ "topic_id": {
+ "type": "integer",
+ "description": "ID of the topic this post belongs to"
+ },
+ "topic_slug": {
+ "type": "string",
+ "description": "Slug of the topic this post belongs to"
+ },
+ "display_username": {
+ "type": "string",
+ "description": "Display username of the post author"
+ },
+ "primary_group_name": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Primary group name of the author"
+ },
+ "flair_name": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Flair name of the author"
+ },
+ "flair_url": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Flair URL of the author"
+ },
+ "flair_bg_color": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Flair background color of the author"
+ },
+ "flair_color": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Flair color of the author"
+ },
+ "flair_group_id": {
+ "type": [
+ "integer",
+ "null"
+ ],
+ "description": "Flair group ID of the author"
+ },
+ "badges_granted": {
+ "type": "array",
+ "description": "Badges granted to the user"
+ },
+ "version": {
+ "type": "integer",
+ "description": "Version number of the post"
+ },
+ "can_edit": {
+ "type": "boolean",
+ "description": "Whether the current user can edit this post"
+ },
+ "can_delete": {
+ "type": "boolean",
+ "description": "Whether the current user can delete this post"
+ },
+ "can_recover": {
+ "type": "boolean",
+ "description": "Whether the current user can recover this post"
+ },
+ "can_see_hidden_post": {
+ "type": "boolean",
+ "description": "Whether the current user can see hidden posts"
+ },
+ "can_wiki": {
+ "type": "boolean",
+ "description": "Whether the current user can wiki this post"
+ },
+ "user_title": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Title of the post author"
+ },
+ "bookmarked": {
+ "type": "boolean",
+ "description": "Whether the post is bookmarked by the current user"
+ },
+ "actions_summary": {
+ "type": "array",
+ "description": "Summary of actions performed on this post",
+ "items": {
+ "type": "object",
+ "additionalProperties": true,
+ "properties": {
+ "id": {
+ "type": "integer",
+ "description": "ID of the action type (e.g., 2 for like)"
+ },
+ "count": {
+ "type": "integer",
+ "description": "Number of times this action has been performed"
+ },
+ "acted": {
+ "type": "boolean",
+ "description": "Whether the current user has performed this action"
+ },
+ "can_undo": {
+ "type": "boolean",
+ "description": "Whether the current user can undo this action"
+ },
+ "can_act": {
+ "type": "boolean",
+ "description": "Whether the current user can perform this action"
+ }
+ }
+ }
+ },
+ "moderator": {
+ "type": "boolean",
+ "description": "Whether the post author is a moderator"
+ },
+ "admin": {
+ "type": "boolean",
+ "description": "Whether the post author is an admin"
+ },
+ "staff": {
+ "type": "boolean",
+ "description": "Whether the post author is staff"
+ },
+ "user_id": {
+ "type": "integer",
+ "description": "ID of the post author"
+ },
+ "hidden": {
+ "type": "boolean",
+ "description": "Whether the post is hidden"
+ },
+ "trust_level": {
+ "type": "integer",
+ "description": "Trust level of the post author"
+ },
+ "deleted_at": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "When the post was deleted"
+ },
+ "user_deleted": {
+ "type": "boolean",
+ "description": "Whether the post was deleted by the user"
+ },
+ "edit_reason": {
+ "type": [
+ "string",
+ "null"
+ ],
+ "description": "Reason for the last edit"
+ },
+ "can_view_edit_history": {
+ "type": "boolean",
+ "description": "Whether the current user can view edit history"
+ },
+ "wiki": {
+ "type": "boolean",
+ "description": "Whether this is a wiki post"
+ },
+ "reviewable_id": {
+ "type": [
+ "integer",
+ "null"
+ ],
+ "description": "ID of the reviewable if this post is under review"
+ },
+ "reviewable_score_count": {
+ "type": "integer",
+ "description": "Number of reviewable scores"
+ },
+ "reviewable_score_pending_count": {
+ "type": "integer",
+ "description": "Number of pending reviewable scores"
+ },
+ "post_url": {
+ "type": "string",
+ "description": "URL of the post"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "username",
+ "avatar_template",
+ "created_at",
+ "cooked",
+ "post_number",
+ "post_type",
+ "posts_count",
+ "updated_at",
+ "reply_count",
+ "reply_to_post_number",
+ "quote_count",
+ "incoming_link_count",
+ "reads",
+ "readers_count",
+ "score",
+ "yours",
+ "topic_id",
+ "topic_slug",
+ "display_username",
+ "primary_group_name",
+ "flair_name",
+ "flair_url",
+ "flair_bg_color",
+ "flair_color",
+ "flair_group_id",
+ "badges_granted",
+ "version",
+ "can_edit",
+ "can_delete",
+ "can_recover",
+ "can_see_hidden_post",
+ "can_wiki",
+ "user_title",
+ "bookmarked",
+ "actions_summary",
+ "moderator",
+ "admin",
+ "staff",
+ "user_id",
+ "hidden",
+ "trust_level",
+ "deleted_at",
+ "user_deleted",
+ "edit_reason",
+ "can_view_edit_history",
+ "wiki",
+ "reviewable_id",
+ "reviewable_score_count",
+ "reviewable_score_pending_count",
+ "post_url"
+ ]
+}
\ No newline at end of file