Class: RswagSchemaExport::Differ

Inherits:
Object
  • Object
show all
Defined in:
lib/rswag_schema_export/differ.rb

Class Method Summary collapse

Class Method Details

.call(previews_schema, new_schema) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rswag_schema_export/differ.rb', line 5

def self.call(previews_schema, new_schema)
  previews_schema_json = JSON.parse(File.read(previews_schema))
  previews_schema_json["host"] = "localhost"

  File.write(previews_schema, JSON.pretty_generate(previews_schema_json))

  new_schema_json = JSON.parse(File.read(new_schema))
  new_schema_json["host"] = "localhost"

  File.write(new_schema, JSON.pretty_generate(new_schema_json))

  diff = ::Swagger::Diff::Diff.new(previews_schema, new_schema)
  changes = []
  report = ""

  diff.changes.map do |topic|
    report += "#{topic.first}: #{topic.last} \n"
    changes << topic.last unless topic.last.empty?
  end
  if changes.empty?
    nil
  else
    report
  end
end