@@ -4,8 +4,8 @@ module GrapeSwagger
4
4
module DocMethods
5
5
class BuildModelDefinition
6
6
class << self
7
- def build ( model , properties , required )
8
- definition = { type : 'object' , properties : properties }
7
+ def build ( model , properties , required , other_def_properties = { } )
8
+ definition = { type : 'object' , properties : properties } . merge ( other_def_properties )
9
9
10
10
if required . nil?
11
11
required_attrs = required_attributes ( model )
@@ -17,6 +17,57 @@ def build(model, properties, required)
17
17
definition
18
18
end
19
19
20
+ def parse_params_from_model ( parsed_response , model , model_name )
21
+ if parsed_response . is_a? ( Hash ) && parsed_response . keys . first == :allOf
22
+ refs_or_models = parsed_response [ :allOf ]
23
+ parsed = parse_refs_and_models ( refs_or_models , model )
24
+
25
+ {
26
+ allOf : parsed
27
+ }
28
+ else
29
+ properties , required = parsed_response
30
+ unless properties &.any?
31
+ raise GrapeSwagger ::Errors ::SwaggerSpec ,
32
+ "Empty model #{ model_name } , swagger 2.0 doesn't support empty definitions."
33
+ end
34
+ properties , other_def_properties = parse_properties ( properties )
35
+
36
+ build (
37
+ model , properties , required , other_def_properties
38
+ )
39
+ end
40
+ end
41
+
42
+ def parse_properties ( properties )
43
+ other_properties = { }
44
+
45
+ discriminator_key , discriminator_value =
46
+ properties . find do |_key , value |
47
+ value [ :documentation ] . try ( :[] , :is_discriminator )
48
+ end
49
+
50
+ if discriminator_key
51
+ discriminator_value . delete ( :documentation )
52
+ properties [ discriminator_key ] = discriminator_value
53
+
54
+ other_properties [ :discriminator ] = discriminator_key
55
+ end
56
+
57
+ [ properties , other_properties ]
58
+ end
59
+
60
+ def parse_refs_and_models ( refs_or_models , model )
61
+ refs_or_models . map do |ref_or_models |
62
+ if ref_or_models . is_a? ( Hash ) && ref_or_models . keys . first == '$ref'
63
+ ref_or_models
64
+ else
65
+ properties , required = ref_or_models
66
+ GrapeSwagger ::DocMethods ::BuildModelDefinition . build ( model , properties , required )
67
+ end
68
+ end
69
+ end
70
+
20
71
private
21
72
22
73
def required_attributes ( model )
0 commit comments