Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'License' message to the annotation proto. #644

Merged
merged 2 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
366 changes: 184 additions & 182 deletions examples/proto/examplepb/a_bit_of_everything.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/proto/examplepb/a_bit_of_everything.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
email: "[email protected]";
};
license: {
name: "BSD 3-Clause License";
url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt";
};
};
// Overwriting host entry breaks tests, so this is not done here.
external_docs: {
Expand Down
4 changes: 4 additions & 0 deletions examples/proto/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"name": "gRPC-Gateway project",
"url": "https://github.com/grpc-ecosystem/grpc-gateway",
"email": "[email protected]"
},
"license": {
"name": "BSD 3-Clause License",
"url": "https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt"
}
},
"schemes": [
Expand Down
11 changes: 11 additions & 0 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,17 @@ func applyTemplate(p param) (*swaggerObject, error) {
s.Info.Contact.Email = spb.Info.Contact.Email
}
}
if spb.Info.License != nil {
if s.Info.License == nil {
s.Info.License = &swaggerLicenseObject{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add the License field to the Info object. I'm surprised this isn't a compile time error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be generated from "message Info" define in openapiv2.proto? Also when I build it with bazel it actually works. I am getting the license fields in the generated json.

}
if spb.Info.License.Name != "" {
s.Info.License.Name = spb.Info.License.Name
}
if spb.Info.License.Url != "" {
s.Info.License.URL = spb.Info.License.Url
}
}
}
if spb.Host != "" {
s.Host = spb.Host
Expand Down
Loading