Skip to content

Commit c0317cd

Browse files
Fabian Hernandezjohanbrandhorst
authored andcommitted
Fix problem while generating swagger documentation for enum messages containing a dot (#898)
Fixes #898
1 parent be12715 commit c0317cd

File tree

7 files changed

+235
-227
lines changed

7 files changed

+235
-227
lines changed

examples/clients/abe/a_bit_of_everything_nested.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ type ABitOfEverythingNested struct {
1818

1919
Amount int64 `json:"amount,omitempty"`
2020

21+
// DeepEnum description.
2122
Ok NestedDeepEnum `json:"ok,omitempty"`
2223
}

examples/clients/abe/a_bit_of_everything_service_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
526526
* @param floatValue Float value field
527527
* @param singleNestedName name is nested field.
528528
* @param singleNestedAmount
529-
* @param singleNestedOk - FALSE: FALSE is false. - TRUE: TRUE is true.
529+
* @param singleNestedOk DeepEnum description. - FALSE: FALSE is false. - TRUE: TRUE is true.
530530
* @param doubleValue
531531
* @param int64Value
532532
* @param uint64Value
@@ -554,7 +554,7 @@ func (a ABitOfEverythingServiceApi) GetMessageWithBody(id string, body Examplepb
554554
* @param repeatedStringAnnotation Repeated string title. Repeated string description.
555555
* @param nestedAnnotationName name is nested field.
556556
* @param nestedAnnotationAmount
557-
* @param nestedAnnotationOk - FALSE: FALSE is false. - TRUE: TRUE is true.
557+
* @param nestedAnnotationOk DeepEnum description. - FALSE: FALSE is false. - TRUE: TRUE is true.
558558
* @return *interface{}
559559
*/
560560
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) {

examples/proto/examplepb/a_bit_of_everything.pb.go

Lines changed: 219 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/proto/examplepb/a_bit_of_everything.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ message ABitOfEverything {
162162
// TRUE is true.
163163
TRUE = 1;
164164
}
165-
DeepEnum ok = 3;
165+
166+
// DeepEnum comment.
167+
DeepEnum ok = 3 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {description: "DeepEnum description."}];
166168
}
167169
Nested single_nested = 25;
168170

examples/proto/examplepb/a_bit_of_everything.swagger.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
},
172172
{
173173
"name": "single_nested.ok",
174-
"description": " - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
174+
"description": "DeepEnum description.\n\n - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
175175
"in": "query",
176176
"required": false,
177177
"type": "string",
@@ -415,7 +415,7 @@
415415
},
416416
{
417417
"name": "nested_annotation.ok",
418-
"description": " - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
418+
"description": "DeepEnum description.\n\n - FALSE: FALSE is false.\n - TRUE: TRUE is true.",
419419
"in": "query",
420420
"required": false,
421421
"type": "string",
@@ -1485,7 +1485,8 @@
14851485
"format": "int64"
14861486
},
14871487
"ok": {
1488-
"$ref": "#/definitions/NestedDeepEnum"
1488+
"$ref": "#/definitions/NestedDeepEnum",
1489+
"description": "DeepEnum description."
14891490
}
14901491
},
14911492
"description": "Nested is nested type."

examples/proto/examplepb/stream.swagger.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
"format": "int64"
103103
},
104104
"ok": {
105-
"$ref": "#/definitions/NestedDeepEnum"
105+
"$ref": "#/definitions/NestedDeepEnum",
106+
"description": "DeepEnum description."
106107
}
107108
},
108109
"description": "Nested is nested type."

protoc-gen-swagger/genswagger/template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,10 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string, is
12651265

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

0 commit comments

Comments
 (0)