From 7f3a1ab4fe607c92814387e46f2f7f3b8c749235 Mon Sep 17 00:00:00 2001 From: hahwul Date: Fri, 18 Aug 2023 19:15:52 +0900 Subject: [PATCH] (#15) Add servers field check --- src/analyzer/analyzers/analyzer_oas3.cr | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/analyzer/analyzers/analyzer_oas3.cr b/src/analyzer/analyzers/analyzer_oas3.cr index a1115411..31098020 100644 --- a/src/analyzer/analyzers/analyzer_oas3.cr +++ b/src/analyzer/analyzers/analyzer_oas3.cr @@ -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 @@ -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