bufbuild/protovalidate

[BUG] Migrator uses wrong field path for string ignore

jschaf opened this issue · 1 comments

Description

Converting a proto message like below should result in a valid proto file.

// erp/api/sale_svc.proto
syntax = "proto3";

package erp.api;

import "validate/validate.proto";
import "buf/validate/validate.proto";

message CreateInvoiceSheetRequest {
  string invoice_sheet_id = 3 [
    (validate.rules).string = {ignore_empty: true, pattern: '^[a-z0-9-]{3,12}$'}
  ];
}

Steps to Reproduce

go run ./tools/protovalidate-migrate --verbose --write --legacy-import validate/validate.proto --remove-legacy erp/api/sale_svc.proto

Expected Behavior

A file like:

syntax = "proto3";

package erp.api;

import "buf/validate/validate.proto";

message CreateInvoiceSheetRequest {
  string invoice_sheet_id = 3 [
    (buf.validate.field).string = { pattern: '^[a-z0-9-]{3,12}$'},
    (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
  ];
}

Actual Behavior

The migrator tries to use string.ignore but it should be ignore.

syntax = "proto3";

package erp.api;

import "buf/validate/validate.proto";

message CreateInvoiceSheetRequest {
  string invoice_sheet_id = 3 [
    (buf.validate.field).string = { pattern: '^[a-z0-9-]{3,12}$'}
    , (buf.validate.field).string.ignore = IGNORE_IF_UNPOPULATED
  ];
}

Screenshots/Logs

Environment

  • Operating System:
  • Version:
  • Compiler/Toolchain:
  • Protobuf Compiler & Version:
  • Protoc-gen-validate Version:
  • Protovalidate Version: 022d7e5

Possible Solution

Additional Context

Thanks fort he report @jschaf! I think this is a duplicate of #202.