@@ -37,8 +37,7 @@ func makeMessageFields(model *api.API, messageID string, schema *schema) ([]*api
3737
3838func makeField (model * api.API , messageID string , input * property ) (* api.Field , error ) {
3939 if input .Schema .Type == "array" {
40- // TODO(#2266) - handle array fields
41- return nil , nil
40+ return makeArrayField (model , messageID , input )
4241 }
4342 if input .Schema .AdditionalProperties != nil {
4443 // TODO(#2283) - handle map fields
@@ -51,8 +50,28 @@ func makeField(model *api.API, messageID string, input *property) (*api.Field, e
5150 return makeScalarField (model , messageID , input )
5251}
5352
53+ func makeArrayField (model * api.API , messageID string , input * property ) (* api.Field , error ) {
54+ if input .Schema .ItemSchema .Type == "object" && input .Schema .ItemSchema .Properties != nil {
55+ // TODO(#2265) - handle inline object...
56+ return nil , nil
57+ }
58+ typez , typezID , err := scalarType (model , messageID , input .Name , input .Schema .ItemSchema )
59+ if err != nil {
60+ return nil , err
61+ }
62+ return & api.Field {
63+ Name : input .Name ,
64+ JSONName : input .Name , // OpenAPI field names are always camelCase
65+ Documentation : input .Schema .Description ,
66+ Typez : typez ,
67+ TypezID : typezID ,
68+ Repeated : true ,
69+ // TODO(#2268) - deprecated fields?
70+ }, nil
71+ }
72+
5473func makeScalarField (model * api.API , messageID string , input * property ) (* api.Field , error ) {
55- typez , typezID , err := scalarType (model , messageID , input )
74+ typez , typezID , err := scalarType (model , messageID , input . Name , input . Schema )
5675 if err != nil {
5776 return nil , err
5877 }
@@ -68,30 +87,30 @@ func makeScalarField(model *api.API, messageID string, input *property) (*api.Fi
6887 }, nil
6988}
7089
71- func scalarType (model * api.API , messageID string , input * property ) (api.Typez , string , error ) {
72- if input .Schema . Type == "" && input . Schema .Ref != "" {
73- typezID := fmt .Sprintf (".%s.%s" , model .PackageName , input .Schema . Ref )
90+ func scalarType (model * api.API , messageID , name string , input * schema ) (api.Typez , string , error ) {
91+ if input .Type == "" && input .Ref != "" {
92+ typezID := fmt .Sprintf (".%s.%s" , model .PackageName , input .Ref )
7493 return api .MESSAGE_TYPE , typezID , nil
7594 }
76- switch input .Schema . Type {
95+ switch input .Type {
7796 case "boolean" :
7897 return api .BOOL_TYPE , "bool" , nil
7998 case "integer" :
80- return scalarTypeForIntegerFormats (messageID , input )
99+ return scalarTypeForIntegerFormats (messageID , name , input )
81100 case "number" :
82- return scalarTypeForNumberFormats (messageID , input )
101+ return scalarTypeForNumberFormats (messageID , name , input )
83102 case "string" :
84- return scalarTypeForStringFormats (messageID , input )
103+ return scalarTypeForStringFormats (messageID , name , input )
85104 case "any" :
86- return scalarTypeForAny (messageID , input )
105+ return scalarTypeForAny (messageID , name , input )
87106 case "object" :
88- return scalarTypeForObject (messageID , input )
107+ return scalarTypeForObject (messageID , name , input )
89108 }
90- return unknownFormat ("scalar" , messageID , input )
109+ return unknownFormat ("scalar" , messageID , name , input )
91110}
92111
93- func scalarTypeForIntegerFormats (messageID string , input * property ) (api.Typez , string , error ) {
94- switch input .Schema . Format {
112+ func scalarTypeForIntegerFormats (messageID , name string , input * schema ) (api.Typez , string , error ) {
113+ switch input .Format {
95114 case "int32" :
96115 return api .INT32_TYPE , "int32" , nil
97116 case "uint32" :
@@ -101,21 +120,21 @@ func scalarTypeForIntegerFormats(messageID string, input *property) (api.Typez,
101120 case "uint64" :
102121 return api .UINT64_TYPE , "uint64" , nil
103122 }
104- return unknownFormat ("integer" , messageID , input )
123+ return unknownFormat ("integer" , messageID , name , input )
105124}
106125
107- func scalarTypeForNumberFormats (messageID string , input * property ) (api.Typez , string , error ) {
108- switch input .Schema . Format {
126+ func scalarTypeForNumberFormats (messageID , name string , input * schema ) (api.Typez , string , error ) {
127+ switch input .Format {
109128 case "float" :
110129 return api .FLOAT_TYPE , "float" , nil
111130 case "double" :
112131 return api .DOUBLE_TYPE , "double" , nil
113132 }
114- return unknownFormat ("number" , messageID , input )
133+ return unknownFormat ("number" , messageID , name , input )
115134}
116135
117- func scalarTypeForStringFormats (messageID string , input * property ) (api.Typez , string , error ) {
118- switch input .Schema . Format {
136+ func scalarTypeForStringFormats (messageID , name string , input * schema ) (api.Typez , string , error ) {
137+ switch input .Format {
119138 case "" :
120139 return api .STRING_TYPE , "string" , nil
121140 case "byte" :
@@ -133,27 +152,27 @@ func scalarTypeForStringFormats(messageID string, input *property) (api.Typez, s
133152 case "uint64" :
134153 return api .UINT64_TYPE , "uint64" , nil
135154 }
136- return unknownFormat ("string" , messageID , input )
155+ return unknownFormat ("string" , messageID , name , input )
137156}
138157
139- func scalarTypeForAny (messageID string , input * property ) (api.Typez , string , error ) {
140- switch input .Schema . Format {
158+ func scalarTypeForAny (messageID , name string , input * schema ) (api.Typez , string , error ) {
159+ switch input .Format {
141160 case "google.protobuf.Value" :
142161 return api .MESSAGE_TYPE , ".google.protobuf.Value" , nil
143162 }
144- return unknownFormat ("any" , messageID , input )
163+ return unknownFormat ("any" , messageID , name , input )
145164}
146165
147- func scalarTypeForObject (messageID string , input * property ) (api.Typez , string , error ) {
148- switch input .Schema . Format {
166+ func scalarTypeForObject (messageID , name string , input * schema ) (api.Typez , string , error ) {
167+ switch input .Format {
149168 case "google.protobuf.Struct" :
150169 return api .MESSAGE_TYPE , ".google.protobuf.Struct" , nil
151170 case "google.protobuf.Any" :
152171 return api .MESSAGE_TYPE , ".google.protobuf.Any" , nil
153172 }
154- return unknownFormat ("object" , messageID , input )
173+ return unknownFormat ("object" , messageID , name , input )
155174}
156175
157- func unknownFormat (baseType , messageID string , input * property ) (api.Typez , string , error ) {
158- return 0 , "" , fmt .Errorf ("unknown %s format (%s) for field %s.%s" , baseType , input .Schema . Format , messageID , input . Name )
176+ func unknownFormat (baseType , messageID , name string , input * schema ) (api.Typez , string , error ) {
177+ return 0 , "" , fmt .Errorf ("unknown %s format (%s) for field %s.%s" , baseType , input .Format , messageID , name )
159178}
0 commit comments