Method: Fitting::Doc.all

Defined in:
lib/fitting/doc.rb

.allObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fitting/doc.rb', line 8

def self.all
  apis = YAML.safe_load(File.read('.fitting.yml'))['APIs']
  return [] unless apis
  apis.map do |api|
    if api['type'] == 'openapi2'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', openapi2_json_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'openapi3'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', openapi3_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'drafter'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', drafter_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'crafter'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', crafter_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'tomogram'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', tomogram_json_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    end
  end.flatten
end