Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-swagger: support all well-known wrapper types #695

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 54 additions & 27 deletions examples/proto/examplepb/wrappers.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/proto/examplepb/wrappers.proto
Expand Up @@ -12,6 +12,9 @@ message Wrappers {
google.protobuf.FloatValue float_value = 4;
google.protobuf.DoubleValue double_value = 5;
google.protobuf.BoolValue bool_value = 6;
google.protobuf.UInt32Value uint32_value = 7;
google.protobuf.UInt64Value uint64_value = 8;
google.protobuf.BytesValue bytes_value = 9;
}

service WrappersService {
Expand Down
14 changes: 13 additions & 1 deletion examples/proto/examplepb/wrappers.swagger.json
Expand Up @@ -54,7 +54,7 @@
"format": "int32"
},
"int64_value": {
"type": "integer",
"type": "string",
"format": "int64"
},
"float_value": {
Expand All @@ -68,6 +68,18 @@
"bool_value": {
"type": "boolean",
"format": "boolean"
},
"uint32_value": {
"type": "integer",
"format": "int64"
},
"uint64_value": {
"type": "string",
"format": "uint64"
},
"bytes_value": {
"type": "string",
"format": "byte"
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion protoc-gen-swagger/genswagger/template.go
Expand Up @@ -26,14 +26,26 @@ var wktSchemas = map[string]schemaCore{
".google.protobuf.StringValue": schemaCore{
Type: "string",
},
".google.protobuf.BytesValue": schemaCore{
Type: "string",
Format: "byte",
},
".google.protobuf.Int32Value": schemaCore{
Type: "integer",
Format: "int32",
},
".google.protobuf.Int64Value": schemaCore{
".google.protobuf.UInt32Value": schemaCore{
Type: "integer",
Format: "int64",
},
".google.protobuf.Int64Value": schemaCore{
Type: "string",
Format: "int64",
},
".google.protobuf.UInt64Value": schemaCore{
Type: "string",
Format: "uint64",
},
".google.protobuf.FloatValue": schemaCore{
Type: "number",
Format: "float",
Expand Down Expand Up @@ -201,10 +213,16 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject,
continue
case ".google.protobuf.StringValue":
continue
case ".google.protobuf.BytesValue":
continue
case ".google.protobuf.Int32Value":
continue
case ".google.protobuf.UInt32Value":
continue
case ".google.protobuf.Int64Value":
continue
case ".google.protobuf.UInt64Value":
continue
case ".google.protobuf.FloatValue":
continue
case ".google.protobuf.DoubleValue":
Expand Down
112 changes: 112 additions & 0 deletions protoc-gen-swagger/genswagger/template_test.go
Expand Up @@ -836,6 +836,118 @@ func TestSchemaOfField(t *testing.T) {
},
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.BytesValue"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "string",
Format: "bytes",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.Int32Value"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "integer",
Format: "int32",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.UInt32Value"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "integer",
Format: "int64",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.Int64Value"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "string",
Format: "int64",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.UInt64Value"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "string",
Format: "uint64",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.FloatValue"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "number",
Format: "float",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.DoubleValue"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "number",
Format: "double",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Name: proto.String("wrapped_field"),
TypeName: proto.String(".google.protobuf.BoolValue"),
Type: protodescriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum(),
},
},
refs: make(refMap),
expected: schemaCore{
Type: "boolean",
Format: "boolean",
},
},
{
field: &descriptor.Field{
FieldDescriptorProto: &protodescriptor.FieldDescriptorProto{
Expand Down