diff --git a/app/views/api/v0/articles/index.json.jbuilder b/app/views/api/v0/articles/index.json.jbuilder index 19e397d68..565f4a8a1 100644 --- a/app/views/api/v0/articles/index.json.jbuilder +++ b/app/views/api/v0/articles/index.json.jbuilder @@ -1,19 +1,26 @@ json.array! @articles do |article| - json.type_of "article" - json.id article.id - json.title article.title - json.description article.description - json.cover_image cloud_cover_url(article.main_image) - json.published_at article.published_at - json.tag_list article.cached_tag_list_array - json.slug article.slug - json.path article.path - json.url article.url - json.canonical_url article.processed_canonical_url - json.comments_count article.comments_count + json.type_of "article" + json.id article.id + json.title article.title + json.description article.description + json.cover_image cloud_cover_url(article.main_image) + json.readable_publish_date article.readable_publish_date + json.social_image article_social_image_url(article) + json.tag_list article.cached_tag_list_array + json.tags article.cached_tag_list + json.slug article.slug + json.path article.path + json.url article.url + json.canonical_url article.processed_canonical_url + json.comments_count article.comments_count json.positive_reactions_count article.positive_reactions_count - json.published_timestamp article.published_timestamp - json.collection_id article.collection_id + json.collection_id article.collection_id + json.created_at article.created_at.utc.iso8601 + json.edited_at article.edited_at&.utc&.iso8601 + json.crossposted_at article.crossposted_at&.utc&.iso8601 + json.published_at article.published_at&.utc&.iso8601 + json.last_comment_at article.last_comment_at&.utc&.iso8601 + json.published_timestamp article.published_timestamp json.partial! "api/v0/shared/user", user: article.user diff --git a/app/views/api/v0/articles/show.json.jbuilder b/app/views/api/v0/articles/show.json.jbuilder index a94dda308..db4ef7aa1 100644 --- a/app/views/api/v0/articles/show.json.jbuilder +++ b/app/views/api/v0/articles/show.json.jbuilder @@ -1,27 +1,36 @@ -json.type_of "article" -json.id @article.id -json.title @article.title -json.description @article.description -json.cover_image cloud_cover_url @article.main_image -json.readable_publish_date @article.readable_publish_date -json.social_image article_social_image_url(@article) -json.tag_list @article.cached_tag_list -json.tags @article.cached_tag_list_array -json.slug @article.slug -json.path @article.path -json.url @article.url -json.canonical_url @article.processed_canonical_url -json.comments_count @article.comments_count +json.type_of "article" +json.id @article.id +json.title @article.title +json.description @article.description +json.cover_image cloud_cover_url @article.main_image +json.readable_publish_date @article.readable_publish_date +json.social_image article_social_image_url(@article) +json.tag_list @article.cached_tag_list +json.tags @article.cached_tag_list_array +json.slug @article.slug +json.path @article.path +json.url @article.url +json.canonical_url @article.processed_canonical_url +json.comments_count @article.comments_count json.positive_reactions_count @article.positive_reactions_count -json.collection_id @article.collection_id +json.collection_id @article.collection_id +json.created_at @article.created_at.utc.iso8601 +json.edited_at @article.edited_at&.utc&.iso8601 +json.crossposted_at @article.crossposted_at&.utc&.iso8601 +json.published_at @article.published_at&.utc&.iso8601 +json.last_comment_at @article.last_comment_at&.utc&.iso8601 +json.published_timestamp @article.published_timestamp -json.created_at @article.created_at.utc.iso8601 -json.edited_at @article.edited_at&.utc&.iso8601 -json.crossposted_at @article.crossposted_at&.utc&.iso8601 -json.published_at @article.published_at&.utc&.iso8601 -json.last_comment_at @article.last_comment_at&.utc&.iso8601 - -json.body_html @article.processed_html +json.body_html @article.processed_html json.body_markdown @article.body_markdown json.partial! "api/v0/shared/user", user: @article.user + +if @article.organization + json.partial! "api/v0/shared/organization", organization: @article.organization +end + +flare_tag = FlareTag.new(@article).tag +if flare_tag + json.partial! "flare_tag", flare_tag: flare_tag +end diff --git a/docs/api_v0.yml b/docs/api_v0.yml index 70707d204..8b8687d7a 100644 --- a/docs/api_v0.yml +++ b/docs/api_v0.yml @@ -2,7 +2,7 @@ openapi: "3.0.2" info: title: DEV API description: Access DEV articles, comments and other resources via API - version: "0.5.7" + version: "0.5.8" termsOfService: https://dev.to/terms contact: name: DEV Team @@ -77,13 +77,21 @@ components: - title - description - cover_image - - published_at + - readable_publish_date + - social_image - tag_list + - tags - slug - path - url - canonical_url + - comments_count - positive_reactions_count + - created_at + - edited_at + - crossposted_at + - published_at + - last_comment_at - published_timestamp - user properties: @@ -99,13 +107,17 @@ components: cover_image: type: string format: url - published_at: + readable_publish_date: type: string - format: date-time + social_image: + type: string + format: url tag_list: type: array items: type: string + tags: + type: string slug: type: string path: @@ -117,9 +129,27 @@ components: canonical_url: type: string format: url + comments_count: + type: integer + format: int32 positive_reactions_count: type: integer format: int32 + created_at: + type: string + format: date-time + edited_at: + type: string + format: date-time + crossposted_at: + type: string + format: date-time + published_at: + type: string + format: date-time + last_comment_at: + type: string + format: date-time published_timestamp: description: Crossposting or published date time type: string @@ -157,6 +187,7 @@ components: - crossposted_at - published_at - last_comment_at + - published_timestamp - body_html - body_markdown - user @@ -216,6 +247,10 @@ components: last_comment_at: type: string format: date-time + published_timestamp: + description: Crossposting or published date time + type: string + format: date-time body_html: type: string body_markdown: @@ -223,6 +258,12 @@ components: user: type: object $ref: "#/components/schemas/ArticleUser" + organization: + type: object + $ref: "#/components/schemas/ArticleOrganization" + flare_tag: + type: object + $ref: "#/components/schemas/ArticleFlareTag" ArticleCreate: type: object diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index d09887f8d..ba49d1901 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -9,6 +9,32 @@ RSpec.describe "Api::V0::Articles", type: :request do end describe "GET /api/articles" do + it "has correct keys in the response" do + article.update_columns(organization_id: organization.id) + get api_articles_path + + index_keys = %w[ + type_of id title description cover_image readable_publish_date social_image + tag_list tags slug path url canonical_url comments_count positive_reactions_count + collection_id created_at edited_at crossposted_at published_at last_comment_at + published_timestamp user organization flare_tag + ] + + expect(json_response.first.keys).to match_array index_keys + end + + it "returns correct tag list" do + get api_articles_path + + expect(json_response.first["tag_list"]).to be_a_kind_of Array + end + + it "returns correct tags" do + get api_articles_path + + expect(json_response.first["tags"]).to be_a_kind_of String + end + context "without params" do it "returns json response" do get api_articles_path @@ -144,6 +170,32 @@ RSpec.describe "Api::V0::Articles", type: :request do end describe "GET /api/articles/:id" do + it "has correct keys in the response" do + article.update_columns(organization_id: organization.id) + get api_article_path(article.id) + + show_keys = %w[ + type_of id title description cover_image readable_publish_date social_image + tag_list tags slug path url canonical_url comments_count positive_reactions_count + collection_id created_at edited_at crossposted_at published_at last_comment_at + published_timestamp body_html body_markdown user organization flare_tag + ] + + expect(json_response.keys).to match_array show_keys + end + + it "returns correct tag list" do + get api_article_path(article.id) + + expect(json_response["tag_list"]).to be_a_kind_of String + end + + it "returns correct tags" do + get api_article_path(article.id) + + expect(json_response["tags"]).to be_a_kind_of Array + end + it "returns proper article" do get api_article_path(article.id) expect(json_response).to include(