mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 02:58:48 +08:00
DEV: Add rswag to aid in api documention (#9546)
Adding in rswag will allow us to write spec files to document and test our api.
This commit is contained in:
73
spec/requests/api/categories_spec.rb
Normal file
73
spec/requests/api/categories_spec.rb
Normal file
@ -0,0 +1,73 @@
|
||||
# frozen_string_literal: true
|
||||
require 'swagger_helper'
|
||||
|
||||
describe 'categories' do
|
||||
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
Jobs.run_immediately!
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
path '/categories.json' do
|
||||
|
||||
post 'Creates a category' do
|
||||
before do
|
||||
Jobs.run_immediately!
|
||||
sign_in(admin)
|
||||
end
|
||||
tags 'Category'
|
||||
consumes 'application/json'
|
||||
parameter name: :category, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
name: { type: :string },
|
||||
color: { type: :string },
|
||||
text_color: { type: :string },
|
||||
},
|
||||
required: [ 'name', 'color', 'text_color' ]
|
||||
}
|
||||
|
||||
produces 'application/json'
|
||||
response '200', 'category created' do
|
||||
schema type: :object, properties: {
|
||||
category: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: { type: :integer },
|
||||
name: { type: :string },
|
||||
color: { type: :string },
|
||||
},
|
||||
required: ["id"]
|
||||
}
|
||||
}, required: ["category"]
|
||||
|
||||
let(:category) { { name: 'todo', color: 'f94cb0', text_color: '412763' } }
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
|
||||
get 'Retreives a list of categories' do
|
||||
tags 'Category'
|
||||
produces 'application/json'
|
||||
|
||||
response '200', 'categories response' do
|
||||
schema type: :object, properties: {
|
||||
category_list: {
|
||||
type: :object,
|
||||
properties: {
|
||||
can_create_category: { type: :boolean },
|
||||
can_create_topic: { type: :boolean },
|
||||
draft: { type: :string, nullable: true },
|
||||
draft_key: { type: :string },
|
||||
draft_sequence: { type: :integer },
|
||||
categories: { type: :array },
|
||||
}, required: ["categories"]
|
||||
}
|
||||
}, required: ["category_list"]
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user