Skip to content

Commit

Permalink
(#15) Improve Analyzer of OAS3
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 18, 2023
1 parent ac9b8fc commit dbaf62f
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/analyzer/analyzers/analyzer_oas3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,31 @@ class AnalyzerOAS3 < Analyzer
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params_query << param
elsif param_obj["in"] == "body"
param = Param.new(param_name, "", "json")
params_body << param
elsif param_obj["in"] == "formData"
param = Param.new(param_name, "", "form")
params_body << param
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_obj|

Check warning on line 33 in src/analyzer/analyzers/analyzer_oas3.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UnusedArgument

Unused argument `param_obj`. If it's necessary, use `_` as an argument name to indicate that it won't be used.
Raw output
> content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|
                                                                ^
param = Param.new(param_name, "", "json")
params_body << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|

Check warning on line 38 in src/analyzer/analyzers/analyzer_oas3.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UnusedArgument

Unused argument `param_obj`. If it's necessary, use `_` as an argument name to indicate that it won't be used.
Raw output
> content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|
                                                                ^
param = Param.new(param_name, "", "form")
params_body << param
end
end
end
end

if params_query.size > 0 && params_body.size > 0
@result << Endpoint.new(base_path + path, method.upcase, params_query + params_body)
elsif params_query.size > 0
@result << Endpoint.new(base_path + path, method.upcase, params_query)
elsif params_body.size > 0
@result << Endpoint.new(base_path + path, method.upcase, params_body)
else
@result << Endpoint.new(base_path + path, method.upcase)
Expand All @@ -56,14 +73,31 @@ class AnalyzerOAS3 < Analyzer
if param_obj["in"] == "query"
param = Param.new(param_name, "", "query")
params_query << param
elsif param_obj["in"] == "body"
param = Param.new(param_name, "", "json")
params_body << param
elsif param_obj["in"] == "formData"
param = Param.new(param_name, "", "form")
params_body << param
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_obj|

Check warning on line 83 in src/analyzer/analyzers/analyzer_oas3.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UnusedArgument

Unused argument `param_obj`. If it's necessary, use `_` as an argument name to indicate that it won't be used.
Raw output
> content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|
                                                                ^
param = Param.new(param_name.to_s, "", "json")
params_body << param
end
elsif content_type == "application/x-www-form-urlencoded"
content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|

Check warning on line 88 in src/analyzer/analyzers/analyzer_oas3.cr

View workflow job for this annotation

GitHub Actions / Ameba

Lint/UnusedArgument

Unused argument `param_obj`. If it's necessary, use `_` as an argument name to indicate that it won't be used.
Raw output
> content_obj["schema"]["properties"].as_h.each do |param_name, param_obj|
                                                                ^
param = Param.new(param_name.to_s, "", "form")
params_body << param
end
end
end
end

if params_query.size > 0 && params_body.size > 0
@result << Endpoint.new(base_path + path.to_s, method.to_s.upcase, params_query + params_body)
elsif params_query.size > 0
@result << Endpoint.new(base_path + path.to_s, method.to_s.upcase, params_query)
elsif params_body.size > 0
@result << Endpoint.new(base_path + path.to_s, method.to_s.upcase, params_body)
else
@result << Endpoint.new(base_path + path.to_s, method.to_s.upcase)
Expand Down

0 comments on commit dbaf62f

Please sign in to comment.