diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 00000000..575ca3ed --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,37 @@ +name: "Rubocop" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + rubocop: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + + - name: Install dependencies + run: bundle install + + - name: Rubocop run + run: | + bash -c " + bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif + [[ $? -ne 2 ]] + " + + - name: Upload Sarif output + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: rubocop.sarif diff --git a/Gemfile b/Gemfile index 207d1889..3fe269cb 100644 --- a/Gemfile +++ b/Gemfile @@ -13,4 +13,5 @@ end group :development do gem 'pry' + gem "code-scanning-rubocop" end diff --git a/lib/rspec/openapi/hooks.rb b/lib/rspec/openapi/hooks.rb index 6c8762ba..58da3fbd 100644 --- a/lib/rspec/openapi/hooks.rb +++ b/lib/rspec/openapi/hooks.rb @@ -12,7 +12,7 @@ RSpec.configuration.after(:each) do |example| if RSpec::OpenAPI.example_types.include?(example.metadata[:type]) && example.metadata[:openapi] != false - path = RSpec::OpenAPI.path.yield_self { |path| path.is_a?(Proc) ? path.call(example) : path } + path = RSpec::OpenAPI.path.yield_self { |p| p.is_a?(Proc) ? p.call(example) : p } record = RSpec::OpenAPI::RecordBuilder.build(self, example: example) path_records[path] << record if record end diff --git a/lib/rspec/openapi/record.rb b/lib/rspec/openapi/record.rb index 984f09d8..4e36d982 100644 --- a/lib/rspec/openapi/record.rb +++ b/lib/rspec/openapi/record.rb @@ -1,5 +1,5 @@ RSpec::OpenAPI::Record = Struct.new( - :method, # @param [String] - "GET" + :http_method, # @param [String] - "GET" :path, # @param [String] - "/v1/status/:id" :path_params, # @param [Hash] - {:controller=>"v1/statuses", :action=>"create", :id=>"1"} :query_params, # @param [Hash] - {:query=>"string"} diff --git a/lib/rspec/openapi/record_builder.rb b/lib/rspec/openapi/record_builder.rb index a8a6e7d8..50b40729 100644 --- a/lib/rspec/openapi/record_builder.rb +++ b/lib/rspec/openapi/record_builder.rb @@ -49,7 +49,7 @@ def build(context, example:) end RSpec::OpenAPI::Record.new( - method: request.request_method, + http_method: request.method, path: path, path_params: raw_path_params(request), query_params: request.query_parameters, diff --git a/lib/rspec/openapi/schema_builder.rb b/lib/rspec/openapi/schema_builder.rb index 3af57eac..e427322d 100644 --- a/lib/rspec/openapi/schema_builder.rb +++ b/lib/rspec/openapi/schema_builder.rb @@ -22,7 +22,7 @@ def build(record) { paths: { normalize_path(record.path) => { - record.method.downcase => { + record.http_method.downcase => { summary: record.summary, tags: record.tags, parameters: build_parameters(record),