Support mount-specific swagger_root and add swagger_filter setting

This commit is contained in:
richie
2016-06-29 16:11:40 -07:00
parent 60f33a5386
commit 7a01babe01
30 changed files with 367 additions and 144 deletions

View File

@@ -0,0 +1,30 @@
require 'rails_helper'
require 'swagger_rails/rspec/dsl'
RSpec.configure do |config|
# NOTE: Should be no need to modify these 3 lines
config.add_setting :swagger_root
config.add_setting :swagger_docs
config.extend SwaggerRails::RSpec::DSL
# Specify a root folder where Swagger JSON files are generated
# NOTE: If you're using the Swagger JSON middleware to serve API descriptions, you'll need
# to ensure that the same folder is also specified in the swagger_rails initializer
config.swagger_root = Rails.root.to_s + '/swagger'
# Define one or more Swagger documents and provide global metadata for each one
# When you run the "swaggerize" rake task, the complete Swagger will be generated
# at the provided relative path under swagger_root
# By default, the operations defined in spec files are added to the first
# document below. You can override this behavior by adding a swagger_doc tag to the
# the root example_group in your specs, e.g. describe '...', swagger_doc: 'v2/swagger.json'
config.swagger_docs = {
'v1/swagger.json' => {
swagger: '2.0',
info: {
title: 'API V1',
version: 'v1'
}
}
}
end

View File

@@ -1,16 +1,14 @@
SwaggerRails.configure do |c|
# Define your swagger documents and provide any global metadata here
# (Individual operations are generated from your spec/test files)
c.swagger_doc 'v1/swagger.json',
{
swagger: '2.0',
info: {
title: 'API V1',
version: 'v1'
}
}
# Specify a root folder where Swagger JSON files are located
# This is used by the Swagger middleware to serve requests for API descriptions
# NOTE: If you're using the rspec DSL to generate Swagger, you'll need to ensure
# that the same folder is also specified in spec/swagger_helper.rb
c.swagger_root = Rails.root.to_s + '/swagger'
# Specify a location to output generated swagger files
c.swagger_dir File.expand_path('../../../swagger', __FILE__)
# Inject a lamda function to alter the returned Swagger prior to serialization
# The function will have access to the rack env for the current request
# For example, you could leverage this to dynamically assign the "host" property
#
#c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
end