Skip to content

Commit

Permalink
(#25) Refactor JSON handling and error handling for method_obj in oas3
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 19, 2023
1 parent 7cfbd7d commit 04e8181
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions src/analyzer/analyzers/analyzer_oas3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,32 @@ class AnalyzerOAS3 < Analyzer
path_obj.as_h.each do |method, method_obj|
params = [] of Param

if method_obj.as_h.has_key?("parameters")
method_obj["parameters"].as_a.each do |param_obj|
param_name = param_obj["name"].to_s
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params << param
elsif param_obj["in"] == "header"
param = Param.new(param_name, "", "header")
params << param
if method_obj.is_a?(JSON::Any) && method_obj.is_a?(Hash(String, JSON::Any))
if method_obj.as_h.has_key?("parameters")
method_obj["parameters"].as_a.each do |param_obj|
param_name = param_obj["name"].to_s
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params << param
elsif param_obj["in"] == "header"
param = Param.new(param_name, "", "header")
params << param
end
end
end
end

if method_obj.as_h.has_key?("requestBody")
method_obj["requestBody"]["content"].as_h.each do |content_type, content_obj|
if content_type == "application/json"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name, "", "json")
params << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name, "", "form")
params << param
if method_obj.as_h.has_key?("requestBody")
method_obj["requestBody"]["content"].as_h.each do |content_type, content_obj|
if content_type == "application/json"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name, "", "json")
params << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name, "", "form")
params << param
end
end
end
end
Expand Down Expand Up @@ -86,30 +88,32 @@ class AnalyzerOAS3 < Analyzer
path_obj.as_h.each do |method, method_obj|
params = [] of Param

if method_obj.as_h.has_key?("parameters")
method_obj["parameters"].as_a.each do |param_obj|
param_name = param_obj["name"].to_s
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params << param
elsif param_obj["in"] == "header"
param = Param.new(param_name, "", "header")
params << param
if method_obj.is_a?(YAML::Any) && method_obj.is_a?(Hash(String, YAML::Any))
if method_obj.as_h.has_key?("parameters")
method_obj["parameters"].as_a.each do |param_obj|
param_name = param_obj["name"].to_s
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params << param
elsif param_obj["in"] == "header"
param = Param.new(param_name, "", "header")
params << param
end
end
end
end

if method_obj.as_h.has_key?("requestBody")
method_obj["requestBody"]["content"].as_h.each do |content_type, content_obj|
if content_type == "application/json"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name.to_s, "", "json")
params << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name.to_s, "", "form")
params << param
if method_obj.as_h.has_key?("requestBody")
method_obj["requestBody"]["content"].as_h.each do |content_type, content_obj|
if content_type == "application/json"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name.to_s, "", "json")
params << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, _|
param = Param.new(param_name.to_s, "", "form")
params << param
end
end
end
end
Expand Down

0 comments on commit 04e8181

Please sign in to comment.