Class: ElderDocs::Engine::ApiController

Inherits:
ActionController::API
  • Object
show all
Includes:
ActionController::MimeResponds
Defined in:
lib/elder_docs/engine/api_controller.rb

Instance Method Summary collapse

Instance Method Details

#articlesObject



19
20
21
22
23
24
25
26
# File 'lib/elder_docs/engine/api_controller.rb', line 19

def articles
  articles_path = find_articles_file
  if articles_path && File.exist?(articles_path)
    render json: JSON.parse(File.read(articles_path, encoding: 'UTF-8'))
  else
    render json: []
  end
end

#configObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/elder_docs/engine/api_controller.rb', line 28

def config
  # Reload config to get latest from elderdocs.yml
  ElderDocs.config.load_config_file
  
  config_data = {
    api_server: ElderDocs.config.api_server,
    api_servers: ElderDocs.config.api_servers || [],
    auth_types: ElderDocs.config.auth_types || ['bearer', 'api_key', 'basic', 'oauth2'],
    ui_config: ElderDocs.config.ui_config || {}
  }
  
  render json: config_data
end

#definitionsObject



10
11
12
13
14
15
16
17
# File 'lib/elder_docs/engine/api_controller.rb', line 10

def definitions
  definitions_path = find_definitions_file
  if definitions_path && File.exist?(definitions_path)
    render json: JSON.parse(File.read(definitions_path, encoding: 'UTF-8'))
  else
    render json: { error: 'definitions.json not found' }, status: :not_found
  end
end