rspec-openapi 0.18.2 → 0.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile +4 -0
- data/README.md +10 -0
- data/lib/rspec/openapi/extractors/hanami.rb +3 -10
- data/lib/rspec/openapi/extractors/rails.rb +2 -2
- data/lib/rspec/openapi/extractors.rb +0 -7
- data/lib/rspec/openapi/record.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +2 -0
- data/lib/rspec/openapi/result_recorder.rb +1 -1
- data/lib/rspec/openapi/schema_builder.rb +5 -1
- data/lib/rspec/openapi/version.rb +1 -1
- data/lib/rspec/openapi.rb +31 -21
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ec34ef0e56eb4c46221d956120a836d20addbfa8d636807effad4b93cf5ac8f8
         | 
| 4 | 
            +
              data.tar.gz: 8b2c33feefc0f7173e6f31a09c66c9824b2f3f6124a24c6f56f59f7f5ff3e938
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e2e12be8f18ac6e3c6641bb3b128bad631c120f4400148f999b758b1b2820b44dd047569036c1adc4393b001a438f2595aacf5869540411ec077c054a6b8d4c3
         | 
| 7 | 
            +
              data.tar.gz: 347a1c54c418ad9957b3137b2d7db8c0c74496b473cdaf9f14dc9e4dab0205340e510317c324ff68494e237b27a369642d7cba2687b6eaa88318a70387557f37
         | 
    
        data/.github/workflows/test.yml
    CHANGED
    
    | @@ -38,7 +38,7 @@ jobs: | |
| 38 38 | 
             
                  - run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
         | 
| 39 39 | 
             
                    name: codecov-action@v4 workaround
         | 
| 40 40 | 
             
                  - name: Upload coverage reports
         | 
| 41 | 
            -
                    uses: codecov/codecov-action@ | 
| 41 | 
            +
                    uses: codecov/codecov-action@v5
         | 
| 42 42 | 
             
                    if: matrix.coverage == 'coverage'
         | 
| 43 43 | 
             
                    with:
         | 
| 44 44 | 
             
                      fail_ci_if_error: true
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -11,8 +11,12 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') | |
| 11 11 | 
             
              gem 'hanami', ENV['HANAMI_VERSION'] || '2.1.0'
         | 
| 12 12 | 
             
              gem 'hanami-controller', ENV['HANAMI_VERSION'] || '2.1.0'
         | 
| 13 13 | 
             
              gem 'hanami-router', ENV['HANAMI_VERSION'] || '2.1.0'
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              gem 'dry-logger', '1.0.3'
         | 
| 14 16 | 
             
            end
         | 
| 15 17 |  | 
| 18 | 
            +
            gem 'concurrent-ruby', '1.3.4'
         | 
| 19 | 
            +
             | 
| 16 20 | 
             
            gem 'roda'
         | 
| 17 21 |  | 
| 18 22 | 
             
            gem 'rails-dom-testing', '~> 2.2'
         | 
    
        data/README.md
    CHANGED
    
    | @@ -122,8 +122,18 @@ RSpec::OpenAPI.path = -> (example) { | |
| 122 122 | 
             
              end
         | 
| 123 123 | 
             
            }
         | 
| 124 124 |  | 
| 125 | 
            +
            # Change the default title of the generated schema
         | 
| 125 126 | 
             
            RSpec::OpenAPI.title = 'OpenAPI Documentation'
         | 
| 126 127 |  | 
| 128 | 
            +
            # Or generate individual titles for your partial schema files, given an RSpec example
         | 
| 129 | 
            +
            RSpec::OpenAPI.title = -> (example) {
         | 
| 130 | 
            +
              case example.file_path
         | 
| 131 | 
            +
              when %r[spec/requests/api/v1/] then 'API v1 Documentation'
         | 
| 132 | 
            +
              when %r[spec/requests/api/v2/] then 'API v2 Documentation'
         | 
| 133 | 
            +
              else 'OpenAPI Documentation'
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
            }
         | 
