From c9bda862b62f4abcba892c3872ef66af8b9d6c05 Mon Sep 17 00:00:00 2001 From: Paul Carey Date: Thu, 6 Jul 2017 10:43:59 +0100 Subject: [PATCH 01/24] adds request spec generator shamelessly stollen from rspec-rails-swagger --- .gitignore | 1 + .../lib/generators/rspec/swagger/USAGE | 9 +++ .../rspec/swagger/swagger_generator.rb | 24 +++++++ .../rspec/swagger/templates/spec.rb | 30 +++++++++ .../lib/rspec/rails/swagger/route_parser.rb | 62 +++++++++++++++++++ rswag-specs/lib/rswag/specs/railtie.rb | 4 ++ 6 files changed, 130 insertions(+) create mode 100644 rswag-specs/lib/generators/rspec/swagger/USAGE create mode 100644 rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb create mode 100644 rswag-specs/lib/generators/rspec/swagger/templates/spec.rb create mode 100644 rswag-specs/lib/rspec/rails/swagger/route_parser.rb diff --git a/.gitignore b/.gitignore index d688e03..a96771f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ **/*/*.sqlite3 **/*/public/assets *.swp +.idea diff --git a/rswag-specs/lib/generators/rspec/swagger/USAGE b/rswag-specs/lib/generators/rspec/swagger/USAGE new file mode 100644 index 0000000..bc354c4 --- /dev/null +++ b/rswag-specs/lib/generators/rspec/swagger/USAGE @@ -0,0 +1,9 @@ +Description: + This creates an RSpec request spec to define Swagger documentation for a + controller. It will create a test for each of the controller's methods. + +Example: + rails generate rspec:swagger V3::AccountsController + + This will create: + spec/requests/v3/accounts_spec.rb diff --git a/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb b/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb new file mode 100644 index 0000000..48f92aa --- /dev/null +++ b/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb @@ -0,0 +1,24 @@ +require 'rspec/rails/swagger/route_parser' +require 'rails/generators' + +module Rspec + module Generators + class SwaggerGenerator < ::Rails::Generators::NamedBase + source_root File.expand_path('../templates', __FILE__) + + def setup + @routes = RSpec::Rails::Swagger::RouteParser.new(controller_path).routes + end + + def create_spec_file + template 'spec.rb', File.join('spec/requests', "#{controller_path}_spec.rb") + end + + private + + def controller_path + file_path.chomp('_controller') + end + end + end +end diff --git a/rswag-specs/lib/generators/rspec/swagger/templates/spec.rb b/rswag-specs/lib/generators/rspec/swagger/templates/spec.rb new file mode 100644 index 0000000..75ff7b3 --- /dev/null +++ b/rswag-specs/lib/generators/rspec/swagger/templates/spec.rb @@ -0,0 +1,30 @@ +require 'swagger_helper' + +RSpec.describe '<%= controller_path %>', type: :request do + <% @routes.each do | template, path_item | %> + path '<%= template %>' do +<% unless path_item[:params].empty? -%> + # You'll want to customize the parameter types... + <% path_item[:params].each do |param| -%> + parameter '<%= param %>', in: :body, type: :string + <% end -%> +<% end -%> +<% path_item[:actions].each do | action, details | -%> + <%= action %>('<%= details[:summary] %>') do + response(200, 'successful') do +<% unless path_item[:params].empty? -%> + <% path_item[:params].each do |param| -%> + let(:<%= param %>) { '123' } + <% end -%> +<% end -%> + + after do |example| + example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) } + end + run_test! + end + end +<% end -%> + end +<% end -%> +end diff --git a/rswag-specs/lib/rspec/rails/swagger/route_parser.rb b/rswag-specs/lib/rspec/rails/swagger/route_parser.rb new file mode 100644 index 0000000..9ab9513 --- /dev/null +++ b/rswag-specs/lib/rspec/rails/swagger/route_parser.rb @@ -0,0 +1,62 @@ +module RSpec + module Rails + module Swagger + class RouteParser + attr_reader :controller + + def initialize(controller) + @controller = controller + end + + def routes + ::Rails.application.routes.routes.select do |route| + route.defaults[:controller] == controller + end.reduce({}) do |tree, route| + path = path_from(route) + verb = verb_from(route) + tree[path] ||= { params: params_from(route), actions: {} } + tree[path][:actions][verb] = { summary: summary_from(route) } + tree + end + end + + private + + def path_from(route) + route.path.spec.to_s + .chomp('(.:format)') # Ignore any format suffix + .gsub(/:([^\/.?]+)/, '{\1}') # Convert :id to {id} + end + + def verb_from(route) + verb = route.verb + if verb.kind_of? String + verb.downcase + else + verb.source.gsub(/[$^]/, '').downcase + end + end + + def summary_from(route) + verb = route.requirements[:action] + noun = route.requirements[:controller].split('/').last.singularize + + # Apply a few customizations to make things more readable + case verb + when 'index' + verb = 'list' + noun = noun.pluralize + when 'destroy' + verb = 'delete' + end + + "#{verb} #{noun}" + end + + def params_from(route) + route.segments - ['format'] + end + end + end + end +end diff --git a/rswag-specs/lib/rswag/specs/railtie.rb b/rswag-specs/lib/rswag/specs/railtie.rb index 8deec2b..43e2302 100644 --- a/rswag-specs/lib/rswag/specs/railtie.rb +++ b/rswag-specs/lib/rswag/specs/railtie.rb @@ -5,6 +5,10 @@ module Rswag rake_tasks do load File.expand_path('../../../tasks/rswag-specs_tasks.rake', __FILE__) end + + generators do + require 'generators/rspec/swagger/swagger_generator.rb' + end end end end From bfd3d66ec24d295e2bc765bcb73693a14134cc3b Mon Sep 17 00:00:00 2001 From: Rich Daley Date: Mon, 7 Jan 2019 14:09:50 +0000 Subject: [PATCH 02/24] Add a 'rake rswag' that runs swaggerize as the default --- README.md | 2 ++ rswag-specs/lib/tasks/rswag-specs_tasks.rake | 3 +++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 08f0157..48fd461 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ Once you have an API that can describe itself in Swagger, you've opened the trea rake rswag:specs:swaggerize ``` + This common command is also aliased as `rake rswag`. + 5. Spin up your app and check out the awesome, auto-generated docs at _/api-docs_! ## The rspec DSL ## diff --git a/rswag-specs/lib/tasks/rswag-specs_tasks.rake b/rswag-specs/lib/tasks/rswag-specs_tasks.rake index adc128c..b7d276b 100644 --- a/rswag-specs/lib/tasks/rswag-specs_tasks.rake +++ b/rswag-specs/lib/tasks/rswag-specs_tasks.rake @@ -16,3 +16,6 @@ namespace :rswag do end end end + +task :rswag => ['rswag:specs:swaggerize'] + From 29c9f7cae266daa6d87c3a43fdd831ffcc373d46 Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Wed, 6 Feb 2019 11:43:02 +0000 Subject: [PATCH 03/24] Allow parsing of yml swagger files in rswag-api --- rswag-api/lib/rswag/api/middleware.rb | 15 ++++++++++++++- .../rswag/api/fixtures/swagger/v1/swagger.yml | 5 +++++ rswag-api/spec/rswag/api/middleware_spec.rb | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 rswag-api/spec/rswag/api/fixtures/swagger/v1/swagger.yml diff --git a/rswag-api/lib/rswag/api/middleware.rb b/rswag-api/lib/rswag/api/middleware.rb index 118c987..c1a4fbb 100644 --- a/rswag-api/lib/rswag/api/middleware.rb +++ b/rswag-api/lib/rswag/api/middleware.rb @@ -1,4 +1,5 @@ require 'json' +require 'yaml' module Rswag module Api @@ -14,7 +15,7 @@ module Rswag filename = "#{@config.resolve_swagger_root(env)}/#{path}" if env['REQUEST_METHOD'] == 'GET' && File.file?(filename) - swagger = load_json(filename) + swagger = parse_file(filename) @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil? return [ @@ -29,6 +30,18 @@ module Rswag private + def parse_file(filename) + if /\.yml$/ === filename + load_yaml(filename) + else + load_json(filename) + end + end + + def load_yaml(filename) + YAML.safe_load(File.read(filename)) + end + def load_json(filename) JSON.parse(File.read(filename)) end diff --git a/rswag-api/spec/rswag/api/fixtures/swagger/v1/swagger.yml b/rswag-api/spec/rswag/api/fixtures/swagger/v1/swagger.yml new file mode 100644 index 0000000..0757e2a --- /dev/null +++ b/rswag-api/spec/rswag/api/fixtures/swagger/v1/swagger.yml @@ -0,0 +1,5 @@ +swagger: '2.0' +info: + title: API V1 + version: v1 +paths: {} diff --git a/rswag-api/spec/rswag/api/middleware_spec.rb b/rswag-api/spec/rswag/api/middleware_spec.rb index aaa148b..f784f25 100644 --- a/rswag-api/spec/rswag/api/middleware_spec.rb +++ b/rswag-api/spec/rswag/api/middleware_spec.rb @@ -76,6 +76,21 @@ module Rswag expect(response[2].join).to include('"host":"tempuri.org"') end end + + context 'when a path maps to a yaml swagger file' do + let(:env) { env_defaults.merge('PATH_INFO' => 'v1/swagger.yml') } + + it 'returns a 200 status' do + expect(response.length).to eql(3) + expect(response.first).to eql('200') + end + + it 'returns contents of the swagger file' do + expect(response.length).to eql(3) + expect(response[1]).to include( 'Content-Type' => 'application/json') + expect(response[2].join).to include('"title":"API V1"') + end + end end end end From 51b47f32e836433031585d1dee1536e38cb425ae Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Wed, 6 Feb 2019 12:15:01 +0000 Subject: [PATCH 04/24] version compatibility --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index bbd3d73..1abf797 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ when '4', '5' gem 'responders' end -gem 'sqlite3' +gem 'sqlite3', '~> 1.3.6' gem 'rswag-api', path: './rswag-api' gem 'rswag-ui', path: './rswag-ui' From 9eb2d3ddec74fced2a2bff47dd652112a5480b35 Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Tue, 12 Feb 2019 10:47:15 +0000 Subject: [PATCH 05/24] Allow ".yaml" and ".yml" filename endings for yaml --- rswag-api/lib/rswag/api/middleware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rswag-api/lib/rswag/api/middleware.rb b/rswag-api/lib/rswag/api/middleware.rb index c1a4fbb..7256794 100644 --- a/rswag-api/lib/rswag/api/middleware.rb +++ b/rswag-api/lib/rswag/api/middleware.rb @@ -31,7 +31,7 @@ module Rswag private def parse_file(filename) - if /\.yml$/ === filename + if /\.ya?ml$/ === filename load_yaml(filename) else load_json(filename) From 49b5059273e50342803031e1b2e2774dcc61f74c Mon Sep 17 00:00:00 2001 From: stefanosx Date: Wed, 6 Mar 2019 12:59:24 +0100 Subject: [PATCH 06/24] Update README.md You need to run the generation of rswag:api:install rswag:ui:install in separated lines to work --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 08f0157..5d9b369 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,8 @@ Once you have an API that can describe itself in Swagger, you've opened the trea Or run the install generators for each package separately if you installed Rswag as separate gems, as indicated above: ```ruby - rails g rswag:api:install rswag:ui:install + rails g rswag:api:install + rails g rswag:ui:install RAILS_ENV=test rails g rswag:specs:install ``` From 57da84d05504c00b21b94a38cb59b9fc63345f9c Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Fri, 4 Oct 2019 14:52:47 +0100 Subject: [PATCH 07/24] add options and trace --- rswag-specs/lib/rswag/specs/example_group_helpers.rb | 2 +- rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rswag-specs/lib/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/rswag/specs/example_group_helpers.rb index c293c63..4939abb 100644 --- a/rswag-specs/lib/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/rswag/specs/example_group_helpers.rb @@ -7,7 +7,7 @@ module Rswag describe(template, metadata, &block) end - [ :get, :post, :patch, :put, :delete, :head ].each do |verb| + [ :get, :post, :patch, :put, :delete, :head, :options, :trace ].each do |verb| define_method(verb) do |summary, &block| api_metadata = { operation: { verb: verb, summary: summary } } describe(verb, api_metadata, &block) diff --git a/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb b/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb index 619a8d7..c870bfc 100644 --- a/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb +++ b/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb @@ -24,7 +24,7 @@ module Rswag end end - describe '#get|post|patch|put|delete|head(verb, summary)' do + describe '#get|post|patch|put|delete|head|options|trace(verb, summary)' do before { subject.post('Creates a blog') } it "delegates to 'describe' with 'operation' metadata" do From dc2ebd94bb701883581bd1b92db6d77766bb4285 Mon Sep 17 00:00:00 2001 From: Hayley Date: Tue, 8 Oct 2019 16:18:55 +0100 Subject: [PATCH 08/24] update swagger ui to 3.18.2 --- CHANGELOG.md | 1 + README.md | 2 +- rswag-ui/package-lock.json | 6 +++--- rswag-ui/package.json | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a8b599..7f30a85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added ### Changed +- Update swagger-ui to 3.18.2 ### Deprecated ### Removed ### Fixed diff --git a/README.md b/README.md index 267b563..3cfff07 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Once you have an API that can describe itself in Swagger, you've opened the trea |Rswag Version|Swagger (OpenAPI) Spec.|swagger-ui| |----------|----------|----------| -|[master](https://github.com/rswag/rswag/tree/master)|2.0|3.17.3| +|[master](https://github.com/rswag/rswag/tree/master)|2.0|3.18.2| |[2.0.6](https://github.com/rswag/rswag/tree/2.0.6)|2.0|3.17.3| |[1.6.0](https://github.com/rswag/rswag/tree/1.6.0)|2.0|2.2.5| diff --git a/rswag-ui/package-lock.json b/rswag-ui/package-lock.json index 664d3fa..144573b 100644 --- a/rswag-ui/package-lock.json +++ b/rswag-ui/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "swagger-ui-dist": { - "version": "3.17.3", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.17.3.tgz", - "integrity": "sha1-37lkCMzEZ3UVX3NpGQxdSyAW/lw=" + "version": "3.18.2", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.18.2.tgz", + "integrity": "sha512-pWAEiKkgWUJvjmLW9AojudnutJ+NTn5g6OdNLj1iIJWwCkoy40K3Upwa24DqFbmIE4vLX4XplND61hp2L+s5vg==" } } } diff --git a/rswag-ui/package.json b/rswag-ui/package.json index 1fce627..27dbc6c 100644 --- a/rswag-ui/package.json +++ b/rswag-ui/package.json @@ -3,6 +3,6 @@ "version": "1.0.0", "private": true, "dependencies": { - "swagger-ui-dist": "3.17.3" + "swagger-ui-dist": "3.18.2" } } From 3542cd0857ea42a63aabdc49ebfc8935e5ac1443 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Mon, 14 Oct 2019 22:17:12 +0100 Subject: [PATCH 09/24] Add a Sprockets 4 manifest Fix #243 --- test-app/app/assets/config/manifest.js | 2 ++ test-app/app/assets/images/.keep | 0 2 files changed, 2 insertions(+) create mode 100644 test-app/app/assets/config/manifest.js create mode 100644 test-app/app/assets/images/.keep diff --git a/test-app/app/assets/config/manifest.js b/test-app/app/assets/config/manifest.js new file mode 100644 index 0000000..5918193 --- /dev/null +++ b/test-app/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/test-app/app/assets/images/.keep b/test-app/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 From 77d00407a4e0a6de2f4a37b5a4b49458d4e37915 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Wed, 16 Oct 2019 20:51:53 +0100 Subject: [PATCH 10/24] whitespace linting --- rswag-specs/lib/rswag/specs/extended_schema.rb | 4 ++-- rswag-specs/lib/rswag/specs/railtie.rb | 2 +- rswag-specs/lib/rswag/specs/request_factory.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rswag-specs/lib/rswag/specs/extended_schema.rb b/rswag-specs/lib/rswag/specs/extended_schema.rb index 62eb4ee..29888f8 100644 --- a/rswag-specs/lib/rswag/specs/extended_schema.rb +++ b/rswag-specs/lib/rswag/specs/extended_schema.rb @@ -3,7 +3,7 @@ require 'json-schema' module Rswag module Specs class ExtendedSchema < JSON::Schema::Draft4 - + def initialize super @attributes['type'] = ExtendedTypeAttribute @@ -13,7 +13,7 @@ module Rswag end class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute - + def self.validate(current_schema, data, fragments, processor, validator, options={}) return if data.nil? && current_schema.schema['x-nullable'] == true super diff --git a/rswag-specs/lib/rswag/specs/railtie.rb b/rswag-specs/lib/rswag/specs/railtie.rb index 43e2302..994a8a4 100644 --- a/rswag-specs/lib/rswag/specs/railtie.rb +++ b/rswag-specs/lib/rswag/specs/railtie.rb @@ -5,7 +5,7 @@ module Rswag rake_tasks do load File.expand_path('../../../tasks/rswag-specs_tasks.rake', __FILE__) end - + generators do require 'generators/rspec/swagger/swagger_generator.rb' end diff --git a/rswag-specs/lib/rswag/specs/request_factory.rb b/rswag-specs/lib/rswag/specs/request_factory.rb index 7106015..14b1edc 100644 --- a/rswag-specs/lib/rswag/specs/request_factory.rb +++ b/rswag-specs/lib/rswag/specs/request_factory.rb @@ -54,7 +54,7 @@ module Rswag definitions[key] end - def add_verb(request, metadata) + def add_verb(request, metadata) request[:verb] = metadata[:operation][:verb] end @@ -104,7 +104,7 @@ module Rswag end # Content-Type header - consumes = metadata[:operation][:consumes] || swagger_doc[:consumes] + consumes = metadata[:operation][:consumes] || swagger_doc[:consumes] if consumes content_type = example.respond_to?(:'Content-Type') ? example.send(:'Content-Type') : consumes.first tuples << [ 'Content-Type', content_type ] From 778d25038558cb59cf6d2c20fac6bd6877b011d8 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Wed, 16 Oct 2019 21:12:36 +0100 Subject: [PATCH 11/24] Split file join path --- rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb b/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb index 48f92aa..81feeb9 100644 --- a/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb +++ b/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb @@ -11,7 +11,7 @@ module Rspec end def create_spec_file - template 'spec.rb', File.join('spec/requests', "#{controller_path}_spec.rb") + template 'spec.rb', File.join('spec', 'requests', "#{controller_path}_spec.rb") end private From 189a7ef06136e42307c2d8b9d1c9a438d48add3e Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Wed, 16 Oct 2019 22:05:14 +0100 Subject: [PATCH 12/24] Move spec generator files, organize whitespace in generator output --- .../lib/generators/rspec/{swagger => }/USAGE | 0 .../rspec/swagger/swagger_generator.rb | 24 ------- .../lib/generators/rspec/swagger_generator.rb | 22 +++++++ .../rspec/{swagger => }/templates/spec.rb | 24 +++---- .../lib/rspec/rails/swagger/route_parser.rb | 62 ------------------- rswag-specs/lib/rswag/route_parser.rb | 58 +++++++++++++++++ 6 files changed, 92 insertions(+), 98 deletions(-) rename rswag-specs/lib/generators/rspec/{swagger => }/USAGE (100%) delete mode 100644 rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb create mode 100644 rswag-specs/lib/generators/rspec/swagger_generator.rb rename rswag-specs/lib/generators/rspec/{swagger => }/templates/spec.rb (59%) delete mode 100644 rswag-specs/lib/rspec/rails/swagger/route_parser.rb create mode 100644 rswag-specs/lib/rswag/route_parser.rb diff --git a/rswag-specs/lib/generators/rspec/swagger/USAGE b/rswag-specs/lib/generators/rspec/USAGE similarity index 100% rename from rswag-specs/lib/generators/rspec/swagger/USAGE rename to rswag-specs/lib/generators/rspec/USAGE diff --git a/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb b/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb deleted file mode 100644 index 81feeb9..0000000 --- a/rswag-specs/lib/generators/rspec/swagger/swagger_generator.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rspec/rails/swagger/route_parser' -require 'rails/generators' - -module Rspec - module Generators - class SwaggerGenerator < ::Rails::Generators::NamedBase - source_root File.expand_path('../templates', __FILE__) - - def setup - @routes = RSpec::Rails::Swagger::RouteParser.new(controller_path).routes - end - - def create_spec_file - template 'spec.rb', File.join('spec', 'requests', "#{controller_path}_spec.rb") - end - - private - - def controller_path - file_path.chomp('_controller') - end - end - end -end diff --git a/rswag-specs/lib/generators/rspec/swagger_generator.rb b/rswag-specs/lib/generators/rspec/swagger_generator.rb new file mode 100644 index 0000000..ddb862c --- /dev/null +++ b/rswag-specs/lib/generators/rspec/swagger_generator.rb @@ -0,0 +1,22 @@ +require 'rswag/route_parser' +require 'rails/generators' + +module Rspec + class SwaggerGenerator < ::Rails::Generators::NamedBase + source_root File.expand_path('../templates', __FILE__) + + def setup + @routes = Rswag::RouteParser.new(controller_path).routes + end + + def create_spec_file + template 'spec.rb', File.join('spec', 'requests', "#{controller_path}_spec.rb") + end + + private + + def controller_path + file_path.chomp('_controller') + end + end +end diff --git a/rswag-specs/lib/generators/rspec/swagger/templates/spec.rb b/rswag-specs/lib/generators/rspec/templates/spec.rb similarity index 59% rename from rswag-specs/lib/generators/rspec/swagger/templates/spec.rb rename to rswag-specs/lib/generators/rspec/templates/spec.rb index 75ff7b3..0673596 100644 --- a/rswag-specs/lib/generators/rspec/swagger/templates/spec.rb +++ b/rswag-specs/lib/generators/rspec/templates/spec.rb @@ -1,22 +1,22 @@ require 'swagger_helper' RSpec.describe '<%= controller_path %>', type: :request do - <% @routes.each do | template, path_item | %> +<% @routes.each do | template, path_item | %> path '<%= template %>' do -<% unless path_item[:params].empty? -%> +<% unless path_item[:params].empty? -%> # You'll want to customize the parameter types... - <% path_item[:params].each do |param| -%> +<% path_item[:params].each do |param| -%> parameter '<%= param %>', in: :body, type: :string - <% end -%> -<% end -%> -<% path_item[:actions].each do | action, details | -%> +<% end -%> +<% end -%> +<% path_item[:actions].each do | action, details | %> <%= action %>('<%= details[:summary] %>') do response(200, 'successful') do -<% unless path_item[:params].empty? -%> - <% path_item[:params].each do |param| -%> +<% unless path_item[:params].empty? -%> +<% path_item[:params].each do |param| -%> let(:<%= param %>) { '123' } - <% end -%> -<% end -%> +<% end -%> +<% end -%> after do |example| example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) } @@ -24,7 +24,7 @@ RSpec.describe '<%= controller_path %>', type: :request do run_test! end end -<% end -%> +<% end -%> end -<% end -%> +<% end -%> end diff --git a/rswag-specs/lib/rspec/rails/swagger/route_parser.rb b/rswag-specs/lib/rspec/rails/swagger/route_parser.rb deleted file mode 100644 index 9ab9513..0000000 --- a/rswag-specs/lib/rspec/rails/swagger/route_parser.rb +++ /dev/null @@ -1,62 +0,0 @@ -module RSpec - module Rails - module Swagger - class RouteParser - attr_reader :controller - - def initialize(controller) - @controller = controller - end - - def routes - ::Rails.application.routes.routes.select do |route| - route.defaults[:controller] == controller - end.reduce({}) do |tree, route| - path = path_from(route) - verb = verb_from(route) - tree[path] ||= { params: params_from(route), actions: {} } - tree[path][:actions][verb] = { summary: summary_from(route) } - tree - end - end - - private - - def path_from(route) - route.path.spec.to_s - .chomp('(.:format)') # Ignore any format suffix - .gsub(/:([^\/.?]+)/, '{\1}') # Convert :id to {id} - end - - def verb_from(route) - verb = route.verb - if verb.kind_of? String - verb.downcase - else - verb.source.gsub(/[$^]/, '').downcase - end - end - - def summary_from(route) - verb = route.requirements[:action] - noun = route.requirements[:controller].split('/').last.singularize - - # Apply a few customizations to make things more readable - case verb - when 'index' - verb = 'list' - noun = noun.pluralize - when 'destroy' - verb = 'delete' - end - - "#{verb} #{noun}" - end - - def params_from(route) - route.segments - ['format'] - end - end - end - end -end diff --git a/rswag-specs/lib/rswag/route_parser.rb b/rswag-specs/lib/rswag/route_parser.rb new file mode 100644 index 0000000..523b36b --- /dev/null +++ b/rswag-specs/lib/rswag/route_parser.rb @@ -0,0 +1,58 @@ +module Rswag + class RouteParser + attr_reader :controller + + def initialize(controller) + @controller = controller + end + + def routes + ::Rails.application.routes.routes.select do |route| + route.defaults[:controller] == controller + end.reduce({}) do |tree, route| + path = path_from(route) + verb = verb_from(route) + tree[path] ||= { params: params_from(route), actions: {} } + tree[path][:actions][verb] = { summary: summary_from(route) } + tree + end + end + + private + + def path_from(route) + route.path.spec.to_s + .chomp('(.:format)') # Ignore any format suffix + .gsub(/:([^\/.?]+)/, '{\1}') # Convert :id to {id} + end + + def verb_from(route) + verb = route.verb + if verb.kind_of? String + verb.downcase + else + verb.source.gsub(/[$^]/, '').downcase + end + end + + def summary_from(route) + verb = route.requirements[:action] + noun = route.requirements[:controller].split('/').last.singularize + + # Apply a few customizations to make things more readable + case verb + when 'index' + verb = 'list' + noun = noun.pluralize + when 'destroy' + verb = 'delete' + end + + "#{verb} #{noun}" + end + + def params_from(route) + route.segments - ['format'] + end + end +end From 4d29e090109e3de9732391b400097afb4afac7eb Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Wed, 16 Oct 2019 23:19:24 +0100 Subject: [PATCH 13/24] Add spec generator test --- .../lib/generators/rspec/templates/spec.rb | 2 +- .../generators/rspec/fixtures/spec/.gitkeep | 0 .../rspec/swagger_generator_spec.rb | 44 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 rswag-specs/spec/generators/rspec/fixtures/spec/.gitkeep create mode 100644 rswag-specs/spec/generators/rspec/swagger_generator_spec.rb diff --git a/rswag-specs/lib/generators/rspec/templates/spec.rb b/rswag-specs/lib/generators/rspec/templates/spec.rb index 0673596..346e348 100644 --- a/rswag-specs/lib/generators/rspec/templates/spec.rb +++ b/rswag-specs/lib/generators/rspec/templates/spec.rb @@ -6,7 +6,7 @@ RSpec.describe '<%= controller_path %>', type: :request do <% unless path_item[:params].empty? -%> # You'll want to customize the parameter types... <% path_item[:params].each do |param| -%> - parameter '<%= param %>', in: :body, type: :string + parameter name: '<%= param %>', in: :path, type: :string, description: '<%= param %>' <% end -%> <% end -%> <% path_item[:actions].each do | action, details | %> diff --git a/rswag-specs/spec/generators/rspec/fixtures/spec/.gitkeep b/rswag-specs/spec/generators/rspec/fixtures/spec/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rswag-specs/spec/generators/rspec/swagger_generator_spec.rb b/rswag-specs/spec/generators/rspec/swagger_generator_spec.rb new file mode 100644 index 0000000..f11ea65 --- /dev/null +++ b/rswag-specs/spec/generators/rspec/swagger_generator_spec.rb @@ -0,0 +1,44 @@ +require 'generator_spec' +require 'generators/rspec/swagger_generator' +require 'tmpdir' + +module Rspec + describe SwaggerGenerator do + include GeneratorSpec::TestCase + destination Dir.mktmpdir + + before(:all) do + prepare_destination + fixtures_dir = File.expand_path('../fixtures', __FILE__) + FileUtils.cp_r("#{fixtures_dir}/spec", destination_root) + end + + after(:all) do + + end + + it 'installs the swagger_helper for rspec' do + allow_any_instance_of(Rswag::RouteParser).to receive(:routes).and_return(fake_routes) + run_generator ['Posts::CommentsController'] + + assert_file('spec/requests/posts/comments_spec.rb') do |content| + assert_match(/parameter name: 'post_id', in: :path, type: :string/, content) + assert_match(/patch\('update_comments comment'\)/, content) + end + end + + private + + def fake_routes + { + "/posts/{post_id}/comments/{id}" => { + :params => ["post_id", "id"], + :actions => { + "get" => { :summary=>"show comment" }, + "patch" => { :summary=>"update_comments comment" } + } + } + } + end + end +end From 07c4c74d75c2e8cead3b891e36b1e516e4196725 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Thu, 17 Oct 2019 00:02:09 +0100 Subject: [PATCH 14/24] Update changelog --- CHANGELOG.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f30a85..fa57b8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,21 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added ### Changed -- Update swagger-ui to 3.18.2 ### Deprecated ### Removed ### Fixed ### Security +## [2.1.0] - 2019-10-17 +### Added +- New Spec Generator [#75](https://github.com/rswag/rswag/pull/75) +- Support for Options and Trace verbs; You must use a framework that supports this, for Options Rails 6.1+ Rails 6 does not support Trace. [#237](https://github.com/rswag/rswag/pull/75) +### Changed +- Update swagger-ui to 3.18.2 [#240](https://github.com/rswag/rswag/pull/240) + ## [2.0.6] - 2019-10-03 ### Added - Support for Rails 6 [#228](https://github.com/rswag/rswag/pull/228) - Support for Windows paths [#176](https://github.com/rswag/rswag/pull/176) ### Changed - Show response body when error code is not expected [#117](https://github.com/rswag/rswag/pull/177) -### Deprecated -### Removed -### Fixed -### Security ## [2.0.5] - 2018-07-10 From 28245d4dd0248b0566315e4f654d38a11633fc80 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Thu, 17 Oct 2019 10:02:24 +0100 Subject: [PATCH 15/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02d3dff..07cc88d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Once you have an API that can describe itself in Swagger, you've opened the trea |Rswag Version|Swagger (OpenAPI) Spec.|swagger-ui| |----------|----------|----------| |[master](https://github.com/rswag/rswag/tree/master)|2.0|3.18.2| -|[2.0.6](https://github.com/rswag/rswag/tree/2.0.6)|2.0|3.17.3| +|[2.1.0](https://github.com/rswag/rswag/tree/2.1.0)|2.0|3.18.2| |[1.6.0](https://github.com/rswag/rswag/tree/1.6.0)|2.0|2.2.5| ## Getting Started ## From e5eb44191c21f8af81b007421cfd9107d3faf6de Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 21 Sep 2018 17:31:28 +0700 Subject: [PATCH 16/24] Use RSpec.describe to fix IRB context warning in Rails console --- .../spec/generators/rswag/specs/install_generator_spec.rb | 2 +- rswag-specs/spec/rswag/specs/configuration_spec.rb | 2 +- rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb | 2 +- rswag-specs/spec/rswag/specs/example_helpers_spec.rb | 4 ++-- rswag-specs/spec/rswag/specs/request_factory_spec.rb | 4 ++-- rswag-specs/spec/rswag/specs/response_validator_spec.rb | 4 ++-- rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb | 6 +++--- test-app/spec/features/swagger_ui_spec.rb | 2 +- test-app/spec/integration/auth_tests_spec.rb | 2 +- test-app/spec/integration/blogs_spec.rb | 2 +- test-app/spec/rake/rswag_specs_swaggerize_spec.rb | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/rswag-specs/spec/generators/rswag/specs/install_generator_spec.rb b/rswag-specs/spec/generators/rswag/specs/install_generator_spec.rb index 39dc6fe..809e4f6 100644 --- a/rswag-specs/spec/generators/rswag/specs/install_generator_spec.rb +++ b/rswag-specs/spec/generators/rswag/specs/install_generator_spec.rb @@ -4,7 +4,7 @@ require 'generators/rswag/specs/install/install_generator' module Rswag module Specs - describe InstallGenerator do + RSpec.describe InstallGenerator do include GeneratorSpec::TestCase destination File.expand_path('../tmp', __FILE__) diff --git a/rswag-specs/spec/rswag/specs/configuration_spec.rb b/rswag-specs/spec/rswag/specs/configuration_spec.rb index b75d843..30da333 100644 --- a/rswag-specs/spec/rswag/specs/configuration_spec.rb +++ b/rswag-specs/spec/rswag/specs/configuration_spec.rb @@ -3,7 +3,7 @@ require 'rswag/specs/configuration' module Rswag module Specs - describe Configuration do + RSpec.describe Configuration do subject { described_class.new(rspec_config) } let(:rspec_config) { OpenStruct.new(swagger_root: swagger_root, swagger_docs: swagger_docs) } diff --git a/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb b/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb index c870bfc..ed667ca 100644 --- a/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb +++ b/rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb @@ -3,7 +3,7 @@ require 'rswag/specs/example_group_helpers' module Rswag module Specs - describe ExampleGroupHelpers do + RSpec.describe ExampleGroupHelpers do subject { double('example_group') } before do diff --git a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb index 3b22af4..283d4fd 100644 --- a/rswag-specs/spec/rswag/specs/example_helpers_spec.rb +++ b/rswag-specs/spec/rswag/specs/example_helpers_spec.rb @@ -3,7 +3,7 @@ require 'rswag/specs/example_helpers' module Rswag module Specs - describe ExampleHelpers do + RSpec.describe ExampleHelpers do subject { double('example') } before do @@ -12,7 +12,7 @@ module Rswag allow(config).to receive(:get_swagger_doc).and_return(swagger_doc) stub_const('Rswag::Specs::RAILS_VERSION', 3) end - let(:config) { double('config') } + let(:config) { double('config') } let(:swagger_doc) do { securityDefinitions: { diff --git a/rswag-specs/spec/rswag/specs/request_factory_spec.rb b/rswag-specs/spec/rswag/specs/request_factory_spec.rb index f883952..0a70f19 100644 --- a/rswag-specs/spec/rswag/specs/request_factory_spec.rb +++ b/rswag-specs/spec/rswag/specs/request_factory_spec.rb @@ -3,13 +3,13 @@ require 'rswag/specs/request_factory' module Rswag module Specs - describe RequestFactory do + RSpec.describe RequestFactory do subject { RequestFactory.new(config) } before do allow(config).to receive(:get_swagger_doc).and_return(swagger_doc) end - let(:config) { double('config') } + let(:config) { double('config') } let(:swagger_doc) { {} } let(:example) { double('example') } let(:metadata) do diff --git a/rswag-specs/spec/rswag/specs/response_validator_spec.rb b/rswag-specs/spec/rswag/specs/response_validator_spec.rb index 1d05427..9f52b5b 100644 --- a/rswag-specs/spec/rswag/specs/response_validator_spec.rb +++ b/rswag-specs/spec/rswag/specs/response_validator_spec.rb @@ -3,13 +3,13 @@ require 'rswag/specs/response_validator' module Rswag module Specs - describe ResponseValidator do + RSpec.describe ResponseValidator do subject { ResponseValidator.new(config) } before do allow(config).to receive(:get_swagger_doc).and_return(swagger_doc) end - let(:config) { double('config') } + let(:config) { double('config') } let(:swagger_doc) { {} } let(:example) { double('example') } let(:metadata) do diff --git a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb index f904fa5..b5b7ad8 100644 --- a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb +++ b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb @@ -3,8 +3,8 @@ require 'ostruct' module Rswag module Specs - - describe SwaggerFormatter do + + RSpec.describe SwaggerFormatter do subject { described_class.new(output, config) } # Mock out some infrastructure @@ -47,7 +47,7 @@ module Rswag end describe '#stop' do - before do + before do FileUtils.rm_r(swagger_root) if File.exists?(swagger_root) allow(config).to receive(:swagger_docs).and_return( 'v1/swagger.json' => { info: { version: 'v1' } }, diff --git a/test-app/spec/features/swagger_ui_spec.rb b/test-app/spec/features/swagger_ui_spec.rb index 7faa14e..24d5790 100644 --- a/test-app/spec/features/swagger_ui_spec.rb +++ b/test-app/spec/features/swagger_ui_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature 'swagger-ui', js: true do +RSpec.feature 'swagger-ui', js: true do scenario 'browsing api-docs' do visit '/api-docs' diff --git a/test-app/spec/integration/auth_tests_spec.rb b/test-app/spec/integration/auth_tests_spec.rb index 8e47d2e..573219e 100644 --- a/test-app/spec/integration/auth_tests_spec.rb +++ b/test-app/spec/integration/auth_tests_spec.rb @@ -1,6 +1,6 @@ require 'swagger_helper' -describe 'Auth Tests API', type: :request, swagger_doc: 'v1/swagger.json' do +RSpec.describe 'Auth Tests API', type: :request, swagger_doc: 'v1/swagger.json' do path '/auth-tests/basic' do post 'Authenticates with basic auth' do diff --git a/test-app/spec/integration/blogs_spec.rb b/test-app/spec/integration/blogs_spec.rb index abca570..28ee892 100644 --- a/test-app/spec/integration/blogs_spec.rb +++ b/test-app/spec/integration/blogs_spec.rb @@ -1,6 +1,6 @@ require 'swagger_helper' -describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do +RSpec.describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do let(:api_key) { 'fake_key' } path '/blogs' do diff --git a/test-app/spec/rake/rswag_specs_swaggerize_spec.rb b/test-app/spec/rake/rswag_specs_swaggerize_spec.rb index 0a590ee..27fc195 100644 --- a/test-app/spec/rake/rswag_specs_swaggerize_spec.rb +++ b/test-app/spec/rake/rswag_specs_swaggerize_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' require 'rake' -describe 'rswag:specs:swaggerize' do +RSpec.describe 'rswag:specs:swaggerize' do let(:swagger_root) { Rails.root.to_s + '/swagger' } - before do + before do TestApp::Application.load_tasks FileUtils.rm_r(swagger_root) if File.exists?(swagger_root) end From 1d5ed8345f12a101795c2ad4aa05689531f89d5e Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 13:37:36 +0100 Subject: [PATCH 17/24] add a PR template --- .github/pull_request_template.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..3eda872 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,12 @@ +## Problem + +## Solution + +### Related Issues + +### Checklist +- [ ] Added tests +- [ ] Changelog updated + +### Steps to Test or Reproduce +Outline the steps to test or reproduce the PR here. \ No newline at end of file From 29becf98f8a131295352f015ad915fe131b6f5bc Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 14:16:46 +0100 Subject: [PATCH 18/24] add issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 14 ++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 11 +++++++++++ .../pull_request_template.md | 0 3 files changed, 25 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md rename .github/{ => PULL_REQUEST_TEMPLATE}/pull_request_template.md (100%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..7a24179 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,14 @@ +## Describe the bug +A clear and concise description of what the bug is. + +## Steps to Test or Reproduce +Steps to reproduce the behavior: + +## Expected behavior +A clear and concise description of what you expected to happen. + +## Screenshots +If applicable, add screenshots to help explain your problem. + +## Additional context +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bde1cd0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,11 @@ +## Is your feature request related to a problem? Please describe. +A clear and concise description of what the problem is. + +## Describe the solution you'd like +A clear and concise description of what you want to happen. + +## Describe alternatives you've considered +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md similarity index 100% rename from .github/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE/pull_request_template.md From 5b1dde772a38ff03fbc9861d4d8a3f730b69113a Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 14:27:07 +0100 Subject: [PATCH 19/24] Update pr template --- .github/PULL_REQUEST_TEMPLATE/pull_request_template.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md index 3eda872..4fc530f 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -1,8 +1,11 @@ ## Problem +A clear and concise description of what the problem is. ## Solution +A clear and concise description of the solution. ### Related Issues +Links to any related issues. ### Checklist - [ ] Added tests From a18d9e51633fca68d376dbb1280b11b648e373e3 Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 14:36:25 +0100 Subject: [PATCH 20/24] update copy --- .github/PULL_REQUEST_TEMPLATE/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md index 4fc530f..73c44a1 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -2,7 +2,7 @@ A clear and concise description of what the problem is. ## Solution -A clear and concise description of the solution. +A clear and concise description of what the solution is. ### Related Issues Links to any related issues. From 8d7385fcac86def49e0e989d9ae9f925bc660aeb Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 16:22:12 +0100 Subject: [PATCH 21/24] update copy --- .github/ISSUE_TEMPLATE/bug_report.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7a24179..57df306 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,7 +2,7 @@ A clear and concise description of what the bug is. ## Steps to Test or Reproduce -Steps to reproduce the behavior: +Please provide an example repo or the steps to reproduce the behavior. ## Expected behavior A clear and concise description of what you expected to happen. @@ -12,3 +12,6 @@ If applicable, add screenshots to help explain your problem. ## Additional context Add any other context about the problem here. + +## Rswag Version +The version of rswag are you using. From ea2ed6ca49fa28d2094cc53f4ca8f3e9354ad70b Mon Sep 17 00:00:00 2001 From: Laura Watson Date: Thu, 17 Oct 2019 17:18:27 +0100 Subject: [PATCH 22/24] Update README --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 07cc88d..12c27b1 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,15 @@ Once you have an API that can describe itself in Swagger, you've opened the trea gem 'rswag' ``` - or if you like to avoid loading rspec in other bundler groups. + or if you like to avoid loading rspec in other bundler groups load the rswag-specs component separately. + Note: Adding it to the :development group is not strictly necessary, but without it, generators and rake tasks must be preceded by RAILS_ENV=test. ```ruby # Gemfile gem 'rswag-api' gem 'rswag-ui' - group :test do + group :development, :test do gem 'rspec-rails' gem 'rswag-specs' end @@ -44,11 +45,11 @@ Once you have an API that can describe itself in Swagger, you've opened the trea ```ruby rails g rswag:install ``` - + Or run the install generators for each package separately if you installed Rswag as separate gems, as indicated above: - + ```ruby - rails g rswag:api:install + rails g rswag:api:install rails g rswag:ui:install RAILS_ENV=test rails g rswag:specs:install ``` @@ -222,7 +223,7 @@ RSpec.configure do |config| end ``` -#### Supporting multiple versions of API #### +#### Supporting multiple versions of API #### By default, the paths, operations and responses defined in your spec files will be associated with the first Swagger document in _swagger_helper.rb_. If your API has multiple versions, you should be using separate documents to describe each of them. In order to assign a file with a given version of API, you'll need to add the ```swagger_doc``` tag to each spec specifying its target document name: ```ruby @@ -237,14 +238,14 @@ describe 'Blogs API', swagger_doc: 'v2/swagger.json' do end ``` -#### Formatting the description literals: #### -Swagger supports the Markdown syntax to format strings. This can be especially handy if you were to provide a long description of a given API version or endpoint. Use [this guide](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for reference. +#### Formatting the description literals: #### +Swagger supports the Markdown syntax to format strings. This can be especially handy if you were to provide a long description of a given API version or endpoint. Use [this guide](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for reference. __NOTE:__ There is one difference between the official Markdown syntax and Swagger interpretation, namely tables. To create a table like this: | Column1 | Collumn2 | | ------- | -------- | -| cell1 | cell2 | +| cell1 | cell2 | you should use the folowing syntax, making sure there are no whitespaces at the start of any of the lines: From c14f72a45e47676312c28729bafece2da83ac8e7 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Fri, 18 Oct 2019 23:18:30 +0100 Subject: [PATCH 23/24] Point the railtie to the correct file Fixes #248 --- rswag-specs/lib/rswag/specs/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rswag-specs/lib/rswag/specs/railtie.rb b/rswag-specs/lib/rswag/specs/railtie.rb index 994a8a4..617403e 100644 --- a/rswag-specs/lib/rswag/specs/railtie.rb +++ b/rswag-specs/lib/rswag/specs/railtie.rb @@ -7,7 +7,7 @@ module Rswag end generators do - require 'generators/rspec/swagger/swagger_generator.rb' + require 'generators/rspec/swagger_generator.rb' end end end From 2cf6812ae0948715b281d8f809d106b0864bc3bb Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sat, 19 Oct 2019 21:39:24 +0100 Subject: [PATCH 24/24] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a39bb68..bbf46e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ rswag ========= [![Build Status](https://travis-ci.org/rswag/rswag.svg?branch=master)](https://travis-ci.org/rswag/rswag) +[![Maintainability](https://api.codeclimate.com/v1/badges/1175b984edc4610f82ab/maintainability)](https://codeclimate.com/github/rswag/rswag/maintainability) [Swagger](http://swagger.io) tooling for Rails API's. Generate beautiful API documentation, including a UI to explore and test operations, directly from your rspec integration tests. @@ -15,7 +16,7 @@ Once you have an API that can describe itself in Swagger, you've opened the trea |Rswag Version|Swagger (OpenAPI) Spec.|swagger-ui| |----------|----------|----------| |[master](https://github.com/rswag/rswag/tree/master)|2.0|3.18.2| -|[2.1.0](https://github.com/rswag/rswag/tree/2.1.0)|2.0|3.18.2| +|[2.1.1](https://github.com/rswag/rswag/tree/2.1.1)|2.0|3.18.2| |[1.6.0](https://github.com/rswag/rswag/tree/1.6.0)|2.0|2.2.5| ## Getting Started ##