Skip to content

Commit

Permalink
Add Handling of 'License' message to the annotation proto.
Browse files Browse the repository at this point in the history
This information is used by the default html doc generator and so it is nice
to be able to provide it.

Add the message to openapiv2.proto and extend template.go to handle it.

Tested via:
bazel build //examples/proto/examplepb:expamplepb_protoc_gen_swagger
more bazel-bin/examples/proto/examplepb/a_bit_of_everything.swagger.json
  • Loading branch information
ensonic committed May 22, 2018
1 parent 74ba578 commit 4e0ecd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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 @@ -19,6 +19,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
11 changes: 11 additions & 0 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,17 @@ func applyTemplate(p param) (string, error) {
s.Info.Contact.Email = spb.Info.Contact.Email
}
}
if spb.Info.License != nil {
if s.Info.License == nil {
s.Info.License = &swaggerLicenseObject{}
}
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
14 changes: 12 additions & 2 deletions protoc-gen-swagger/options/openapiv2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ message Info {
string description = 2;
string terms_of_service = 3;
Contact contact = 4;
// field 5 is reserved for 'license'.
reserved 5;
License license=5;
string version = 6;
}

Expand All @@ -90,6 +89,17 @@ message Contact {
string email = 3;
}

// `License` is a representation of OpenAPI v2 specification's License object.
//
// See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#licenseObject
//
message License {
// Required. The license name used for the API.
string name = 1;
// A URL to the license used for the API.
string url = 2;
}

// `ExternalDocumentation` is a representation of OpenAPI v2 specification's
// ExternalDocumentation object.
//
Expand Down

0 comments on commit 4e0ecd0

Please sign in to comment.