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

[Bug] Missing field in Generated TypeScript Code Using buf with google.type.Decimal #157

Open
jekabolt opened this issue Dec 12, 2023 · 0 comments

Comments

@jekabolt
Copy link

jekabolt commented Dec 12, 2023

Description
When using buf to generate TypeScript HTTP code from .proto files, the max_price field defined as google.type.Decimal in FilterConditions is not being generated in the TypeScript code. This issue does not occur when google.type.Decimal is replaced with string. The problem seems specific to the handling of google.type.Decimal type for the max_price field.

Environment
Go version: 1.21.4 darwin/arm64
TypeScript version: Version 5.1.3
OS: Darwin & Ubuntu

Steps to Reproduce
Define min_price and max_price fields in FilterConditions message in common.proto using google.type.Decimal.
Generate TypeScript code using buf.gen.yaml configuration.
Observe that only minPrice is generated correctly in TypeScript, while maxPrice is missing.
Expected Behavior
Both minPrice and maxPrice fields should be generated in the TypeScript code, similar to how they are generated when defined as string types.

Actual Behavior
Only the minPrice field is generated in the TypeScript code. The maxPrice field is missing when using google.type.Decimal type.

Additional Information
admin.proto and common.proto files used for generating code.
buf.gen.yaml configuration file.
Examples of generated code with min_price and max_price as google.type.Decimal and as string.
Example Files

test.proto

rpc GetProductsPaged(GetProductsPagedRequest) returns (GetProductsPagedResponse) {
    option (google.api.http) = {get: "/api/admin/product/paged"};
}

message GetProductsPagedRequest {
  int32 limit = 1;
  int32 offset = 2;
  FilterConditions filter_conditions = 3;
}

message FilterConditions {
  google.type.Decimal min_price = 1;
  google.type.Decimal max_price = 2;
}

buf.gen.yaml

version: v1
managed:
  enabled: true
plugins:
  - plugin: typescript-http
    out: src/api/proto-http
    opt: paths=source_relative

generated code with min/max google.type.Decimal

 if (request.filterConditions?.minPrice?.value) {
        queryParams.push(`filterConditions.minPrice.value=${encodeURIComponent(request.filterConditions.minPrice.value.toString())}`)
      }
      if (request.filterConditions?.onSale) {
        queryParams.push(`filterConditions.onSale=${encodeURIComponent(request.filterConditions.onSale.toString())}`)
      }
      if (request.filterConditions?.color) {
        queryParams.push(`filterConditions.color=${encodeURIComponent(request.filterConditions.color.toString())}`)
      }
      if (request.filterConditions?.categoryId) {
        queryParams.push(`filterConditions.categoryId=${encodeURIComponent(request.filterConditions.categoryId.toString())}`)
      }
      if (request.filterConditions?.sizesIds) {
        request.filterConditions.sizesIds.forEach((x) => {
          queryParams.push(`filterConditions.sizesIds=${encodeURIComponent(x.toString())}`)
        })
      }
      if (request.filterConditions?.preorder) {
        queryParams.push(`filterConditions.preorder=${encodeURIComponent(request.filterConditions.preorder.toString())}`)
      }
      if (request.filterConditions?.byTag) {
        queryParams.push(`filterConditions.byTag=${encodeURIComponent(request.filterConditions.byTag.toString())}`)
      }

generated code with min/max string

if (request.filterConditions?.minPrice) {
        queryParams.push(`filterConditions.minPrice=${encodeURIComponent(request.filterConditions.minPrice.toString())}`)
      }
      if (request.filterConditions?.maxPrice) {
        queryParams.push(`filterConditions.maxPrice=${encodeURIComponent(request.filterConditions.maxPrice.toString())}`)
      }
      if (request.filterConditions?.onSale) {
        queryParams.push(`filterConditions.onSale=${encodeURIComponent(request.filterConditions.onSale.toString())}`)
      }
      if (request.filterConditions?.color) {
        queryParams.push(`filterConditions.color=${encodeURIComponent(request.filterConditions.color.toString())}`)
      }
      if (request.filterConditions?.categoryId) {
        queryParams.push(`filterConditions.categoryId=${encodeURIComponent(request.filterConditions.categoryId.toString())}`)
      }
      if (request.filterConditions?.sizesIds) {
        request.filterConditions.sizesIds.forEach((x) => {
          queryParams.push(`filterConditions.sizesIds=${encodeURIComponent(x.toString())}`)
        })
      }
      if (request.filterConditions?.preorder) {
        queryParams.push(`filterConditions.preorder=${encodeURIComponent(request.filterConditions.preorder.toString())}`)
      }
      if (request.filterConditions?.byTag) {
        queryParams.push(`filterConditions.byTag=${encodeURIComponent(request.filterConditions.byTag.toString())}`)
      }
@jekabolt jekabolt changed the title Missing ' Field in Generated TypeScript Code Using buf with google.type.Decimal Missing Field in Generated TypeScript Code Using buf with google.type.Decimal Dec 12, 2023
@jekabolt jekabolt changed the title Missing Field in Generated TypeScript Code Using buf with google.type.Decimal Missing field in Generated TypeScript Code Using buf with google.type.Decimal Dec 12, 2023
@jekabolt jekabolt changed the title Missing field in Generated TypeScript Code Using buf with google.type.Decimal [Bug] Missing field in Generated TypeScript Code Using buf with google.type.Decimal Dec 12, 2023
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

1 participant