Commit f639971b authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '207935-status-page-json-changes' into 'master'

Resolve "Status Page MVC: JSON format and endpoints"

Closes #207935

See merge request gitlab-org/gitlab!26979
parents 6f976b81 1a2d9231
...@@ -9,9 +9,14 @@ module StatusPage ...@@ -9,9 +9,14 @@ module StatusPage
expose :updated_at expose :updated_at
expose :created_at expose :created_at
expose :user_notes, as: :comments, using: IncidentCommentEntity expose :user_notes, as: :comments, using: IncidentCommentEntity
expose :links
private private
def links
{ details: StatusPage::Storage.details_path(object.iid) }
end
def user_notes def user_notes
Array(options[:user_notes]) Array(options[:user_notes])
end end
......
...@@ -5,7 +5,7 @@ module StatusPage ...@@ -5,7 +5,7 @@ module StatusPage
entity IncidentEntity entity IncidentEntity
def represent_list(resource) def represent_list(resource)
represent(resource, except: [:comments]) { incidents: represent(resource, except: [:comments]) }
end end
def represent_details(resource, user_notes) def represent_details(resource, user_notes)
......
...@@ -8,11 +8,11 @@ module StatusPage ...@@ -8,11 +8,11 @@ module StatusPage
MAX_COMMENTS = 100 MAX_COMMENTS = 100
def self.details_path(id) def self.details_path(id)
"incident/#{id}.json" "data/incident/#{id}.json"
end end
def self.list_path def self.list_path
'list.json' 'data/list.json'
end end
class Error < StandardError class Error < StandardError
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"state", "state",
"title", "title",
"description", "description",
"links",
"updated_at", "updated_at",
"created_at" "created_at"
], ],
...@@ -16,6 +17,13 @@ ...@@ -16,6 +17,13 @@
}, },
"title": { "type": "string" }, "title": { "type": "string" },
"description": { "type": "string" }, "description": { "type": "string" },
"links": {
"type": "object",
"properties": {
"details": { "type": "string" }
},
"additionalProperties": false
},
"updated_at": { "type": "date" }, "updated_at": { "type": "date" },
"created_at": { "type": "date" } "created_at": { "type": "date" }
} }
......
{ {
"type": "object",
"required": ["incidents"],
"properties": {
"incidents": {
"type": "array", "type": "array",
"items": { "$ref": "basic_incident.json" }, "items": { "$ref": "basic_incident.json" }
}
},
"additionalProperties": false "additionalProperties": false
} }
...@@ -6,12 +6,12 @@ describe StatusPage::Storage do ...@@ -6,12 +6,12 @@ describe StatusPage::Storage do
describe '.details_path' do describe '.details_path' do
subject { described_class.details_path(123) } subject { described_class.details_path(123) }
it { is_expected.to eq('incident/123.json') } it { is_expected.to eq('data/incident/123.json') }
end end
describe '.list_path' do describe '.list_path' do
subject { described_class.list_path } subject { described_class.list_path }
it { is_expected.to eq('list.json') } it { is_expected.to eq('data/list.json') }
end end
end end
...@@ -19,7 +19,8 @@ describe StatusPage::IncidentEntity do ...@@ -19,7 +19,8 @@ describe StatusPage::IncidentEntity do
description: issue.description_html, description: issue.description_html,
updated_at: issue.updated_at, updated_at: issue.updated_at,
created_at: issue.created_at, created_at: issue.created_at,
comments: [] comments: [],
links: { details: "data/incident/#{issue.iid}.json" }
) )
end end
......
...@@ -14,7 +14,7 @@ describe StatusPage::IncidentSerializer do ...@@ -14,7 +14,7 @@ describe StatusPage::IncidentSerializer do
describe '.represent_list' do describe '.represent_list' do
let(:resource) { [issue] } let(:resource) { [issue] }
let(:json_entity) do let(:json_entity) do
subject.represent_list(resource).map(&:with_indifferent_access) subject.represent_list(resource).with_indifferent_access
end end
it_behaves_like 'valid JSON schema', schema: 'status_page/incident_list' it_behaves_like 'valid JSON schema', schema: 'status_page/incident_list'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment