Skip to content

Commit 929d1ba

Browse files
protoc-gen-swagger: correctly type struct.proto types
1 parent 86e5755 commit 929d1ba

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

protoc-gen-swagger/genswagger/template.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ var wktSchemas = map[string]schemaCore{
6262
Format: "boolean",
6363
},
6464
".google.protobuf.Empty": schemaCore{},
65+
".google.protobuf.Struct": schemaCore{
66+
Type: "object",
67+
},
68+
".google.protobuf.Value": schemaCore{
69+
Type: "object",
70+
},
71+
".google.protobuf.ListValue": schemaCore{
72+
Type: "array",
73+
Items: (*swaggerItemsObject)(&schemaCore{
74+
Type: "object",
75+
}),
76+
},
77+
".google.protobuf.NullValue": schemaCore{
78+
Type: "string",
79+
},
6580
}
6681

6782
func listEnumNames(enum *descriptor.Enum) (names []string) {

protoc-gen-swagger/genswagger/template_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,61 @@ func TestSchemaOfField(t *testing.T) {
11931193
Format: "boolean",
11941194
},
11951195
},
1196+
{
1197+
field: &descriptor.Field{
1198+
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
1199+
Name: proto.String("wrapped_field"),
1200+
TypeName: proto.String(".google.protobuf.Struct"),
1201+
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
1202+
},
1203+
},
1204+
refs: make(refMap),
1205+
expected: schemaCore{
1206+
Type: "object",
1207+
},
1208+
},
1209+
{
1210+
field: &descriptor.Field{
1211+
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
1212+
Name: proto.String("wrapped_field"),
1213+
TypeName: proto.String(".google.protobuf.Value"),
1214+
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
1215+
},
1216+
},
1217+
refs: make(refMap),
1218+
expected: schemaCore{
1219+
Type: "object",
1220+
},
1221+
},
1222+
{
1223+
field: &descriptor.Field{
1224+
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
1225+
Name: proto.String("wrapped_field"),
1226+
TypeName: proto.String(".google.protobuf.ListValue"),
1227+
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
1228+
},
1229+
},
1230+
refs: make(refMap),
1231+
expected: schemaCore{
1232+
Type: "array",
1233+
Items: (*swaggerItemsObject)(&schemaCore{
1234+
Type: "object",
1235+
}),
1236+
},
1237+
},
1238+
{
1239+
field: &descriptor.Field{
1240+
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
1241+
Name: proto.String("wrapped_field"),
1242+
TypeName: proto.String(".google.protobuf.NullValue"),
1243+
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
1244+
},
1245+
},
1246+
refs: make(refMap),
1247+
expected: schemaCore{
1248+
Type: "string",
1249+
},
1250+
},
11961251
{
11971252
field: &descriptor.Field{
11981253
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{

0 commit comments

Comments
 (0)