24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/apiture/swagger/parser.rb', line 24
def build_specification(json)
specification = build_node(Specification, json)
specification.info = build_node(Info, json['info'])
specification.external_docs = build_node(ExternalDocs, json['externalDocs'])
specification.schemes = json['schemes']
specification.produces = json['produces'] || []
specification.consumes = json['consumes'] || []
build_security_definition_hash(specification, json)
build_security_node_list(specification, json)
specification.paths = build_node_hash(Path, json, 'paths') do |path, path_json|
trace = [path.id]
[:get, :put, :post, :delete, :options, :head, :patch].each do |method|
if op_json = path_json[method.to_s]
trace.unshift(method)
op = build_node(Operation, op_json, constructor_args: [method], trace: trace)
op.external_docs = build_node(ExternalDocs, op_json['externalDocs'], trace: trace)
op.parameters = build_node_list(Parameter, op_json, 'parameters', trace: trace) do |param, param_json|
trace.unshift(param_json["name"])
if param_json["schema"] && param_json["schema"].kind_of?(Hash)
trace.unshift("schema")
schema_json = param_json["schema"]
param.schema = build_node(Definition, schema_json, trace: trace)
build_schema_content(param.schema, schema_json)
trace.shift
end
trace.shift
end
build_security_definition_hash(op, json)
build_security_node_list(op, op_json)
path.send("#{method}=".to_sym, op)
trace.shift
end
end
trace.shift
end
specification.definitions = build_node_hash(Definition, json, 'definitions') do |definition, def_json|
build_schema_content(definition, def_json)
end
specification
end
|