skryukov / skooma

Skooma is a Ruby library for validating API implementations against OpenAPI documents.
MIT License
134 stars 5 forks source link

Skooma::Error: Missing `name` key /request #12

Closed ShonRepo closed 6 months ago

ShonRepo commented 6 months ago

Hey. This test produces a strange error. There are no problems in other tests.

require "public_helper"

describe "Related material" do
  let_it_be(:author) { create :material_author }
  let_it_be(:main_material) { create :material, author: author }
  let_it_be(:material1) { create :material, author: author }
  let_it_be(:material2) { create :material, author: author }
  let_it_be(:material3) { create :material, author: author }
  let_it_be(:material4) { create :material }
  let_it_be(:tag) { create :material_tag, materials: [main_material, material1, material2, material4] }

  sso_auth_skooma

  describe "/materials/related-materials" do
    describe "GET" do
      subject { get "/public/v1/materials/related-materials/", params: params, headers: {Authorization: authorization} }

      let(:params) do
        {
          id: main_material.id,
          authors: author.id,
          tags: tag.id
        }
      end

      context "success" do
        it { is_expected.to conform_schema(200) }
      end

      context "Not found" do
        let(:params) do
          {
            id: -1,
            authors: author.id,
            tags: tag.id
          }
        end

        it { is_expected.to conform_schema(404) }
      end
    end
  end
end

Error:

Skooma::Error: Missing `name` key /request: 

  0) Related material /materials/related-materials GET success is expected to conform schema with 200 response code
     Failure/Error: it { is_expected.to conform_schema(200) }

     Skooma::Error:
       Missing `name` key /request: 
     # ./spec/requests/public/v1/materials/related_materials_spec.rb:27:in `block (5 levels) in <top (required)>'
     # ./spec/rails_helper.rb:46:in `block (3 levels) in <top (required)>'
     # /Users/ivannikolaev/.rbenv/versions/3.2.2/lib/ruby/3.2.0/forwardable.rb:240:in `cleaning'
     # /Users/ivannikolaev/.rbenv/versions/3.2.2/lib/ruby/3.2.0/forwardable.rb:240:in `cleaning'
     # ./spec/rails_helper.rb:45:in `block (2 levels) in <top (required)>'
     # /Users/ivannikolaev/.rbenv/versions/3.2.2/bin/rspec:25:in `load'
     # /Users/ivannikolaev/.rbenv/versions/3.2.2/bin/rspec:25:in `<main>'
skryukov commented 6 months ago

It looks like skooma thinks that one of request parameters misses the name keyword. Could you check if the openapi document is valid? If it is valid, could you share the /public/v1/materials/related-materials.get schema?

ShonRepo commented 6 months ago
  "/materials/related-materials":
    get:
      summary: Materials
      tags:
      - Материалы
      security:
      - bearer: []
      parameters:
      - in: query
        required: true
        name: id
        schema:
          type: integer
        explode: false
      - in: query
        required: true
        name: authors
        schema:
          type: integer
        explode: false
      - in: query
        required: true
        name: tags
        schema:
          type: string
        explode: false
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  "$ref": "#/components/schemas/related_material_list"
        '404':
          description: Not found
skryukov commented 6 months ago

The problem is that required was executed before name was set, another problem is a poor error message 😂

Both issues are fixed and will be available in the next release. Thanks for your issues ❤️

ShonRepo commented 6 months ago

Thanks!