@@ -4,8 +4,8 @@ module GrapeSwagger
44 module DocMethods
55 class BuildModelDefinition
66 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 )
99
1010 if required . nil?
1111 required_attrs = required_attributes ( model )
@@ -17,6 +17,57 @@ def build(model, properties, required)
1717 definition
1818 end
1919
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+
2071 private
2172
2273 def required_attributes ( model )
0 commit comments