| 136 | 
            +
             | 
| 127 137 | 
             
            # Disable generating `example`
         | 
| 128 138 | 
             
            RSpec::OpenAPI.enable_example = false
         | 
| 129 139 |  | 
| @@ -19,10 +19,7 @@ class Inspector | |
| 19 19 | 
             
              def call(verb, path)
         | 
| 20 20 | 
             
                route = routes.find { |r| r.http_method == verb && r.path == path }
         | 
| 21 21 |  | 
| 22 | 
            -
                if route. | 
| 23 | 
            -
                  # FIXME: This is a hack to pass `/sites/***` in testing
         | 
| 24 | 
            -
                  {}
         | 
| 25 | 
            -
                elsif route.to.is_a?(Proc)
         | 
| 22 | 
            +
                if route.to.is_a?(Proc)
         | 
| 26 23 | 
             
                  {
         | 
| 27 24 | 
             
                    tags: [],
         | 
| 28 25 | 
             
                    summary: "#{verb} #{path}",
         | 
| @@ -55,7 +52,7 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new | |
| 55 52 | 
             
              # @param [RSpec::Core::Example] example
         | 
| 56 53 | 
             
              # @return Array
         | 
| 57 54 | 
             
              def request_attributes(request, example)
         | 
| 58 | 
            -
                route = Hanami.app.router.recognize(request.path, method: request.method)
         | 
| 55 | 
            +
                route = Hanami.app.router.recognize(Rack::MockRequest.env_for(request.path, method: request.method))
         | 
| 59 56 |  | 
| 60 57 | 
             
                return RSpec::OpenAPI::Extractors::Rack.request_attributes(request, example) unless route.routable?
         | 
| 61 58 |  | 
| @@ -69,7 +66,7 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new | |
| 69 66 | 
             
                deprecated = metadata[:deprecated]
         | 
| 70 67 | 
             
                path = request.path
         | 
| 71 68 |  | 
| 72 | 
            -
                raw_path_params = route.params | 
| 69 | 
            +
                raw_path_params = route.params
         | 
| 73 70 |  | 
| 74 71 | 
             
                result = InspectorAnalyzer.call(request.method, add_id(path, route))
         | 
| 75 72 |  | 
| @@ -95,8 +92,6 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new | |
| 95 92 | 
             
                return path if route.params.empty?
         | 
| 96 93 |  | 
| 97 94 | 
             
                route.params.each_pair do |key, value|
         | 
| 98 | 
            -
                  next unless RSpec::OpenAPI::Extractors.number_or_nil(value)
         | 
| 99 | 
            -
             | 
| 100 95 | 
             
                  path = path.sub("/#{value}", "/:#{key}")
         | 
| 101 96 | 
             
                end
         | 
| 102 97 |  | 
| @@ -107,8 +102,6 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new | |
| 107 102 | 
             
                return path if route.params.empty?
         | 
| 108 103 |  | 
| 109 104 | 
             
                route.params.each_pair do |key, value|
         | 
| 110 | 
            -
                  next unless RSpec::OpenAPI::Extractors.number_or_nil(value)
         | 
| 111 | 
            -
             | 
| 112 105 | 
             
                  path = path.sub("/#{value}", "/{#{key}}")
         | 
| 113 106 | 
             
                end
         | 
| 114 107 |  | 
| @@ -12,10 +12,10 @@ class << RSpec::OpenAPI::Extractors::Rails = Object.new | |
| 12 12 |  | 
| 13 13 | 
             
                route, path = find_rails_route(fixed_request)
         | 
| 14 14 |  | 
| 15 | 
            -
                raise "No route matched for #{fixed_request.request_method} #{fixed_request.path_info}" if route.nil?
         | 
| 16 | 
            -
             | 
| 17 15 | 
             
                return RSpec::OpenAPI::Extractors::Rack.request_attributes(request, example) unless path
         | 
| 18 16 |  | 
| 17 | 
            +
                raise "No route matched for #{fixed_request.request_method} #{fixed_request.path_info}" if route.nil?
         | 
| 18 | 
            +
             | 
| 19 19 | 
             
                metadata = example.metadata[:openapi] || {}
         | 
| 20 20 | 
             
                summary = metadata[:summary] || RSpec::OpenAPI.summary_builder.call(example)
         | 
| 21 21 | 
             
                tags = metadata[:tags] || RSpec::OpenAPI.tags_builder.call(example)
         | 
    
        data/lib/rspec/openapi/record.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            RSpec::OpenAPI::Record = Struct.new(
         | 
| 4 | 
            +
              :title,                 # @param [String]  - "API Documentation - Statuses"
         | 
| 4 5 | 
             
              :http_method,           # @param [String]  - "GET"
         | 
| 5 6 | 
             
              :path,                  # @param [String]  - "/v1/status/:id"
         | 
| 6 7 | 
             
              :path_params,           # @param [Hash]    - {:controller=>"v1/statuses", :action=>"create", :id=>"1"}
         | 
| @@ -11,6 +11,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new | |
| 11 11 | 
             
                request, response = extractor.request_response(context)
         | 
| 12 12 | 
             
                return if request.nil?
         | 
| 13 13 |  | 
| 14 | 
            +
                title = RSpec::OpenAPI.title.then { |t| t.is_a?(Proc) ? t.call(example) : t }
         | 
| 14 15 | 
             
                path, summary, tags, operation_id, required_request_params, raw_path_params, description, security, deprecated =
         | 
| 15 16 | 
             
                  extractor.request_attributes(request, example)
         | 
| 16 17 |  | 
| @@ -19,6 +20,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new | |
| 19 20 | 
             
                request_headers, response_headers = extract_headers(request, response)
         | 
| 20 21 |  | 
| 21 22 | 
             
                RSpec::OpenAPI::Record.new(
         | 
| 23 | 
            +
                  title: title,
         | 
| 22 24 | 
             
                  http_method: request.method,
         | 
| 23 25 | 
             
                  path: path,
         | 
| 24 26 | 
             
                  path_params: raw_path_params,
         | 
| @@ -16,7 +16,7 @@ class RSpec::OpenAPI::ResultRecorder | |
| 16 16 | 
             
                    puts "WARNING: Unable to load #{config_file}: #{e}"
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 |  | 
| 19 | 
            -
                  title =  | 
| 19 | 
            +
                  title = records.first.title
         | 
| 20 20 | 
             
                  RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
         | 
| 21 21 | 
             
                    schema = RSpec::OpenAPI::DefaultSchema.build(title)
         | 
| 22 22 | 
             
                    schema[:info].merge!(RSpec::OpenAPI.info)
         | 
| @@ -36,7 +36,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new | |
| 36 36 | 
             
                        security: record.security,
         | 
| 37 37 | 
             
                        deprecated: record.deprecated ? true : nil,
         | 
| 38 38 | 
             
                        parameters: build_parameters(record),
         | 
| 39 | 
            -
                        requestBody: http_method  | 
| 39 | 
            +
                        requestBody: include_nil_request_body?(http_method) ? nil : build_request_body(record),
         | 
| 40 40 | 
             
                        responses: {
         | 
| 41 41 | 
             
                          record.status.to_s => response,
         | 
| 42 42 | 
             
                        },
         | 
| @@ -48,6 +48,10 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new | |
| 48 48 |  | 
| 49 49 | 
             
              private
         | 
| 50 50 |  | 
| 51 | 
            +
              def include_nil_request_body?(http_method)
         | 
| 52 | 
            +
                %w[delete get].include?(http_method)
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 51 55 | 
             
              def enrich_with_required_keys(obj)
         | 
| 52 56 | 
             
                obj[:required] = obj[:properties]&.keys || []
         | 
| 53 57 | 
             
                obj
         | 
    
        data/lib/rspec/openapi.rb
    CHANGED
    
    | @@ -15,30 +15,17 @@ require 'rspec/openapi/shared_hooks' | |
| 15 15 | 
             
            require 'rspec/openapi/extractors'
         | 
| 16 16 | 
             
            require 'rspec/openapi/extractors/rack'
         | 
| 17 17 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
               | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                require 'hanami'
         | 
| 23 | 
            -
              rescue LoadError
         | 
| 24 | 
            -
                warn 'Hanami not detected' if DEBUG_ENABLED
         | 
| 25 | 
            -
              else
         | 
| 26 | 
            -
                require 'rspec/openapi/extractors/hanami'
         | 
| 27 | 
            -
              end
         | 
| 18 | 
            +
            module RSpec::OpenAPI
         | 
| 19 | 
            +
              class Config
         | 
| 20 | 
            +
                class << self
         | 
| 21 | 
            +
                  attr_accessor :debug_enabled
         | 
| 28 22 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                 | 
| 33 | 
            -
              else
         | 
| 34 | 
            -
                require 'rspec/openapi/extractors/rails'
         | 
| 23 | 
            +
                  def load_environment_settings
         | 
| 24 | 
            +
                    @debug_enabled = ['', '1', 'true'].include?(ENV['DEBUG']&.downcase)
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 35 27 | 
             
              end
         | 
| 36 | 
            -
            end
         | 
| 37 28 |  | 
| 38 | 
            -
            require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
         | 
| 39 | 
            -
            require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
         | 
| 40 | 
            -
             | 
| 41 | 
            -
            module RSpec::OpenAPI
         | 
| 42 29 | 
             
              @path = 'doc/openapi.yaml'
         | 
| 43 30 | 
             
              @title = File.basename(Dir.pwd)
         | 
| 44 31 | 
             
              @comment = nil
         | 
| @@ -84,3 +71,26 @@ module RSpec::OpenAPI | |
| 84 71 | 
             
                attr_reader   :config_filename
         | 
| 85 72 | 
             
              end
         | 
| 86 73 | 
             
            end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            if ENV['OPENAPI']
         | 
| 76 | 
            +
              RSpec::OpenAPI::Config.load_environment_settings
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              begin
         | 
| 79 | 
            +
                require 'hanami'
         | 
| 80 | 
            +
              rescue LoadError
         | 
| 81 | 
            +
                warn 'Hanami not detected' if RSpec::OpenAPI::Config.debug_enabled
         | 
| 82 | 
            +
              else
         | 
| 83 | 
            +
                require 'rspec/openapi/extractors/hanami'
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              begin
         | 
| 87 | 
            +
                require 'rails'
         | 
| 88 | 
            +
              rescue LoadError
         | 
| 89 | 
            +
                warn 'Rails not detected' if RSpec::OpenAPI::Config.debug_enabled
         | 
| 90 | 
            +
              else
         | 
| 91 | 
            +
                require 'rspec/openapi/extractors/rails'
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
            end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
            require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
         | 
| 96 | 
            +
            require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rspec-openapi
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.18. | 
| 4 | 
            +
              version: 0.18.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Takashi Kokubun
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire:
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2025-02-06 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: actionpack
         | 
| @@ -109,7 +109,7 @@ licenses: | |
| 109 109 | 
             
            metadata:
         | 
| 110 110 | 
             
              homepage_uri: https://github.com/exoego/rspec-openapi
         | 
| 111 111 | 
             
              source_code_uri: https://github.com/exoego/rspec-openapi
         | 
| 112 | 
            -
              changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.18. | 
| 112 | 
            +
              changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.18.4
         | 
| 113 113 | 
             
              rubygems_mfa_required: 'true'
         | 
| 114 114 | 
             
            post_install_message:
         | 
| 115 115 | 
             
            rdoc_options: []
         |