ubicloud/bin/check-needed-openapi-paths
Jeremy Evans 761eeed12f Remove invalid request method for firewall path from openapi.yml
While working on #4101, I came across a bogus openapi.yml entry,
which I removed in 61d036ced0.

This led me to believe there may be other bogus entries. I modified
bin/check-needed-openapi-paths to not just check whether a path was
needed, but whether the request method + path combination was needed.
It only found a single other bogus path
(`POST /project/{project_id}/firewall`), which this removes. The
correct path to create a firewall is
`POST /project/{project_id}/location/{location}/firewall/{firewall_reference}`,
which remains.
2025-10-30 02:30:48 +09:00

39 lines
898 B
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require "yaml"
file = "openapi/openapi.yml"
openapi = YAML.load_file(file)
paths = openapi["paths"]
unnecessary_paths = []
# Run all api specs with one path deleted. If there is not a failure,
# the path isn't actually needed and should be removed.
paths.each do |path, methods|
methods.keys.each do |meth|
next if meth == "parameters"
value = methods.delete(meth)
File.write(file, YAML.dump(openapi))
method_path = "#{meth.upcase} #{path}"
print "#{method_path}..."
if system("rake api_spec >/dev/null 2>&1")
unnecessary_paths << method_path
puts "NOT NEEDED"
else
puts "needed"
methods[meth] = value
end
end
end
File.write(file, YAML.dump(openapi))
system("rake linter:openapi")
unless unnecessary_paths.empty?
puts "These paths are not used:", unnecessary_paths
exit 1
end