diff --git a/examples/examplepb/a_bit_of_everything.pb.go b/examples/examplepb/a_bit_of_everything.pb.go index 4ba8752c92e..ae0f419bf2d 100644 --- a/examples/examplepb/a_bit_of_everything.pb.go +++ b/examples/examplepb/a_bit_of_everything.pb.go @@ -88,8 +88,10 @@ type ABitOfEverything struct { // Types that are valid to be assigned to OneofValue: // *ABitOfEverything_OneofEmpty // *ABitOfEverything_OneofString - OneofValue isABitOfEverything_OneofValue `protobuf_oneof:"oneof_value"` - MapValue map[string]NumericEnum `protobuf:"bytes,22,rep,name=map_value,json=mapValue" json:"map_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=gengo.grpc.gateway.examples.examplepb.NumericEnum"` + OneofValue isABitOfEverything_OneofValue `protobuf_oneof:"oneof_value"` + MapValue map[string]NumericEnum `protobuf:"bytes,22,rep,name=map_value,json=mapValue" json:"map_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=gengo.grpc.gateway.examples.examplepb.NumericEnum"` + MappedStringValue map[string]string `protobuf:"bytes,23,rep,name=mapped_string_value,json=mappedStringValue" json:"mapped_string_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + MappedNestedValue map[string]*ABitOfEverything_Nested `protobuf:"bytes,24,rep,name=mapped_nested_value,json=mappedNestedValue" json:"mapped_nested_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` } func (m *ABitOfEverything) Reset() { *m = ABitOfEverything{} } @@ -146,6 +148,20 @@ func (m *ABitOfEverything) GetMapValue() map[string]NumericEnum { return nil } +func (m *ABitOfEverything) GetMappedStringValue() map[string]string { + if m != nil { + return m.MappedStringValue + } + return nil +} + +func (m *ABitOfEverything) GetMappedNestedValue() map[string]*ABitOfEverything_Nested { + if m != nil { + return m.MappedNestedValue + } + return nil +} + // XXX_OneofFuncs is for the internal use of the proto package. func (*ABitOfEverything) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { return _ABitOfEverything_OneofMarshaler, _ABitOfEverything_OneofUnmarshaler, _ABitOfEverything_OneofSizer, []interface{}{ @@ -673,70 +689,75 @@ var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{ } var fileDescriptor1 = []byte{ - // 1033 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x57, 0xdd, 0x6e, 0x1b, 0x45, - 0x18, 0xed, 0xda, 0x89, 0x63, 0x7f, 0x1b, 0x3b, 0xee, 0x94, 0x16, 0x63, 0x40, 0x49, 0x97, 0x16, - 0x82, 0xa9, 0x76, 0xdb, 0x0d, 0x02, 0x14, 0x09, 0xa4, 0x9a, 0x1a, 0x8a, 0x94, 0x26, 0x62, 0x43, - 0x83, 0x14, 0x09, 0x59, 0x6b, 0x7b, 0xe2, 0xae, 0x62, 0xef, 0xac, 0xf6, 0xc7, 0xd4, 0xb2, 0xc2, - 0x45, 0xb9, 0x41, 0xe2, 0x02, 0x09, 0x1e, 0x80, 0x6b, 0x90, 0xe0, 0x45, 0x7a, 0xc9, 0x2b, 0xf0, - 0x20, 0x7c, 0x33, 0xb3, 0xbb, 0xac, 0x5d, 0x84, 0xcd, 0x56, 0x2a, 0x77, 0x3b, 0x33, 0x67, 0xce, - 0x9c, 0xef, 0xe7, 0xcc, 0xd8, 0x70, 0x8b, 0x3e, 0xb6, 0xc7, 0xde, 0x88, 0x06, 0x46, 0xfc, 0xe1, - 0xf5, 0x0c, 0xbb, 0xdb, 0x73, 0xc2, 0x2e, 0x3b, 0xeb, 0xd2, 0x09, 0xf5, 0xa7, 0xe1, 0x23, 0xc7, - 0x1d, 0xea, 0x9e, 0xcf, 0x42, 0x46, 0x6e, 0x0e, 0xa9, 0x3b, 0x64, 0xfa, 0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e, 0x29, 0x01, 0x6f, 0x40, 0xf5, 0xcc, 0x79, 0x4c, 0x07, 0x29, 0x49, 0x19, 0x21, 0x25, - 0x6b, 0x33, 0x9e, 0x9c, 0x07, 0xa5, 0x3c, 0x15, 0x04, 0x6d, 0xc4, 0xa0, 0x84, 0xe9, 0x75, 0x80, - 0x1e, 0x63, 0xa3, 0x18, 0x01, 0x88, 0x28, 0x5b, 0x15, 0x3e, 0x93, 0x8a, 0x0d, 0x42, 0x1f, 0x53, - 0x15, 0x03, 0x54, 0x51, 0x05, 0x55, 0xce, 0xcd, 0xc5, 0x93, 0x9e, 0x52, 0x45, 0x48, 0x55, 0xc6, - 0x93, 0x1c, 0xf2, 0x39, 0x00, 0x75, 0xa3, 0x71, 0x0c, 0xa8, 0x21, 0xa0, 0x66, 0x9a, 0x2b, 0xd6, - 0xec, 0x30, 0x1a, 0x53, 0xdf, 0xe9, 0x77, 0x70, 0xbf, 0x55, 0xe1, 0x2c, 0x92, 0xf2, 0x26, 0xd4, - 0x82, 0xf9, 0xe8, 0xb6, 0x90, 0x76, 0xcb, 0xaa, 0x06, 0x73, 0xe1, 0xa5, 0xb0, 0x34, 0x53, 0x75, - 0x84, 0xd5, 0x13, 0x58, 0xa6, 0x26, 0x41, 0x36, 0x86, 0xcb, 0x08, 0xba, 0x8c, 0x61, 0x66, 0x62, - 0x88, 0x21, 0x29, 0x0f, 0x41, 0x08, 0x91, 0x90, 0x84, 0xc5, 0x84, 0xab, 0x3e, 0xf5, 0x28, 0xc6, - 0x32, 0xe8, 0xce, 0x65, 0xed, 0x0a, 0x76, 0x69, 0xc5, 0xba, 0x92, 0x2c, 0x1e, 0x67, 0xb2, 0x77, - 0x02, 0x2a, 0x73, 0x29, 0xf7, 0xe2, 0xd8, 0x0b, 0xa7, 0x8d, 0x97, 0x90, 0x55, 0x35, 0xf7, 0x56, - 0xcc, 0x4d, 0x87, 0xef, 0x79, 0x20, 0x3d, 0x74, 0xff, 0x92, 0x05, 0x82, 0x49, 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x6f, 0x2e, 0xed, 0x61, 0xfe, 0xeb, 0xe4, - 0x82, 0xfc, 0xac, 0xc0, 0xda, 0x81, 0x13, 0x84, 0x24, 0x4f, 0xd4, 0xf9, 0x65, 0xbe, 0x25, 0x64, - 0x5e, 0x27, 0xcb, 0xea, 0x7a, 0x5b, 0x21, 0xbf, 0x60, 0x9a, 0x1e, 0x7a, 0x83, 0x17, 0x5f, 0xd2, - 0x3b, 0x42, 0xe3, 0x3b, 0xcd, 0x15, 0x53, 0xc9, 0x5b, 0xf0, 0x1b, 0x28, 0xdd, 0xa3, 0x23, 0x8a, - 0x52, 0x9f, 0xa9, 0x68, 0x2e, 0x09, 0x71, 0x35, 0x5b, 0xab, 0x56, 0xf3, 0x29, 0x56, 0xb3, 0xd3, - 0x7f, 0xc4, 0x88, 0xfe, 0xaf, 0xa7, 0xa1, 0x34, 0x5d, 0x3e, 0xab, 0x89, 0xba, 0xff, 0x88, 0xd7, - 0xfa, 0x42, 0xd8, 0x57, 0xe4, 0xd6, 0x32, 0x61, 0x14, 0xd5, 0x18, 0x33, 0x79, 0x9d, 0x9c, 0xbe, - 0xa2, 0xd5, 0x8d, 0x89, 0x99, 0xe2, 0xf9, 0xda, 0xbe, 0x7c, 0x5c, 0x4e, 0x09, 0x79, 0x66, 0x89, - 0xf7, 0x66, 0x99, 0x1b, 0xfa, 0x85, 0x44, 0xb4, 0xb2, 0x81, 0x85, 0x6a, 0x6e, 0xe0, 0xdb, 0x4a, - 0x5b, 0x3d, 0xad, 0xa4, 0x95, 0xeb, 0x95, 0xc4, 0x3f, 0x83, 0xbd, 0xbf, 0x02, 0x00, 0x00, 0xff, - 0xff, 0x9e, 0x8d, 0xf0, 0x8e, 0xc7, 0x0c, 0x00, 0x00, + // 1110 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x57, 0x5f, 0x6f, 0x1b, 0x45, + 0x10, 0xef, 0xd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, 0xdf, 0xb2, 0x82, 0x83, 0x93, 0x76, + 0x2a, 0x0c, 0x63, 0x54, 0x08, 0x43, 0xab, 0x5f, 0x97, 0x36, 0xa5, 0xad, 0xb2, 0xc1, 0xbe, 0xf1, + 0x11, 0x2a, 0x3a, 0xc4, 0x0f, 0x48, 0xbf, 0x9e, 0xdb, 0xcc, 0x6f, 0xc9, 0xfa, 0x27, 0xea, 0x5c, + 0xba, 0xd5, 0x69, 0x72, 0x75, 0x9f, 0xb1, 0x18, 0x31, 0x1b, 0xde, 0x40, 0xf2, 0xc9, 0x90, 0x9a, + 0x41, 0x67, 0x64, 0x0e, 0x43, 0x52, 0xcf, 0x83, 0xcb, 0x9c, 0x81, 0x98, 0xe9, 0x28, 0xb2, 0xe0, + 0x9b, 0x68, 0xb9, 0x4f, 0xc3, 0xee, 0x90, 0xc4, 0x88, 0x02, 0x20, 0x24, 0x43, 0xe6, 0x36, 0x0e, + 0x01, 0x0e, 0xcb, 0x09, 0x3e, 0x78, 0x3f, 0x46, 0x2c, 0x01, 0x22, 0x6f, 0x20, 0x66, 0x4a, 0x39, + 0x42, 0x11, 0x51, 0x04, 0x44, 0xc1, 0x90, 0x43, 0x01, 0xc2, 0x39, 0xb6, 0xf5, 0x18, 0x71, 0x15, + 0x10, 0x4b, 0x8c, 0x63, 0x5b, 0xe7, 0x80, 0xb7, 0x50, 0xe5, 0xc4, 0x7a, 0x4a, 0xfa, 0x29, 0x49, + 0x09, 0x20, 0x45, 0x63, 0x39, 0x36, 0x66, 0x41, 0x29, 0x4f, 0x19, 0x40, 0x57, 0x63, 0x50, 0xc2, + 0xf4, 0x26, 0x42, 0x5d, 0x4a, 0x87, 0x31, 0x02, 0x01, 0xa2, 0x64, 0x94, 0x23, 0x4b, 0x2a, 0xd6, + 0x0f, 0x3c, 0x48, 0x55, 0x0c, 0x90, 0x59, 0x15, 0x64, 0x6e, 0xcb, 0xc4, 0x93, 0x7a, 0xa9, 0x00, + 0xa4, 0xc2, 0xe3, 0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0xa3, 0xdf, 0x8b, 0xea, 0x17, 0xfd, 0x98, 0x6e, 0xf1, 0x84, + 0xa9, 0x4c, 0xc7, 0x16, 0x7e, 0x7b, 0xe6, 0x1d, 0x8e, 0x7e, 0x6a, 0x9e, 0xe1, 0x9f, 0x25, 0x54, + 0xd8, 0xb3, 0xfc, 0x00, 0x2f, 0x12, 0xf5, 0xe2, 0x32, 0xdf, 0x61, 0x32, 0x6f, 0xe2, 0x59, 0x75, + 0xbd, 0x2b, 0xe1, 0x5f, 0x20, 0x4d, 0x8f, 0xdd, 0xfe, 0xab, 0x2f, 0xe9, 0x3d, 0xa6, 0xf1, 0xbd, + 0xc6, 0x9c, 0xa9, 0x8c, 0xae, 0xe0, 0x33, 0x54, 0xdc, 0x25, 0x43, 0x02, 0x52, 0xcf, 0x55, 0x74, + 0x21, 0x09, 0x71, 0x35, 0x9b, 0xf3, 0x56, 0xf3, 0x05, 0x54, 0xb3, 0xdd, 0x7b, 0x42, 0xb1, 0xfa, + 0x8f, 0xde, 0x40, 0x9a, 0xca, 0x5f, 0xa3, 0x44, 0xdd, 0xbf, 0xc4, 0x2b, 0x3d, 0x26, 0xec, 0x6b, + 0x7c, 0x67, 0x96, 0x30, 0x02, 0x6a, 0xb4, 0x09, 0x1f, 0x27, 0xc7, 0xaf, 0x29, 0x35, 0x6d, 0xa4, + 0xa7, 0xf8, 0x68, 0x6f, 0x87, 0x3f, 0x2e, 0xc7, 0x18, 0x9f, 0xdb, 0x8a, 0xee, 0x66, 0x29, 0x6a, + 0xe8, 0x57, 0x12, 0xd1, 0xdc, 0x0d, 0xcc, 0x54, 0x47, 0x0d, 0x7c, 0x57, 0x6a, 0xc9, 0xc7, 0xe5, + 0xb4, 0x72, 0xdd, 0x22, 0xfb, 0x9b, 0xb7, 0xfd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x49, 0xeb, + 0x23, 0xde, 0x94, 0x0e, 0x00, 0x00, } diff --git a/examples/examplepb/a_bit_of_everything.proto b/examples/examplepb/a_bit_of_everything.proto index c1a5a2ffa25..12f95322dbb 100644 --- a/examples/examplepb/a_bit_of_everything.proto +++ b/examples/examplepb/a_bit_of_everything.proto @@ -36,12 +36,14 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; - oneof oneof_value { EmptyMessage oneof_empty = 20; string oneof_string = 21; } + map map_value = 22; + map mapped_string_value = 23; + map mapped_nested_value = 24; } message EmptyMessage { diff --git a/examples/examplepb/streamless_everything.proto b/examples/examplepb/streamless_everything.proto index a6d2145d8ab..33458b28aab 100644 --- a/examples/examplepb/streamless_everything.proto +++ b/examples/examplepb/streamless_everything.proto @@ -35,6 +35,14 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; + oneof oneof_value { + EmptyMessage oneof_empty = 20; + string oneof_string = 21; + } + + map map_value = 22; + map mapped_string_value = 23; + map mapped_nested_value = 24; } message EmptyMessage { diff --git a/examples/examplepb/streamless_everything.swagger.json b/examples/examplepb/streamless_everything.swagger.json index 508508eb36e..dde159dc540 100644 --- a/examples/examplepb/streamless_everything.swagger.json +++ b/examples/examplepb/streamless_everything.swagger.json @@ -396,12 +396,38 @@ "type": "integer", "format": "int64" }, + "map_value": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/examplepbNumericEnum" + } + }, + "mapped_nested_value": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/ABitOfEverythingNested" + } + }, + "mapped_string_value": { + "type": "object", + "additionalProperties": { + "type": "string", + "format": "string" + } + }, "nested": { "type": "array", "items": { "$ref": "#/definitions/ABitOfEverythingNested" } }, + "oneof_empty": { + "$ref": "#/definitions/examplepbEmptyMessage" + }, + "oneof_string": { + "type": "string", + "format": "string" + }, "repeated_string_value": { "type": "array", "items": { diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index 3793d0e5578..412763e1e9f 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -50,129 +50,115 @@ func findNestedMessagesAndEnumerations(message *descriptor.Message, reg *descrip func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, reg *descriptor.Registry) { for _, msg := range messages { - object := swaggerSchemaObject{ - Type: "object", - Properties: map[string]swaggerSchemaObject{}, + if opt := msg.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry { + continue } - for _, field := range msg.Fields { - var fieldType, fieldFormat string - primitive := true - // Field type and format from http://swagger.io/specification/ in the - // "Data Types" table - switch field.FieldDescriptorProto.Type.String() { - case "TYPE_DOUBLE": - fieldType = "number" - fieldFormat = "double" - break - case "TYPE_FLOAT": - fieldType = "number" - fieldFormat = "float" - break - case "TYPE_INT64": - fieldType = "integer" - fieldFormat = "int64" - break - case "TYPE_UINT64": - fieldType = "integer" - fieldFormat = "int64" - break - case "TYPE_INT32": - fieldType = "integer" - fieldFormat = "int32" - break - case "TYPE_FIXED64": - fieldType = "integer" - fieldFormat = "int64" - break - case "TYPE_FIXED32": - fieldType = "integer" - fieldFormat = "int32" - break - case "TYPE_BOOL": - fieldType = "boolean" - fieldFormat = "boolean" - break - case "TYPE_STRING": - fieldType = "string" - fieldFormat = "string" - break - case "TYPE_GROUP": - // WTF is a group? is this sufficient? - primitive = false - break - case "TYPE_MESSAGE": - // Check in here if it is the special date/datetime proto and - // serialize as a primitive date object - primitive = false - fieldType = "" - fieldFormat = "" - break - case "TYPE_BYTES": - fieldType = "string" - fieldFormat = "byte" - break - case "TYPE_UINT32": - fieldType = "integer" - fieldFormat = "int64" - break - case "TYPE_ENUM": - primitive = false - fieldType = "" - fieldFormat = "" - break - case "TYPE_SFIXED32": - fieldType = "integer" - fieldFormat = "int32" - break - case "TYPE_SFIXED64": - fieldType = "integer" - fieldFormat = "int32" - break - case "TYPE_SINT32": - fieldType = "integer" - fieldFormat = "int32" - break - case "TYPE_SINT64": - fieldType = "integer" - fieldFormat = "int64" - break - default: - fieldType = field.FieldDescriptorProto.Type.String() - fieldFormat = "UNKNOWN" - } + schema := swaggerSchemaObject{ + schemaCore: schemaCore{ + Type: "object", + }, + Properties: make(map[string]swaggerSchemaObject), + } + for _, f := range msg.Fields { + schema.Properties[f.GetName()] = schemaOfField(f, reg) + } + d[fullyQualifiedNameToSwaggerName(msg.FQMN(), reg)] = schema + } +} - if primitive { - // If repeated render as an array of items. - if field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED { - object.Properties[field.GetName()] = swaggerSchemaObject{ - Type: "array", - Items: &swaggerItemsObject{ - Type: fieldType, - Format: fieldFormat, - }, - } - } else { - object.Properties[field.GetName()] = swaggerSchemaObject{ - Type: fieldType, - Format: fieldFormat, - } - } - } else { - if field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED { - object.Properties[field.GetName()] = swaggerSchemaObject{ - Type: "array", - Items: &swaggerItemsObject{ - Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(field.GetTypeName(), reg), - }, - } - } else { - object.Properties[field.GetName()] = swaggerSchemaObject{ - Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(field.GetTypeName(), reg), - } - } - } +// schemaOfField returns a swagger Schema Object for a protobuf field. +func schemaOfField(f *descriptor.Field, reg *descriptor.Registry) swaggerSchemaObject { + const ( + singular = 0 + array = 1 + object = 2 + ) + var ( + core schemaCore + aggregate int + ) + + fd := f.FieldDescriptorProto + if m, err := reg.LookupMsg("", f.GetTypeName()); err == nil { + if opt := m.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry { + fd = m.GetField()[1] + aggregate = object } - d[fullyQualifiedNameToSwaggerName(msg.FQMN(), reg)] = object + } + if fd.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED { + aggregate = array + } + + switch ft := fd.GetType(); ft { + case pbdescriptor.FieldDescriptorProto_TYPE_ENUM, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE, pbdescriptor.FieldDescriptorProto_TYPE_GROUP: + core = schemaCore{ + Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(fd.GetTypeName(), reg), + } + default: + ftype, format, ok := primitiveSchema(ft) + if ok { + core = schemaCore{Type: ftype, Format: format} + } else { + core = schemaCore{Type: ft.String(), Format: "UNKNOWN"} + } + } + switch aggregate { + case array: + return swaggerSchemaObject{ + schemaCore: schemaCore{ + Type: "array", + }, + Items: (*swaggerItemsObject)(&core), + } + case object: + return swaggerSchemaObject{ + schemaCore: schemaCore{ + Type: "object", + }, + AdditionalProperties: &swaggerSchemaObject{schemaCore: core}, + } + default: + return swaggerSchemaObject{schemaCore: core} + } +} + +// primitiveSchema returns a pair of "Type" and "Format" in JSON Schema for +// the given primitive field type. +// The last return parameter is true iff the field type is actually primitive. +func primitiveSchema(t pbdescriptor.FieldDescriptorProto_Type) (ftype, format string, ok bool) { + switch t { + case pbdescriptor.FieldDescriptorProto_TYPE_DOUBLE: + return "number", "double", true + case pbdescriptor.FieldDescriptorProto_TYPE_FLOAT: + return "number", "float", true + case pbdescriptor.FieldDescriptorProto_TYPE_INT64: + return "integer", "int64", true + case pbdescriptor.FieldDescriptorProto_TYPE_UINT64: + return "integer", "int64", true + case pbdescriptor.FieldDescriptorProto_TYPE_INT32: + return "integer", "int32", true + case pbdescriptor.FieldDescriptorProto_TYPE_FIXED64: + return "integer", "int64", true + case pbdescriptor.FieldDescriptorProto_TYPE_FIXED32: + return "integer", "int32", true + case pbdescriptor.FieldDescriptorProto_TYPE_BOOL: + return "boolean", "boolean", true + case pbdescriptor.FieldDescriptorProto_TYPE_STRING: + return "string", "string", true + case pbdescriptor.FieldDescriptorProto_TYPE_BYTES: + return "string", "byte", true + case pbdescriptor.FieldDescriptorProto_TYPE_UINT32: + return "integer", "int64", true + case pbdescriptor.FieldDescriptorProto_TYPE_SFIXED32: + return "integer", "int32", true + case pbdescriptor.FieldDescriptorProto_TYPE_SFIXED64: + return "integer", "int32", true + case pbdescriptor.FieldDescriptorProto_TYPE_SINT32: + return "integer", "int32", true + case pbdescriptor.FieldDescriptorProto_TYPE_SINT64: + return "integer", "int64", true + default: + return "", "", false } } @@ -190,7 +176,9 @@ func renderEnumerationsAsDefinition(enums enumMap, d swaggerDefinitionsObject, r } d[fullyQualifiedNameToSwaggerName(enum.FQEN(), reg)] = swaggerSchemaObject{ - Type: "string", + schemaCore: schemaCore{ + Type: "string", + }, Enum: enumNames, Default: defaultValue, } @@ -316,79 +304,18 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re for _, parameter := range b.PathParams { var paramType, paramFormat string - switch parameter.Target.FieldDescriptorProto.Type.String() { - case "TYPE_DOUBLE": - paramType = "number" - paramFormat = "double" - break - case "TYPE_FLOAT": - paramType = "number" - paramFormat = "float" - break - case "TYPE_INT64": - paramType = "integer" - paramFormat = "int64" - break - case "TYPE_UINT64": - paramType = "integer" - paramFormat = "int64" - break - case "TYPE_INT32": - paramType = "integer" - paramFormat = "int32" - break - case "TYPE_FIXED64": - paramType = "integer" - paramFormat = "int64" - break - case "TYPE_FIXED32": - paramType = "integer" - paramFormat = "int32" - break - case "TYPE_BOOL": - paramType = "boolean" - paramFormat = "boolean" - break - case "TYPE_STRING": - paramType = "string" - paramFormat = "string" - break - case "TYPE_GROUP": - return fmt.Errorf("Groups are not allowed in the path for a HTTP RPC. Please use a primitive type instead (string, int64, etc)") - case "TYPE_MESSAGE": - return fmt.Errorf("Groups are not allowed in the path for a HTTP RPC. Please use a primitive type instead (string, int64, etc)") - case "TYPE_BYTES": - paramType = "string" - paramFormat = "byte" - break - case "TYPE_UINT32": - paramType = "integer" - paramFormat = "int64" - break - case "TYPE_ENUM": + switch pt := parameter.Target.GetType(); pt { + case pbdescriptor.FieldDescriptorProto_TYPE_GROUP, pbdescriptor.FieldDescriptorProto_TYPE_MESSAGE: + return fmt.Errorf("only primitive types are allowed in path parameters") + case pbdescriptor.FieldDescriptorProto_TYPE_ENUM: paramType = fullyQualifiedNameToSwaggerName(parameter.Target.GetTypeName(), reg) paramFormat = "" - break - case "TYPE_SFIXED32": - paramType = "integer" - paramFormat = "int32" - break - case "TYPE_SFIXED64": - paramType = "integer" - paramFormat = "int32" - break - case "TYPE_SINT32": - paramType = "integer" - paramFormat = "int32" - break - case "TYPE_SINT64": - paramType = "integer" - paramFormat = "int64" - break default: - paramType = parameter.Target.FieldDescriptorProto.Type.String() - return fmt.Errorf("Detected field type of '" + paramType + "' which is unknown. Please use a primitive type (Ex: string, int64)") - + var ok bool + paramType, paramFormat, ok = primitiveSchema(pt) + if !ok { + return fmt.Errorf("unknown field type %v", pt) + } } parameters = append(parameters, swaggerParameterObject{ @@ -407,7 +334,9 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re In: "body", Required: true, Schema: &swaggerSchemaObject{ - Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)), + schemaCore: schemaCore{ + Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)), + }, }, }) } @@ -425,7 +354,9 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re "default": swaggerResponseObject{ Description: "Description", Schema: swaggerSchemaObject{ - Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)), + schemaCore: schemaCore{ + Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)), + }, }, }, }, diff --git a/protoc-gen-swagger/genswagger/types.go b/protoc-gen-swagger/genswagger/types.go index fd441683b1b..ba7c0fde490 100644 --- a/protoc-gen-swagger/genswagger/types.go +++ b/protoc-gen-swagger/genswagger/types.go @@ -69,13 +69,16 @@ type swaggerParameterObject struct { Schema *swaggerSchemaObject `json:"schema,omitempty"` } +// core part of schema, which is common to itemsObject and schemaObject. // http://swagger.io/specification/#itemsObject -type swaggerItemsObject struct { +type schemaCore struct { Type string `json:"type,omitempty"` Format string `json:"format,omitempty"` Ref string `json:"$ref,omitempty"` } +type swaggerItemsObject schemaCore + // http://swagger.io/specification/#responsesObject type swaggerResponsesObject map[string]swaggerResponseObject @@ -87,12 +90,11 @@ type swaggerResponseObject struct { // http://swagger.io/specification/#schemaObject type swaggerSchemaObject struct { - Ref string `json:"$ref,omitempty"` - Type string `json:"type,omitempty"` - Format string `json:"format,omitempty"` + schemaCore // Properties can be recursively defined - Properties map[string]swaggerSchemaObject `json:"properties,omitempty"` - Items *swaggerItemsObject `json:"items,omitempty"` + Properties map[string]swaggerSchemaObject `json:"properties,omitempty"` + AdditionalProperties *swaggerSchemaObject `json:"additionalProperties,omitempty"` + Items *swaggerItemsObject `json:"items,omitempty"` // If the item is an enumeration include a list of all the *NAMES* of the // enum values. I'm not sure how well this will work but assuming all enums