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

How to change title and version in generated swagger json file #1269

Closed
rahulk84 opened this issue May 5, 2020 · 4 comments
Closed

How to change title and version in generated swagger json file #1269

rahulk84 opened this issue May 5, 2020 · 4 comments

Comments

@rahulk84
Copy link

rahulk84 commented May 5, 2020

Hello Everyone,

I wanted to know how to set title and version while converting proto files to swagger json files. I am able to generate json file with protoc-gen-swagger (grpc-ecosystem.grpc-gateway) but the title and version is coming as below:

{
  "swagger": "2.0",
  "info": {
    "title": "abc.proto",
    "version": "version not set"
  },
  "schemes": [
    "http",
    "https"
  ]
}

I am generating swagger json file using spring boot app :

<outputTarget>
 <type>protoc-gen-swagger</type>
<pluginArtifact>com.grpc-ecosystem.grpc-gateway:protoc-gen-swagger:${protoc-gen-swagger.version}:exe:${os.detected.classifier}</pluginArtifact>
<outputDirectory>${project.build.directory}/api-definitions</outputDirectory>
</outputTarget>

Can someone help me on how to pass title and version, as swagger hub is not accepting json with the above generated version.

@johanbrandhorst
Copy link
Collaborator

https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.proto#L17-L35 shows how to customize this part of the generation. Would you be able to help us improve the documentation around this? I'd love for this to be more discoverable by users.

@rahulk84
Copy link
Author

rahulk84 commented May 6, 2020

The above link is mainly for go, what if we do it for java and publish it as maven dependency it will be useful for everyone going forward.

@johanbrandhorst
Copy link
Collaborator

I have no experience of the java ecosystem, if you think that would be useful than please go ahead, I'd be happy to add a link to your published package to our docs.

@kuchaguangjie
Copy link

Here is what I did to set swagger-ui base info:

in .proto file:

import "protoc-gen-openapiv2/options/annotations.proto";

// swagger-ui base info,
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  info: {
    title: "grpc-gateway demo";
    version: "1.0";
    contact: {
      name: "gRPC-Gateway project";
      url: "https://github.com/grpc-ecosystem/grpc-gateway";
      email: "none@example.com";
    };
    license: {
      name: "My License";
      url: "LICENSE.txt";
    };
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants