Skip to content

Commit 562956f

Browse files
committed
Backing out 'swagger extras' JSON code, per [request][1].
[1]: #134 (comment)
1 parent f45fe56 commit 562956f

File tree

4 files changed

+3
-133
lines changed

4 files changed

+3
-133
lines changed

examples/examplepb/echo_service.pb.go

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

examples/examplepb/echo_service.proto

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,11 @@ option go_package = "examplepb";
55
//
66
// Echo Service API consists of a single service which returns
77
// a message.
8-
//
9-
// <!-- swagger extras start
10-
// {
11-
// "info": {
12-
// "title": "Echo Service",
13-
// "version": "1.0",
14-
// "contact": {
15-
// "name": "gRPC-Gateway project",
16-
// "url": "https://github.com/gengo/grpc-gateway",
17-
// "email": "[email protected]"
18-
// }
19-
// },
20-
// "host": "localhost",
21-
// "externalDocs": {
22-
// "url": "https://github.com/gengo/grpc-gateway",
23-
// "description": "More about gRPC-Gateway"
24-
// }
25-
// }
26-
// swagger extras end -->
278
package gengo.grpc.gateway.examples.examplepb;
289

2910
import "google/api/annotations.proto";
3011

3112
// SimpleMessage represents a simple message sent to the Echo service.
32-
//
33-
// <!-- swagger extras start
34-
// {
35-
// "externalDocs": {
36-
// "url": "http://github.com/gengo/grpc-gateway",
37-
// "description": "Find out more about EchoService"
38-
// }
39-
// }
40-
// swagger extras end -->
4113
message SimpleMessage {
4214
// Id represents the message identifier.
4315
string id = 1;
@@ -49,15 +21,6 @@ service EchoService {
4921
//
5022
// The message posted as the id parameter will also be
5123
// returned.
52-
//
53-
// <!-- swagger extras start
54-
// {
55-
// "externalDocs": {
56-
// "url": "http://github.com/gengo/grpc-gateway",
57-
// "description": "Find out more about EchoService"
58-
// }
59-
// }
60-
// swagger extras end -->
6124
rpc Echo(SimpleMessage) returns (SimpleMessage) {
6225
option (google.api.http) = {
6326
post: "/v1/example/echo/{id}"

examples/examplepb/echo_service.swagger.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
"info": {
44
"title": "Echo Service",
55
"description": "Echo Service API consists of a single service which returns\na message.",
6-
"version": "1.0",
7-
"contact": {
8-
"name": "gRPC-Gateway project",
9-
"url": "https://github.com/gengo/grpc-gateway",
10-
"email": "[email protected]"
11-
}
6+
"version": "version not set"
127
},
13-
"host": "localhost",
148
"schemes": [
159
"http",
1610
"https"
@@ -46,11 +40,7 @@
4640
],
4741
"tags": [
4842
"EchoService"
49-
],
50-
"externalDocs": {
51-
"description": "Find out more about EchoService",
52-
"url": "http://github.com/gengo/grpc-gateway"
53-
}
43+
]
5444
}
5545
},
5646
"/v1/example/echo_body": {

protoc-gen-swagger/genswagger/template.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
pbdescriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
1414
)
1515

16-
var swaggerExtrasRegexp = regexp.MustCompile(`(?s)^(.*[^\s])[\s]*<!-- swagger extras start(.*)swagger extras end -->[\s]*(.*)$`)
17-
1816
// findServicesMessagesAndEnumerations discovers all messages and enums defined in the RPC methods of the service.
1917
func findServicesMessagesAndEnumerations(s []*descriptor.Service, reg *descriptor.Registry, m messageMap, e enumMap) {
2018
for _, svc := range s {
@@ -541,55 +539,20 @@ func applyTemplate(p param) (string, error) {
541539
// updateSwaggerDataFromComments updates a Swagger object based on a comment
542540
// from the proto file.
543541
//
544-
// As a first step, a section matching:
545-
//
546-
// <!-- swagger extras start.*swagger extras end-->
547-
//
548-
// where .* contains valid JSON will be stored for later processing, and then
549-
// removed from the passed string.
550-
// (Implementation note: Currently, the JSON gets immediately applied and
551-
// thus cannot override summary and description.)
552-
//
553542
// First paragraph of a comment is used for summary. Remaining paragraphs of a
554543
// comment are used for description. If 'Summary' field is not present on the
555544
// passed swaggerObject, the summary and description are joined by \n\n.
556545
//
557546
// If there is a field named 'Info', its 'Summary' and 'Description' fields
558-
// will be updated instead. (JSON always gets applied directly to the passed
559-
// object.)
547+
// will be updated instead.
560548
//
561549
// If there is no 'Summary', the same behavior will be attempted on 'Title',
562550
// but only if the last character is not a period.
563-
//
564-
// To apply additional Swagger properties, one can pass valid JSON as described
565-
// before. This JSON gets parsed and applied to the passed swaggerObject
566-
// directly. This lets users easily apply custom properties such as contact
567-
// details, API base path, et al.
568551
func updateSwaggerDataFromComments(swaggerObject interface{}, comment string) error {
569552
if len(comment) == 0 {
570553
return nil
571554
}
572555

573-
// Find a section containing additional Swagger metadata.
574-
matches := swaggerExtrasRegexp.FindStringSubmatch(comment)
575-
576-
if len(matches) > 0 {
577-
// If found, before further processing, replace the
578-
// comment with a version that does not contain the
579-
// extras.
580-
comment = matches[1]
581-
if len(matches[3]) > 0 {
582-
comment += "\n\n" + matches[3]
583-
}
584-
585-
// Parse the JSON and apply it.
586-
// TODO(ivucica): apply extras /after/ applying summary
587-
// and description.
588-
if err := json.Unmarshal([]byte(matches[2]), swaggerObject); err != nil {
589-
return fmt.Errorf("error: %s, parsing: %s", err.Error(), matches[2])
590-
}
591-
}
592-
593556
// Figure out what to apply changes to.
594557
swaggerObjectValue := reflect.ValueOf(swaggerObject)
595558
infoObjectValue := swaggerObjectValue.Elem().FieldByName("Info")

0 commit comments

Comments
 (0)