Fix API inconsistencies between articles 'index' and 'show' (#4560)
* Fix API inconsistencies between articles 'index' and 'show' * Update API docs; revert tags from articles index * Fix specs * Update specs
This commit is contained in:
parent
89e893f157
commit
df857d860a
4 changed files with 149 additions and 40 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue