Class: MemoriClient::Swagger::ProcessSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/memori_client/swagger/process_specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, kind:) ⇒ ProcessSpecification

Returns a new instance of ProcessSpecification.



5
6
7
8
9
10
11
12
# File 'lib/memori_client/swagger/process_specification.rb', line 5

def initialize(uri:, kind:)
  @uri = uri
  @kind = kind
  @result = {}
  @endpoints = {}
  @methods = {}
  @methods_collisions = []
end

Instance Attribute Details

#swagger_specObject (readonly)

Returns the value of attribute swagger_spec.



4
5
6
# File 'lib/memori_client/swagger/process_specification.rb', line 4

def swagger_spec
  @swagger_spec
end

Instance Method Details

#callObject



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
# File 'lib/memori_client/swagger/process_specification.rb', line 14

def call
  puts "Processing Swagger spec #{@kind} from #{@uri}"
  data = URI.open(@uri).read
  parsed = JSON.parse(data)
  @swagger_spec = parsed
  paths = parsed['paths']
  # routes = collect_routes(paths)
  # puts JSON.pretty_generate(routes)
  paths.each do |path, path_data|
    path_data.each do |method, endpoint|
      module_name, info = analyze_path(method, path, endpoint)
      unless module_name.nil?
        @result[module_name] ||= []
        @result[module_name] << info
      end
    end
  end

  # Verify collisions
  @methods.keys.sort.each do |m|
    if @methods[m].size > 1
      @methods_collisions << m
      puts "#{m} => #{@methods[m].size}"
      @methods[m].each do |mm|
        puts " - #{mm}"
      end
    end
  end

  if @methods_collisions.size > 0
    puts "Stopping because we found #{@methods_collisions.size} collisions in ns #{@kind}. Collisions are:"
    @methods_collisions.each do |m|
      puts "Method: #{m}"
      puts @methods[m].join("\n")
      puts '--'
    end

    raise "Stop"
  end

  @result
end