mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Renames and fixes specs in api and specs project to prefix OpenApi module. Gem name to open_api-rswag
This commit is contained in:
@@ -1,71 +1,73 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rswag/specs/swagger_formatter'
|
||||
require 'open_api/rswag/specs/swagger_formatter'
|
||||
require 'ostruct'
|
||||
|
||||
module Rswag
|
||||
module Specs
|
||||
describe SwaggerFormatter do
|
||||
subject { described_class.new(output, config) }
|
||||
module OpenApi
|
||||
module Rswag
|
||||
module Specs
|
||||
describe SwaggerFormatter do
|
||||
subject { described_class.new(output, config) }
|
||||
|
||||
# Mock out some infrastructure
|
||||
before do
|
||||
allow(config).to receive(:swagger_root).and_return(swagger_root)
|
||||
end
|
||||
let(:config) { double('config') }
|
||||
let(:output) { double('output').as_null_object }
|
||||
let(:swagger_root) { File.expand_path('tmp/swagger', __dir__) }
|
||||
|
||||
describe '#example_group_finished(notification)' do
|
||||
# Mock out some infrastructure
|
||||
before do
|
||||
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
||||
subject.example_group_finished(notification)
|
||||
end
|
||||
let(:swagger_doc) { {} }
|
||||
let(:notification) { OpenStruct.new(group: OpenStruct.new(metadata: api_metadata)) }
|
||||
let(:api_metadata) do
|
||||
{
|
||||
path_item: { template: '/blogs' },
|
||||
operation: { verb: :post, summary: 'Creates a blog' },
|
||||
response: { code: '201', description: 'blog created' }
|
||||
}
|
||||
allow(config).to receive(:swagger_root).and_return(swagger_root)
|
||||
end
|
||||
let(:config) { double('config') }
|
||||
let(:output) { double('output').as_null_object }
|
||||
let(:swagger_root) { File.expand_path('tmp/swagger', __dir__) }
|
||||
|
||||
it 'converts to swagger and merges into the corresponding swagger doc' do
|
||||
expect(swagger_doc).to match(
|
||||
paths: {
|
||||
'/blogs' => {
|
||||
post: {
|
||||
summary: 'Creates a blog',
|
||||
responses: {
|
||||
'201' => { description: 'blog created' }
|
||||
}
|
||||
}
|
||||
}
|
||||
describe '#example_group_finished(notification)' do
|
||||
before do
|
||||
allow(config).to receive(:get_swagger_doc).and_return(swagger_doc)
|
||||
subject.example_group_finished(notification)
|
||||
end
|
||||
let(:swagger_doc) { {} }
|
||||
let(:notification) { OpenStruct.new(group: OpenStruct.new(metadata: api_metadata)) }
|
||||
let(:api_metadata) do
|
||||
{
|
||||
path_item: { template: '/blogs' },
|
||||
operation: { verb: :post, summary: 'Creates a blog' },
|
||||
response: { code: '201', description: 'blog created' }
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stop' do
|
||||
before do
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
allow(config).to receive(:swagger_docs).and_return(
|
||||
'v1/swagger.json' => { info: { version: 'v1' } },
|
||||
'v2/swagger.json' => { info: { version: 'v2' } }
|
||||
)
|
||||
subject.stop(notification)
|
||||
it 'converts to swagger and merges into the corresponding swagger doc' do
|
||||
expect(swagger_doc).to match(
|
||||
paths: {
|
||||
'/blogs' => {
|
||||
post: {
|
||||
summary: 'Creates a blog',
|
||||
responses: {
|
||||
'201' => { description: 'blog created' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
let(:notification) { double('notification') }
|
||||
describe '#stop' do
|
||||
before do
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
allow(config).to receive(:swagger_docs).and_return(
|
||||
'v1/swagger.json' => { info: { version: 'v1' } },
|
||||
'v2/swagger.json' => { info: { version: 'v2' } }
|
||||
)
|
||||
subject.stop(notification)
|
||||
end
|
||||
|
||||
it 'writes the swagger_doc(s) to file' do
|
||||
expect(File).to exist("#{swagger_root}/v1/swagger.json")
|
||||
expect(File).to exist("#{swagger_root}/v2/swagger.json")
|
||||
end
|
||||
let(:notification) { double('notification') }
|
||||
|
||||
after do
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
it 'writes the swagger_doc(s) to file' do
|
||||
expect(File).to exist("#{swagger_root}/v1/swagger.json")
|
||||
expect(File).to exist("#{swagger_root}/v2/swagger.json")
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_r(swagger_root) if File.exist?(swagger_root)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user