Skip to content

Commit

Permalink
(#15) Add servers field check
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 18, 2023
1 parent dbaf62f commit 7f3a1ab
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/analyzer/analyzers/analyzer_oas3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ class AnalyzerOAS3 < Analyzer
json_obj = JSON.parse(content)

base_path = @url
servers = json_obj["servers"]
if !servers.nil?
servers.as_a.each do |server_obj|
if server_obj["url"].to_s.starts_with?("http")
user_uri = URI.parse(@url)
source_uri = URI.parse(server_obj["url"].to_s)
if user_uri.host == source_uri.host
base_path = @url + source_uri.path
break
end
end
end
end

json_obj["paths"].as_h.each do |path, path_obj|
path_obj.as_h.each do |method, method_obj|
params_query = [] of Param
Expand Down Expand Up @@ -62,6 +76,20 @@ class AnalyzerOAS3 < Analyzer
content = File.read(oas3_yaml, encoding: "utf-8", invalid: :skip)
yaml_obj = YAML.parse(content)
base_path = @url
servers = yaml_obj["servers"]
if !servers.nil?
servers.as_a.each do |server_obj|
if server_obj["url"].to_s.starts_with?("http")
user_uri = URI.parse(@url)
source_uri = URI.parse(server_obj["url"].to_s)
if user_uri.host == source_uri.host
base_path = @url + source_uri.path
break
end
end
end
end

yaml_obj["paths"].as_h.each do |path, path_obj|
path_obj.as_h.each do |method, method_obj|
params_query = [] of Param
Expand Down

0 comments on commit 7f3a1ab

Please sign in to comment.