4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/swagger/shell/doc_loader.rb', line 4
def load(url)
api_docs = JSON.parse(Faraday.new(url: url).get.body)
swagger_version = api_docs["swaggerVersion"] || api_docs["swagger"]
ApiStruct.new(api_docs["basePath"]).tap do |root_api|
if swagger_version == "1.2"
api_docs["apis"].each do |api|
api_body = JSON.parse Faraday.new(url: url + api["path"].gsub("{format}", :json.to_s)).get.body
api_body["apis"].each do |api2|
path = api2["path"].gsub(/^#{Swagger::Shell.config_api.ignore_top_url}/, "")
path_keys = path.split("/").reject {|s| s == "" }.tap {|p| p.last.gsub!(".json", "") }
info = api2["operations"].first
api_info = OpenStruct.new(
summary: info["summary"],
notes: info["notes"],
parameters: info["parameters"],
response_messages: info["responseMessages"],
nickname: info["nickname"],
)
root_api.add_api(path_keys, info["method"], api_info)
end
end
elsif swagger_version == "2.0"
api_docs["paths"].each do |path, methods|
methods.each do |method, api_info|
path_keys = path.split("/").reject {|s| s == "" } root_api.add_api(path_keys, method) end
end
end
end
end
|