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

Invalid module name for proto files with dashes or dots in name #42

Open
anatolym opened this issue Dec 11, 2022 · 0 comments · Fixed by dpup/protoc-gen-grpc-gateway-ts#20 · May be fixed by #43
Open

Invalid module name for proto files with dashes or dots in name #42

anatolym opened this issue Dec 11, 2022 · 0 comments · Fixed by dpup/protoc-gen-grpc-gateway-ts#20 · May be fixed by #43

Comments

@anatolym
Copy link

anatolym commented Dec 11, 2022

Description

When a protobuf service consists of several files, and some files have special chars in their names like . or -, the generated TS code has invalid import instructions.

Affected version

https://github.com/grpc-ecosystem/protoc-gen-grpc-gateway-ts/releases/tag/v1.1.2

Reproduce steps

  • Prepare the env
git clone [email protected]:grpc-ecosystem/protoc-gen-grpc-gateway-ts.git && \
  cd protoc-gen-grpc-gateway-ts && \
  git checkout v1.1.2 && \
  go install . && \
  mkdir -p tmp/generated && \
  cd tmp
  • Create a new proto service with files files service.proto and product-models.proto.
// src: ./service.proto
syntax = "proto3";

package myservice;

import "google/api/annotations.proto";

import "product-models.proto";

service MyService {
  rpc GetProducts(GetProductReuest) returns (GetProductResponse) {
    option (google.api.http) = {
      post: "/products"
      body: "*"
    };
  }
}

message GetProductReuest {
  repeated int64 ids = 1;
}

message GetProductResponse {
  repeated Product products = 1;
}
// src: ./product-models.proto
syntax = "proto3";

package myservice;

message Product {
  string name = 1;
  string description = 2;
}
  • Generate TS
protoc --grpc-gateway-ts_out=./generated \
  --grpc-gateway-ts_opt=use_proto_names=true,logtostderr=true,loglevel=debug \
  -I . \
  -I ../integration_tests \
  *.proto
  • Observe invalid import name MyserviceProduct-models in tmp/generated/service.pb.ts:
/* eslint-disable */
// @ts-nocheck
/*
* This file is a generated Typescript file for GRPC Gateway, DO NOT MODIFY
*/

import * as fm from "./fetch.pb"
import * as MyserviceProduct-models from "./product-models.pb"
export type GetProductReuest = {
  ids?: string[]
}

export type GetProductResponse = {
  products?: MyserviceProduct-models.Product[]
}

export class MyService {
  static GetProducts(req: GetProductReuest, initReq?: fm.InitReq): Promise<GetProductResponse> {
    return fm.fetchReq<GetProductReuest, GetProductResponse>(`/products`, {...initReq, method: "POST", body: JSON.stringify(req, fm.replacer)})
  }
}
anatolym added a commit to anatolym/protoc-gen-grpc-gateway-ts that referenced this issue Dec 11, 2022
Fixes grpc-ecosystem#42

The fix patches `data.GetModuleName` func to return a camel cased string to be used as a unique module name in TS artifacts. Here we replace manual conversion of a package name and base file name with `ToCamel` func of the `github.com/iancoleman/strcase` package. This helper package has already been included in go.mod.
`ToCamel` removes `.`, `-`, `_` or whitespace chars from the input string and uses those as a mark to capitalize the next letter.
anatolym added a commit to anatolym/protoc-gen-grpc-gateway-ts that referenced this issue Dec 11, 2022
Fixes grpc-ecosystem#42

The fix patches `data.GetModuleName` func to return a camel cased string to be used as a unique module name in TS artifacts. Here we replace manual conversion of a package name and base file name with `ToCamel` func of the `github.com/iancoleman/strcase` package. This helper package has already been included in go.mod.
`ToCamel` removes `.`, `-`, `_` or whitespace chars from the input string and uses those as a mark to capitalize the next letter.
dpup pushed a commit to dpup/protoc-gen-grpc-gateway-ts that referenced this issue May 12, 2024
Fixes grpc-ecosystem#42

The fix patches `data.GetModuleName` func to return a camel cased string to be used as a unique module name in TS artifacts. Here we replace manual conversion of a package name and base file name with `ToCamel` func of the `github.com/iancoleman/strcase` package. This helper package has already been included in go.mod.
`ToCamel` removes `.`, `-`, `_` or whitespace chars from the input string and uses those as a mark to capitalize the next letter.
dpup pushed a commit to dpup/protoc-gen-grpc-gateway-ts that referenced this issue May 12, 2024
Fixes grpc-ecosystem#42

The fix patches `data.GetModuleName` func to return a camel cased string to be used as a unique module name in TS artifacts. Here we replace manual conversion of a package name and base file name with `ToCamel` func of the `github.com/iancoleman/strcase` package. This helper package has already been included in go.mod.
`ToCamel` removes `.`, `-`, `_` or whitespace chars from the input string and uses those as a mark to capitalize the next letter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant