mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 06:54:15 +08:00
ee7809e8a8
From the openapi spec: https://spec.openapis.org/oas/latest.html#fixed-fields-7 each endpoint needs to have an `operationId`: > Unique string used to identify the operation. The id MUST be unique > among all operations described in the API. The operationId value is > case-sensitive. Tools and libraries MAY use the operationId to uniquely > identify an operation, therefore, it is RECOMMENDED to follow common > programming naming conventions. Running the linter on our openapi.json file with this command: `npx @redocly/openapi-cli lint openapi.json` produced the following warning on all of our endpoints: > Operation object should contain `operationId` field This commit resolves these warnings by adding an operationId field to each endpoint.
110 lines
3.1 KiB
Ruby
110 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
require 'swagger_helper'
|
|
|
|
describe 'badges' do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
let(:badge) { Fabricate(:badge) }
|
|
|
|
before do
|
|
Jobs.run_immediately!
|
|
sign_in(admin)
|
|
end
|
|
|
|
path '/admin/badges.json' do
|
|
|
|
get 'List badges' do
|
|
tags 'Badges'
|
|
operationId 'adminListBadges'
|
|
consumes 'application/json'
|
|
expected_request_schema = nil
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = load_spec_schema('badge_list_response')
|
|
schema expected_response_schema
|
|
|
|
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
|
|
|
|
post 'Create badge' do
|
|
tags 'Badges'
|
|
operationId 'createBadge'
|
|
consumes 'application/json'
|
|
expected_request_schema = load_spec_schema('badge_create_request')
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = load_spec_schema('badge_create_response')
|
|
schema expected_response_schema
|
|
|
|
let(:params) { {
|
|
'name' => 'badge1',
|
|
'badge_type_id' => 2
|
|
} }
|
|
|
|
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 '/admin/badges/{id}.json' do
|
|
|
|
put 'Update badge' do
|
|
tags 'Badges'
|
|
operationId 'updateBadge'
|
|
consumes 'application/json'
|
|
expected_request_schema = load_spec_schema('badge_update_request')
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
parameter name: :params, in: :body, schema: expected_request_schema
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = load_spec_schema('badge_update_response')
|
|
schema expected_response_schema
|
|
|
|
let(:id) { badge.id }
|
|
|
|
let(:params) { {
|
|
'name' => 'badge1',
|
|
'badge_type_id' => 2
|
|
} }
|
|
|
|
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
|
|
|
|
delete 'Delete badge' do
|
|
tags 'Badges'
|
|
operationId 'deleteBadge'
|
|
consumes 'application/json'
|
|
expected_request_schema = nil
|
|
parameter name: :id, in: :path, schema: { type: :integer }
|
|
|
|
produces 'application/json'
|
|
response '200', 'success response' do
|
|
expected_response_schema = nil
|
|
schema expected_response_schema
|
|
|
|
let(:id) { badge.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
|
|
end
|