insomnia icon indicating copy to clipboard operation
insomnia copied to clipboard

Unable to import proto file that depends upon another protofile

Open dpclark4 opened this issue 3 years ago • 12 comments

Describe the bug I have a proto file, a.proto, that has a dependency upon a message in a different proto file, b.proto. To get around this, I am forced to move all of my proto definitions into one file.

To Reproduce Steps to reproduce the behavior: Simplified version: b.proto

message FooStruct {
  string foo = 1;
}

a.proto

message BarStruct {
  string bar = 1;
  Foostruct imported_struct = 2;
}

Try to import a.proto and receive the following (I have omitted my actual file names and substituted the above)

Error: no such Type or Enum 'FooStruct' in Type BarStruct
    at Type.lookupTypeOrEnum (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86897:15)
    at Field.resolve (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:74747:94)
    at Type.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:114185:21)
    at Namespace.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Namespace.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Namespace.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Namespace.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Namespace.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Root.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:86794:25)
    at Root.resolveAll (file:///Applications/Insomnia.app/Contents/Resources/app.asar/bundle.js:115345:43)


**Expected behavior**
I should be able to import proto files that have imports from other proto files.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
Version: Insomnia 2021.3.0-beta.1
Release date: 4/21/2021
OS: Darwin x64 19.6.0
Electron: 9.3.5
Node: 12.14.1
V8: 8.3.110.13-electron.0
Architecture: x64
node-libcurl: libcurl/7.73.0 OpenSSL/1.1.1j zlib/1.2.11 brotli/1.0.9 zstd/1.4.9 libidn2/2.1.1 libssh2/1.9.0 nghttp2/1.41.0

**Additional context**
Add any other context about the problem here.

dpclark4 avatar Apr 22 '21 21:04 dpclark4

If a.proto depends on something in b.proto, both proto files need to be available to Insomnia (they are fully ingested by Insomnia). In order to provide two .protos in this way, you need to upload them by uploading a directory. You can upload your entire code-directory if you want and Insomnia will keep the folder structure but ignore all non-.proto files.

You need to upload a common parent directory (it doesn't have to be a direct parent) because Insomnia needs to understand the relative file paths which exist when importing a type from a separate file. You shouldn't need to combine everything into one file.

Let me know if that doesn't clarify the usage and I can elaborate :)

develohpanda avatar Apr 22 '21 21:04 develohpanda

Hi @develohpanda, I run into the same error if I use the import directory option too.

dpclark4 avatar Apr 22 '21 22:04 dpclark4

Gotcha - how are you importing b.proto in a.proto, and could you show an outline of the file/directory structure you have?

develohpanda avatar Apr 22 '21 22:04 develohpanda

I have a folder called test, representing my service, which lives inside a folder with many other proto files for other services. Inside test is a folder called api. Inside the api folder, I have two files: a and b .proto. b.proto looks like:

syntax = "proto3";

package com.org.contracts.test.api;

option java_outer_classname = "ModelProtos";

message FooStruct {
   string foo = 1;
}

a.proto looks like:

syntax = "proto3";

package com.org.contracts.test.api;

import "com/org/contracts/test/api/b.proto";

option java_outer_classname = "ContractProtos";

message BarStruct {
    string bar = 1;
    FooStruct imported_struct = 2;
}

Again, the error is like: Error: no such Type or Enum 'FooStruct' in Type .com.org.contracts.test.api.BarStruct

dpclark4 avatar Apr 22 '21 23:04 dpclark4

👍🏽 From com/org/contracts/test/api, which directory are you selecting to import into Insomnia?

develohpanda avatar Apr 22 '21 23:04 develohpanda

I have tried importing both the api (immediate parent) and the test folder (parent of api). I get the same error both times. I cannot import the next level up, contracts, because I get errors on other proto files - this is probably the same issue too.

dpclark4 avatar Apr 22 '21 23:04 dpclark4

I vaguely recall that relative imports aren't possible (something like import ../b.proto)?

If you can visualize how the files are being resolved compared to what is given, you'll see the problem.

If Insomnia is only provided the test folder containing api/a.proto and api/b.proto, but it's trying to resolve from com/org/contracts/test/api/b.proto, that entire directory structure doesn't exist for Insomnia, so the import fails.

Assuming relative imports do not work, you'll need to provide the top-most directory - in this case, the parent of com.

Ie. if your folder stucture is ~/dev/project/com/org/contracts..., you'll need to upload project. This is less a requirement of Insomnia specifically, but if gRPC can't find the filepath to resolve from it will always fail.

develohpanda avatar Apr 22 '21 23:04 develohpanda

I don't know if this is a related issue, but when I try to import a directory, it is not allowing me to pick sub directories. image

koppathachan avatar May 01 '21 12:05 koppathachan

@sasidakh that seems to be unrelated (maybe OS specific), could you please open another issue (and share your OS details) please? Thanks!

develohpanda avatar May 01 '21 12:05 develohpanda

It is not always possible to load the parent folder. Some projects rely on other open source projects, for example I'm importing timestamp from google:

import "google/protobuf/timestamp.proto";

Is this not supported by Insomnia?

fabitamas avatar Apr 11 '22 19:04 fabitamas