Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 459 forks source link

Recording does not include params in the documentation #686

Open florinionce opened 4 years ago

florinionce commented 4 years ago

Hello,

I'm not sure if this is intended, or a known limitation or I'm simply making something wrong, but If I record the examples from RSpec, I don't get the parameters in the generated documentation.

Let's say I have this dummy spec:

  describe 'POST /api/v1/dummy' do
    context 'valid user' do
      before do
        post '/api/v1/dummy', params:  { sort: true }
      end

      it 'returns status code ok' do
        expect(response).to have_http_status(:ok)
      end

      it 'returns the body', :show_in_doc do
        expect(json['ok']).to eq(true)
      end
    end
  end

If I record the examples, I don't get the parameter that is being sent in the parameters list, I can only see it in the example from above. See the following screenshot image

This is my config:

# frozen_string_literal: true

Apipie.configure do |config|
  config.app_name                = 'Test app'
  config.api_base_url            = '/api'
  config.doc_base_url            = '/apipie'
  config.api_controllers_matcher = Rails.root.join('app', 'controllers', 'api', '**', '*.rb')
  config.show_all_examples       = true
  config.translate               = false
  config.validate                = false
  config.namespaced_resources    = true
  config.swagger_api_host        = 'http://localhost:3000'

  config.authenticate = proc do
    authenticate_or_request_with_http_basic do |username, password|
      username == Credentials[:apipie][:username] && password == Credentials[:apipie][:password]
    end
  end
end

I know that I can get it working by adding param :sort, [true, false], but I was wondering If I can do it without having to write all the params. I would rather rely on the specs to keep the documentation up to date, instead of manually making all the changes.

Is there something that I am missing here or it's just ignoring them?

sasharevzin commented 3 years ago

@florinionce sorry for not a related question, but you have two tests in your spec, but it shows only one example in doc. Shouldn't it show two examples?

florinionce commented 3 years ago

@sasharevzin - that's because I only wrote show_in_doc: true for one of the tests. In order to display multiple tests, I pretty much follow this example