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

format tool #729

Closed
unship opened this issue Aug 17, 2018 · 9 comments
Closed

format tool #729

unship opened this issue Aug 17, 2018 · 9 comments

Comments

@unship
Copy link

unship commented Aug 17, 2018

I use clang-format to format proto file, but the output option section of proto file is not what I expect,

say I clang-format -i examples/proto/examplepb/a_bit_of_everything.proto

I get

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
  info : {title : "A Bit of Everything";
version : "1.0";
contact : {
name:
  "gRPC-Gateway project";
url:
  "https://github.com/grpc-ecosystem/grpc-gateway";
email:
  "[email protected]";
};
}
;
// Overwriting host entry breaks tests, so this is not done here.
external_docs : {
url:
  "https://github.com/grpc-ecosystem/grpc-gateway";
description:
  "More about gRPC-Gateway";
}
schemes : HTTP;
schemes : HTTPS;
schemes : WSS;
consumes : "application/json";
consumes : "application/x-foo-mime";
produces : "application/json";
produces : "application/x-foo-mime";
security_definitions : {
security : {
key:
  "BasicAuth";
value : {
type:
  TYPE_BASIC;
}
}
security : {
key:
  "ApiKeyAuth";
value : {
type:
  TYPE_API_KEY;
in:
  IN_HEADER;
name:
  "X-API-Key";
}
}
security : {
key:
  "OAuth2";
value : {
type:
  TYPE_OAUTH2;
flow:
  FLOW_ACCESS_CODE;
authorization_url:
  "https://example.com/oauth/authorize";
token_url:
  "https://example.com/oauth/token";
scopes : {
scope : {
key:
  "read";
value:
  "Grants read access";
}
scope : {
key:
  "write";
value:
  "Grants write access";
}
scope : {
key:
  "admin";
value:
  "Grants read and write access to administrative information";
}
}
}
}
}
security : {
security_requirement : {
key:
  "BasicAuth";
value : {};
}
security_requirement : {
key:
  "ApiKeyAuth";
value : {};
}
}
security : {
security_requirement : {
key:
  "OAuth2";
value : {
scope:
  "read";
scope:
  "write";
}
}
security_requirement : {
key:
  "ApiKeyAuth";
value : {};
}
}
responses : {
key:
  "403";
value : {
description:
  "Returned when the user does not have permission to access the resource.";
}
}
responses : {
key:
  "404";
value : {
description:
  "Returned when the resource does not exist.";
schema : {
json_schema : {
type:
  STRING;
}
}
}
}
responses : {
key:
  "418";
value : {
description:
  "I'm a teapot.";
schema : {
json_schema : {
ref:
  ".grpc.gateway.examples.examplepb.NumericEnum";
}
}
}
}
}
;

so what format tool are you using?

@johanbrandhorst
Copy link
Collaborator

The files in this repo are manually formatted, but a formatting tool that solves this much better than clang is prototool.

I'll close this issue as it's largely unrelated to the gateway, but feel free to reopen if you have more questions.

@yuhang2
Copy link

yuhang2 commented Dec 12, 2018

Hey @llVim , Do you find the solution for how to formatting proto file?

@unship
Copy link
Author

unship commented Dec 18, 2018

@yuhang2 not yet

@johanbrandhorst
Copy link
Collaborator

As I said in my previous comment, using prototool --no-rewrite format works well for me.

@ec2ainun
Copy link

@johanbrandhorst
Hi johan, can you provide guide in documentation on how to setup prototool with current grpc-gateway /v2 ?
i am new and try to work with grpc-gateway
i already use buf to generate stub, but unfortunately there is no buf format right now

@johanbrandhorst
Copy link
Collaborator

Do you need any particular configuration to use the prototool formatter on its own? buf is going to get a formatter eventually, we just haven't gotten around to implementing it yet 😁.

@ec2ainun
Copy link

@johanbrandhorst not really sir 😄
i just want to format .proto file, but i got problem on importing

<input>:1:1:Import "google/api/annotations.proto" was not found.
<input>:1:1:Import "protoc-gen-openapiv2/options/annotations.proto" was not found.
api/proto/v1/todo-service.proto:6:1:Import "google/api/annotations.proto" was not found or had errors.
api/proto/v1/todo-service.proto:7:1:Import "protoc-gen-openapiv2/options/annotations.proto" was not found or had errors.

and im try to look for solution on the prototool github issue, but it seems no one responding, i know that it will be replaced by buf, as for now, i just wanna search working solution haha
reference issue:
Import "google/api/annotations.proto" was not found or had errors

@johanbrandhorst
Copy link
Collaborator

Yeah I'm not sure, I don't know prototool, I haven't used it in years. I'm afraid maybe you just don't use formatting for now?

@ec2ainun
Copy link

@johanbrandhorst okay sir, thanks for replaying
as for now, manually formatted is the way, while waiting buf format release.

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

4 participants