oswee / api

Oswee API
0 stars 0 forks source link

Import "protoc-gen-swagger/options/openapiv2.proto" was not found or had errors. #7

Closed dzintars closed 2 years ago

dzintars commented 4 years ago

Need to include the annotations

dzintars commented 4 years ago

Dzintars Klavins 16:23 Hi all. Just want to check something. Want to use import "protoc-gen-swagger/options/openapiv2.proto"; in *.proto, but it complains that file not found. Year or so ago i was doing something like this cp $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google /usr/local/include/google to copy the extra annotations and to make them available for protoc. Now it seems that the same annotations by default are located at $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.14.7/third_party/googleapis/google . Docs say's:

// +build tools
package tools
import (
    _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway"
    _ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger"
    _ "github.com/golang/protobuf/protoc-gen-go"
)

and

$ go install \
    github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
    github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
    github.com/golang/protobuf/protoc-gen-go

and i should be good to go, but it seems to me it's not the case. ptotoc can't find:

import "protoc-gen-swagger/options/openapiv2.proto";
import "protoc-gen-swagger/options/annotations.proto";
import "google/protobuf/timestamp.proto";

and IDE complains. Is it due to some recent updates or migration to the modules?

Johan Brandhorst-Satzkorn 16:25 You need to copy the proto files into your local repository 16:25 The go installation is just for the generators

Dzintars Klavins 16:25 This is another solution

Johan Brandhorst-Satzkorn 16:25 No, you shouldn't depend on the mod file directory at all 16:25 Copying is the recommended solution 16:25 (For now)

Dzintars Klavins 16:25 Ah ok.. i was aware of it

Johan Brandhorst-Satzkorn 16:26 It's there in the README:

You will need to provide the required third party protobuf files to the protoc compiler. They are included in this repo under the third_party/googleapis folder, and we recommend copying them into your protoc generation file structure. If you've structured your proto files according to something like the Buf style guide, you could copy the files into a top-level ./google folder. 16:26 If this is unclear, how could we improve the documentation?

Dzintars Klavins 16:26 Tnx for the clarification. Is there some pending updates? >(For now)

Johan Brandhorst-Satzkorn 16:27 There's nothing the grpc-gateway can do, but Buf (where I work) is working on something that will make this much easier to manage :slightly_smiling_face:

Dzintars Klavins 16:28 Great. This was a little place of confusion for some time to many devs. :slightly_smiling_face:

Johan Brandhorst-Satzkorn 16:28 Yeah, it's a bit of a mess. Another alternative is to use Bazel, which we also support in the gateway

Dzintars Klavins 16:29 I'm interested in Bazel in general... but i need to find some time to dive into it. :slightly_smiling_face:

Dzintars Klavins 17:04 Do you handle in some way that IDE error about import not found? Not that big a deal... just to tidy things up. :) (edited)

Johan Brandhorst-Satzkorn 17:05 It'll depend on what plugin you use, personally I don't use any proto plugins

17:06 You should be able to fix it by modifying the include paths

Dzintars Klavins 17:07 Great. Thank You. I got it all working. Just don't like those red waves on imports. :slightly_smiling_face: (edited)

Johan Brandhorst-Satzkorn 17:08 Yeah... we have a vim plugin for buf I believe, not sure it's public. We have plans for a vs code extension too. It's definitely due some good tooling :slightly_smiling_face:

Dzintars Klavins 17:10 Nice. A lot of good news. Great to see this project taking off. :slightly_smiling_face: Saw some MS project migrating to gRPC... .NET believe..

17:10 anyway. Thank You a lot.

Johan Brandhorst-Satzkorn 17:10 :+1::skin-tone-2:

dzintars commented 4 years ago
cp -R $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.14.7/third_party/googleapis/google ./third_party

and

cp -R $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.14.7/protoc-gen-swagger ./third_party

You can narrow that down just to *.proto files as i don't need those Bazel and Go files.