Skip to content

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

DEV: Update api docs to update username and to get post replies (#15881)

Blake Ericksone66241af7f96
diff --git a/spec/requests/api/posts_spec.rb b/spec/requests/api/posts_spec.rb
index a3934282989..8b3694ec62f 100644
--- a/spec/requests/api/posts_spec.rb
+++ b/spec/requests/api/posts_spec.rb
@@ -318,6 +318,33 @@ describe 'posts' do
end
end
+ path '/posts/{id}/replies.json' do
+ get 'List replies to a post' do
+ tags 'Posts'
+ operationId 'postReplies'
+ consumes 'application/json'
+ expected_request_schema = nil
+ parameter name: :id, in: :path, schema: { type: :string }
+
+ produces 'application/json'
+ response '200', 'post replies' do
+ expected_response_schema = load_spec_schema('post_replies_response')
+ schema expected_response_schema
+
+ fab!(:user) { Fabricate(:user) }
+ fab!(:topic) { Fabricate(:topic) }
+ fab!(:post) { Fabricate(:post, topic: topic, user: user) }
+ let!(:reply) { PostCreator.new(user, raw: "this is some text for my post", topic_id: topic.id, reply_to_post_number: post.post_number).create }
+ let!(:id) { post.id }
+
+ 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
+ end
+
path '/posts/{id}/locked.json' do
put 'Lock a post from being edited' do
tags 'Posts'
diff --git a/spec/requests/api/schemas/json/post_replies_response.json b/spec/requests/api/schemas/json/post_replies_response.json
new file mode 100644
index 00000000000..f3c10bca6b7
--- /dev/null
+++ b/spec/requests/api/schemas/json/post_replies_response.json
@@ -0,0 +1,268 @@
+{
+ "type": "array",
+ "minItems": 1,
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "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": "integer"
+ },
+ "quote_count": {
+ "type": "integer"
+ },
+ "incoming_link_count": {
+ "type": "integer"
+ },
+ "reads": {
+ "type": "integer"
+ },
+ "readers_count": {
+ "type": "integer"
+ },
+ "score": {
+ "type": "integer"
+ },
+ "yours": {
+ "type": "boolean"
+ },
+ "topic_id": {
+ "type": "integer"
+ },
+ "topic_slug": {
+ "type": "string"
+ },
+ "display_username": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "primary_group_name": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "flair_name": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "flair_url": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "flair_bg_color": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "flair_color": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "version": {
+ "type": "integer"
+ },
+ "can_edit": {
+ "type": "boolean"
+ },
+ "can_delete": {
+ "type": "boolean"
+ },
+ "can_recover": {
+ "type": "boolean"
+ },
+ "can_wiki": {
+ "type": "boolean"
+ },
+ "user_title": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "reply_to_user": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "username": {
+ "type": "string"
+ },
+ "avatar_template": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "username",
+ "avatar_template"
+ ]
+ },
+ "bookmarked": {
+ "type": "boolean"
+ },
+ "actions_summary": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "can_act": {
+ "type": "boolean"
+ }
+ },
+ "required": [
+ "id",
+ "can_act"
+ ]
+ }
+ ]
+ },
+ "moderator": {
+ "type": "boolean"
+ },
+ "admin": {
+ "type": "boolean"
+ },
+ "staff": {
+ "type": "boolean"
+ },
+ "user_id": {
+ "type": "integer"
+ },
+ "hidden": {
+ "type": "boolean"
+ },
+ "trust_level": {
+ "type": "integer"
+ },
+ "deleted_at": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "user_deleted": {
+ "type": "boolean"
+ },
+ "edit_reason": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "can_view_edit_history": {
+ "type": "boolean"
+ },
+ "wiki": {
+ "type": "boolean"
+ },
+ "reviewable_id": {
+ "type": [
+ "string",
+ "null"
+ ]
+ },
+ "reviewable_score_count": {
+ "type": "integer"
+ },
+ "reviewable_score_pending_count": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "username",
+ "avatar_template",
+ "created_at",
+ "cooked",
+ "post_number",
+ "post_type",
+ "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",
+ "version",
+ "can_edit",
+ "can_delete",
+ "can_recover",
+ "can_wiki",
+ "user_title",
+ "reply_to_user",
+ "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"
+ ]
+ }
+}
diff --git a/spec/requests/api/schemas/json/user_update_username_request.json b/spec/requests/api/schemas/json/user_update_username_request.json
new file mode 100644
index 00000000000..b098303aae5
--- /dev/null
+++ b/spec/requests/api/schemas/json/user_update_username_request.json
@@ -0,0 +1,11 @@
+{
+ "additionalProperties": false,
+ "properties": {
+ "new_username": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "new_username"
+ ]
+}
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index a50be753a5b..7c1cf361fe9 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -176,7 +176,6 @@ describe 'users' do
end
path '/u/{username}/preferences/email.json' do
-
put 'Update email' do
tags 'Users'
operationId 'updateEmail'
@@ -201,7 +200,33 @@ describe 'users' do
end
end
end
+ end
+
+ path '/u/{username}/preferences/username.json' do
+ put 'Update username' do
+ tags 'Users'
+ operationId 'updateUsername'
+ consumes 'application/json'
+ expected_request_schema = load_spec_schema('user_update_username_request')
+ parameter name: :username, in: :path, type: :string, required: true
+ parameter name: :params, in: :body, schema: expected_request_schema
+
+ produces 'application/json'
+ response '200', 'username updated' do
+
+ let(:user) { Fabricate(:user) }
+ let(:username) { user.username }
+ let(:params) { { 'new_username' => "#{user.username}1" } }
+
+ expected_response_schema = nil
+
+ 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
end
path '/directory_items.json' do