Skip to content

Commit

Permalink
Fix problem while generating swagger documentation for enum messages …
Browse files Browse the repository at this point in the history
…containing a dot (#898)

Fixes #898
  • Loading branch information
Fabian Hernandez authored and johanbrandhorst committed Mar 7, 2019
1 parent be12715 commit c0317cd
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 227 deletions.
1 change: 1 addition & 0 deletions examples/clients/abe/a_bit_of_everything_nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ type ABitOfEverythingNested struct {

Amount int64 `json:"amount,omitempty"`

// DeepEnum description.
Ok NestedDeepEnum `json:"ok,omitempty"`
}
4 changes: 2 additions & 2 deletions examples/clients/abe/a_bit_of_everything_service_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
* @param floatValue Float value field
* @param singleNestedName name is nested field.
* @param singleNestedAmount
* @param singleNestedOk - FALSE: FALSE is false. - TRUE: TRUE is true.
* @param singleNestedOk DeepEnum description. - FALSE: FALSE is false. - TRUE: TRUE is true.
* @param doubleValue
* @param int64Value
* @param uint64Value
Expand Down Expand Up @@ -554,7 +554,7 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
* @param repeatedStringAnnotation Repeated string title. Repeated string description.
* @param nestedAnnotationName name is nested field.
* @param nestedAnnotationAmount
* @param nestedAnnotationOk - FALSE: FALSE is false. - TRUE: TRUE is true.
* @param nestedAnnotationOk DeepEnum description. - FALSE: FALSE is false. - TRUE: TRUE is true.
* @return *interface{}
*/
func (a ABitOfEverythingServiceApi) GetQuery(uuid string, floatValue float32, singleNestedName string, singleNestedAmount int64, singleNestedOk string, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, bytesValue string, uint32Value int64, enumValue string, pathEnumValue string, nestedPathEnumValue string, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, repeatedStringValue []string, oneofString string, nonConventionalNameValue string, timestampValue time.Time, repeatedEnumValue []string, repeatedEnumAnnotation []string, enumValueAnnotation string, repeatedStringAnnotation []string, nestedAnnotationName string, nestedAnnotationAmount int64, nestedAnnotationOk string) (*interface{}, *APIResponse, error) {
Expand Down
437 changes: 219 additions & 218 deletions examples/proto/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/proto/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ message ABitOfEverything {
// TRUE is true.
TRUE = 1;
}
DeepEnum ok = 3;

// DeepEnum comment.
DeepEnum ok = 3 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {description: "DeepEnum description."}];
}
Nested single_nested = 25;

Expand Down
7 changes: 4 additions & 3 deletions examples/proto/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
},
{
"name": "single_nested.ok",
"description": " - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
"description": "DeepEnum description.\n\n - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
"in": "query",
"required": false,
"type": "string",
Expand Down Expand Up @@ -415,7 +415,7 @@
},
{
"name": "nested_annotation.ok",
"description": " - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
"description": "DeepEnum description.\n\n - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
"in": "query",
"required": false,
"type": "string",
Expand Down Expand Up @@ -1485,7 +1485,8 @@
"format": "int64"
},
"ok": {
"$ref": "#/definitions/NestedDeepEnum"
"$ref": "#/definitions/NestedDeepEnum",
"description": "DeepEnum description."
}
},
"description": "Nested is nested type."
Expand Down
3 changes: 2 additions & 1 deletion examples/proto/examplepb/stream.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"format": "int64"
},
"ok": {
"$ref": "#/definitions/NestedDeepEnum"
"$ref": "#/definitions/NestedDeepEnum",
"description": "DeepEnum description."
}
},
"description": "Nested is nested type."
Expand Down
6 changes: 4 additions & 2 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,10 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string, is

// There was no summary field on the swaggerObject. Try to apply the
// whole comment into description if the swagger object description is empty.
if descriptionValue.CanSet() && (descriptionValue.Len() == 0 || isPackageObject){
descriptionValue.Set(reflect.ValueOf(strings.Join(paragraphs, "\n\n")))
if descriptionValue.CanSet() {
if descriptionValue.Len() == 0 || isPackageObject {
descriptionValue.Set(reflect.ValueOf(strings.Join(paragraphs, "\n\n")))
}
return nil
}

Expand Down

0 comments on commit c0317cd

Please sign in to comment.