Skip to content

Commit

Permalink
Parameters should be typed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
achew22 committed Jan 9, 2016
1 parent a0a4ad5 commit 96f971a
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 28 deletions.
52 changes: 26 additions & 26 deletions examples/examplepb/streamless_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,57 +112,57 @@
"name": "float_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "number",
"format": "float"
},
{
"name": "double_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "number",
"format": "double"
},
{
"name": "int64_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int64"
},
{
"name": "uint64_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int64"
},
{
"name": "int32_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int32"
},
{
"name": "fixed64_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int64"
},
{
"name": "fixed32_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int32"
},
{
"name": "bool_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "boolean",
"format": "boolean"
},
{
"name": "string_value",
Expand All @@ -175,36 +175,36 @@
"name": "uint32_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int64"
},
{
"name": "sfixed32_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int32"
},
{
"name": "sfixed64_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int32"
},
{
"name": "sint32_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int32"
},
{
"name": "sint64_value",
"in": "path",
"required": true,
"type": "string",
"format": "string"
"type": "integer",
"format": "int64"
}
]
}
Expand Down
83 changes: 81 additions & 2 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,92 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject) er
// Iterate over all the swagger parameters
parameters := swaggerParametersObject{}
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":
panic("Groups are not allowed in the path for a HTTP RPC. Please use a primitive type instead (string, int64, etc)")
break
case "TYPE_MESSAGE":
panic("Groups are not allowed in the path for a HTTP RPC. Please use a primitive type instead (string, int64, etc)")
break
case "TYPE_BYTES":
paramType = "string"
paramFormat = "byte"
break
case "TYPE_UINT32":
paramType = "integer"
paramFormat = "int64"
break
case "TYPE_ENUM":
paramType = "integer"
paramFormat = "int64"
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()
panic("Detected field type of '" + paramType + "' which is unknown. Please use a primitive type (Ex: string, int64)")

}

parameters = append(parameters, swaggerParameterObject{
Name: parameter.String(),
In: "path",
Required: true,
// Parameters in gRPC-Gateway can only be strings?
Type: "string",
Format: "string",
Type: paramType,
Format: paramFormat,
})
}
// Now check if there is a body parameter
Expand Down

0 comments on commit 96f971a

Please sign in to comment.