zipmark/rspec_api_documentation

undefined method `route' for RSpec::Core::Example when using callbacks

Opened this issue · 2 comments

I'm getting an undefined method exception when trying to generate docs for callbacks

  resource 'Webhook Callback' do
    let(:webhook) { Webhook.new(url: callback_url) }

    callback '/webhook' do
      let(:callback_url) { 'https://example.com/webhook' }
      let(:payload) do
        {
          name: name,
          email: email,
        }.as_json
      end

      trigger_callback do
        webhook.call(payload)
      end

      example 'Receiving a callback' do
        do_callback
        expect(request_method).to eq('POST')
        expect(request_headers['Content-Type']).to eq('application/json')
        expect(JSON.parse(request_body)).to eq(payload)
      end
    end
  end

The specs pass when I just run them as part of the full RSpec suite, but when I run them using rake docs:generate I get:

/Users/viamin/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/example.rb:14:in `method_missing': undefined method `route' for #<RSpec::Core::Example:0x00007fba4643a500> (NoMethodError)

I see in #222 there's mention of needing a get/post block, but it's not clear if/how that's needed for callbacks. (The relish docs look more like my example above)

So I fixed this by adding route: '<my callbackurl>', method: :post, and extended_parameters: {} to my failing example metadata.

This creates invalid OpenAPI docs, since there's a missing response code. Not sure how that's expected to be set - expect(status).to eq(200) after a do_callback raises an error: undefined local variable or method 'status'