Skip to content

Commit

Permalink
Merge pull request #247 from dprotaso/master
Browse files Browse the repository at this point in the history
Render the swagger request body properly
  • Loading branch information
tmc authored Nov 5, 2016
2 parents 89be3a9 + 8e63463 commit 84398b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/clients/abe/ABitOfEverythingServiceApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ func (a ABitOfEverythingServiceApi) Echo_1 () (SubStringMessage, error) {
* @param body
* @return SubStringMessage
*/
//func (a ABitOfEverythingServiceApi) Echo_2 (body SubStringMessage) (SubStringMessage, error) {
func (a ABitOfEverythingServiceApi) Echo_2 (body SubStringMessage) (SubStringMessage, error) {
//func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) {
func (a ABitOfEverythingServiceApi) Echo_2 (body string) (SubStringMessage, error) {

_sling := sling.New().Post(a.basePath)

Expand Down
3 changes: 2 additions & 1 deletion examples/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/subStringMessage"
"type": "string",
"format": "string"
}
}
],
Expand Down
19 changes: 14 additions & 5 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
}
// Now check if there is a body parameter
if b.Body != nil {
var schema swaggerSchemaObject

if len(b.Body.FieldPath) == 0 {
schema = swaggerSchemaObject{
schemaCore: schemaCore{
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)),
},
}
} else {
lastField := b.Body.FieldPath[len(b.Body.FieldPath) - 1]
schema = schemaOfField(lastField.Target, reg)
}

desc := ""
if meth.GetClientStreaming() {
desc = "(streaming inputs)"
Expand All @@ -386,11 +399,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
Description: desc,
In: "body",
Required: true,
Schema: &swaggerSchemaObject{
schemaCore: schemaCore{
Ref: fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)),
},
},
Schema: &schema,
})
}

Expand Down

0 comments on commit 84398b9

Please sign in to comment.