Skip to content

Commit f45fe56

Browse files
committed
Title used a bit less often, which is important for swaggerSchemaObject.
1 parent 0d71621 commit f45fe56

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

examples/examplepb/streamless_everything.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@
426426
"uint32_value": {
427427
"type": "integer",
428428
"format": "int64",
429-
"description": "TODO(yugui) add bytes_value"
429+
"title": "TODO(yugui) add bytes_value"
430430
},
431431
"uint64_value": {
432432
"type": "integer",

protoc-gen-swagger/genswagger/template.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,18 @@ func applyTemplate(p param) (string, error) {
558558
// will be updated instead. (JSON always gets applied directly to the passed
559559
// object.)
560560
//
561-
// If there is no 'Summary', the same behavior will be attempted on 'Title'.
561+
// If there is no 'Summary', the same behavior will be attempted on 'Title',
562+
// but only if the last character is not a period.
562563
//
563564
// To apply additional Swagger properties, one can pass valid JSON as described
564565
// before. This JSON gets parsed and applied to the passed swaggerObject
565566
// directly. This lets users easily apply custom properties such as contact
566567
// details, API base path, et al.
567568
func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) error {
569+
if len(comment) == 0 {
570+
return nil
571+
}
572+
568573
// Find a section containing additional Swagger metadata.
569574
matches := swaggerExtrasRegexp.FindStringSubmatch(comment)
570575

@@ -597,8 +602,10 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) er
597602
// Figure out which properties to update.
598603
summaryValue := infoObjectValue.FieldByName("Summary")
599604
descriptionValue := infoObjectValue.FieldByName("Description")
605+
usingTitle := false
600606
if !summaryValue.CanSet() {
601607
summaryValue = infoObjectValue.FieldByName("Title")
608+
usingTitle = true
602609
}
603610

604611
// If there is a summary (or summary-equivalent), use the first
@@ -608,16 +615,18 @@ func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) er
608615

609616
summary := strings.TrimSpace(paragraphs[0])
610617
description := strings.TrimSpace(strings.Join(paragraphs[1:], "\n\n"))
611-
if len(summary) > 0 {
612-
summaryValue.Set(reflect.ValueOf(summary))
613-
}
614-
if len(description) > 0 {
615-
if !descriptionValue.CanSet() {
616-
return fmt.Errorf("Object that has Summary but no Description?")
618+
if !usingTitle || summary[len(summary)-1] != '.' {
619+
if len(summary) > 0 {
620+
summaryValue.Set(reflect.ValueOf(summary))
617621
}
618-
descriptionValue.Set(reflect.ValueOf(description))
622+
if len(description) > 0 {
623+
if !descriptionValue.CanSet() {
624+
return fmt.Errorf("Encountered object type with a summary, but no description")
625+
}
626+
descriptionValue.Set(reflect.ValueOf(description))
627+
}
628+
return nil
619629
}
620-
return nil
621630
}
622631

623632
// There was no summary field on the swaggerObject. Try to apply the

0 commit comments

Comments
 (0)