Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bufbuild/protovalidate-go
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.4.3
Choose a base ref
...
head repository: bufbuild/protovalidate-go
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.0
Choose a head ref
  • 4 commits
  • 10 files changed
  • 3 contributors

Commits on Dec 12, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1638987 View commit details

Commits on Dec 20, 2023

  1. Move out of internal functions that create env options for field desc…

    …riptors (#83)
    
    Move `RequiredCELEnvOptions` and `ProtoFieldToCELType` out of internal
    so that it can be reused by the buf CLI for `buf lint`.
    
    Also rename `ProtoKindToCELType` to `protoKindToCELType` because no
    other packages calls it directly.
    oliversun9 authored Dec 20, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    06d9f6b View commit details

Commits on Jan 2, 2024

  1. Bump the go group with 1 update (#89)

    [![Dependabot compatibility
    score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go&package-manager=go_modules&previous-version=1.31.0-20231115204500-e097f827e652.2&new-version=1.32.0-20231115204500-e097f827e652.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
    
    Dependabot will resolve any conflicts with this PR as long as you don't
    alter it yourself. You can also trigger a rebase manually by commenting
    `@dependabot rebase`.
    
    [//]: # (dependabot-automerge-start)
    [//]: # (dependabot-automerge-end)
    
    ---
    
    <details>
    <summary>Dependabot commands and options</summary>
    <br />
    
    You can trigger Dependabot actions by commenting on this PR:
    - `@dependabot rebase` will rebase this PR
    - `@dependabot recreate` will recreate this PR, overwriting any edits
    that have been made to it
    - `@dependabot merge` will merge this PR after your CI passes on it
    - `@dependabot squash and merge` will squash and merge this PR after
    your CI passes on it
    - `@dependabot cancel merge` will cancel a previously requested merge
    and block automerging
    - `@dependabot reopen` will reopen this PR if it is closed
    - `@dependabot close` will close this PR and stop Dependabot recreating
    it. You can achieve the same result by closing it manually
    - `@dependabot show <dependency name> ignore conditions` will show all
    of the ignore conditions of the specified dependency
    - `@dependabot ignore <dependency name> major version` will close this
    group update PR and stop Dependabot creating any more for the specific
    dependency's major version (unless you unignore this specific
    dependency's major version or upgrade to it yourself)
    - `@dependabot ignore <dependency name> minor version` will close this
    group update PR and stop Dependabot creating any more for the specific
    dependency's minor version (unless you unignore this specific
    dependency's minor version or upgrade to it yourself)
    - `@dependabot ignore <dependency name>` will close this group update PR
    and stop Dependabot creating any more for the specific dependency
    (unless you unignore this specific dependency or upgrade to it yourself)
    - `@dependabot unignore <dependency name>` will remove all of the ignore
    conditions of the specified dependency
    - `@dependabot unignore <dependency name> <ignore condition>` will
    remove the ignore condition of the specified dependency and ignore
    conditions
    
    
    </details>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 2, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4aa948d View commit details

Commits on Jan 17, 2024

  1. Bump the go group with 1 update (#90)

    Bumps the go group with 1 update:
    [github.com/envoyproxy/protoc-gen-validate](https://github.com/envoyproxy/protoc-gen-validate).
    
    Updates `github.com/envoyproxy/protoc-gen-validate` from 1.0.2 to 1.0.3
    <details>
    <summary>Release notes</summary>
    <p><em>Sourced from <a
    href="https://github.com/envoyproxy/protoc-gen-validate/releases">github.com/envoyproxy/protoc-gen-validate's
    releases</a>.</em></p>
    <blockquote>
    <h2>v1.0.3</h2>
    <h2>What's Changed</h2>
    <ul>
    <li>Handle github-actions and pip dependencies by <a
    href="https://github.com/mmorel-35"><code>@​mmorel-35</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/908">bufbuild/protoc-gen-validate#908</a></li>
    <li>Update README.md to include new protovalidate releases by <a
    href="https://github.com/elliotmjackson"><code>@​elliotmjackson</code></a>
    in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/922">bufbuild/protoc-gen-validate#922</a></li>
    <li>Bump google.golang.org/protobuf from 1.30.0 to 1.31.0 by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/906">bufbuild/protoc-gen-validate#906</a></li>
    <li>Bump golang.org/x/tools from 0.10.0 to 0.12.0 by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/939">bufbuild/protoc-gen-validate#939</a></li>
    <li>Bump golang.org/x/net from 0.11.0 to 0.14.0 in /tests by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/932">bufbuild/protoc-gen-validate#932</a></li>
    <li>Trim the readme down by <a
    href="https://github.com/elliotmjackson"><code>@​elliotmjackson</code></a>
    in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/938">bufbuild/protoc-gen-validate#938</a></li>
    <li>Update tibdex/github-app-token by <a
    href="https://github.com/rubensf"><code>@​rubensf</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/968">bufbuild/protoc-gen-validate#968</a></li>
    <li>Bump actions/checkout from 3 to 4 by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/959">bufbuild/protoc-gen-validate#959</a></li>
    <li>Bump google.protobuf.version from 3.23.3 to 3.24.3 in /java by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/955">bufbuild/protoc-gen-validate#955</a></li>
    <li>Update Go+GHA deps by <a
    href="https://github.com/rodaine"><code>@​rodaine</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/984">bufbuild/protoc-gen-validate#984</a></li>
    <li>Bump java deps by <a
    href="https://github.com/rodaine"><code>@​rodaine</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/985">bufbuild/protoc-gen-validate#985</a></li>
    <li>Setup golangci-lint by <a
    href="https://github.com/mmorel-35"><code>@​mmorel-35</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/987">bufbuild/protoc-gen-validate#987</a></li>
    <li>Move PGV documentation back into the root README by <a
    href="https://github.com/nicksnyder"><code>@​nicksnyder</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1012">bufbuild/protoc-gen-validate#1012</a></li>
    <li>Group dependabot version updates by <a
    href="https://github.com/rodaine"><code>@​rodaine</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1024">bufbuild/protoc-gen-validate#1024</a></li>
    <li>Fix dependabot by <a
    href="https://github.com/rodaine"><code>@​rodaine</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1025">bufbuild/protoc-gen-validate#1025</a></li>
    <li>Bump the go-tests group in /tests with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1030">bufbuild/protoc-gen-validate#1030</a></li>
    <li>Bump the java group in /java with 9 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1028">bufbuild/protoc-gen-validate#1028</a></li>
    <li>Bump the github-actions group with 2 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1027">bufbuild/protoc-gen-validate#1027</a></li>
    <li>Bump the go group with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1026">bufbuild/protoc-gen-validate#1026</a></li>
    <li>Bump the java group in /java with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1032">bufbuild/protoc-gen-validate#1032</a></li>
    <li>Enable gocritic linter by <a
    href="https://github.com/mmorel-35"><code>@​mmorel-35</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1000">bufbuild/protoc-gen-validate#1000</a></li>
    <li>Fix typos in proto comments by <a
    href="https://github.com/WineChord"><code>@​WineChord</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/999">bufbuild/protoc-gen-validate#999</a></li>
    <li>Enable unused linter by <a
    href="https://github.com/mmorel-35"><code>@​mmorel-35</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/988">bufbuild/protoc-gen-validate#988</a></li>
    <li>Bump the go group with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1033">bufbuild/protoc-gen-validate#1033</a></li>
    <li>Bump the go-tests group in /tests with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1036">bufbuild/protoc-gen-validate#1036</a></li>
    <li>Bump the java group in /java with 3 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1035">bufbuild/protoc-gen-validate#1035</a></li>
    <li>Bump the github-actions group with 3 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1038">bufbuild/protoc-gen-validate#1038</a></li>
    <li>Bump the java group in /java with 3 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1040">bufbuild/protoc-gen-validate#1040</a></li>
    <li>Bump the github-actions group with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1041">bufbuild/protoc-gen-validate#1041</a></li>
    <li>Bump the java group in /java with 3 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1047">bufbuild/protoc-gen-validate#1047</a></li>
    <li>Bump the go group with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1045">bufbuild/protoc-gen-validate#1045</a></li>
    <li>Bump the go-tests group in /tests with 1 update by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1046">bufbuild/protoc-gen-validate#1046</a></li>
    <li>Bump the java group in /java with 2 updates by <a
    href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1049">bufbuild/protoc-gen-validate#1049</a></li>
    <li>Statically build all releases by <a
    href="https://github.com/rodaine"><code>@​rodaine</code></a> in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1052">bufbuild/protoc-gen-validate#1052</a></li>
    </ul>
    <h2>New Contributors</h2>
    <ul>
    <li><a href="https://github.com/mmorel-35"><code>@​mmorel-35</code></a>
    made their first contribution in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/908">bufbuild/protoc-gen-validate#908</a></li>
    <li><a
    href="https://github.com/nicksnyder"><code>@​nicksnyder</code></a> made
    their first contribution in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/1012">bufbuild/protoc-gen-validate#1012</a></li>
    <li><a href="https://github.com/WineChord"><code>@​WineChord</code></a>
    made their first contribution in <a
    href="https://redirect.github.com/bufbuild/protoc-gen-validate/pull/999">bufbuild/protoc-gen-validate#999</a></li>
    </ul>
    <p><strong>Full Changelog</strong>: <a
    href="https://github.com/bufbuild/protoc-gen-validate/compare/v1.0.2...v1.0.3">https://github.com/bufbuild/protoc-gen-validate/compare/v1.0.2...v1.0.3</a></p>
    </blockquote>
    </details>
    <details>
    <summary>Commits</summary>
    <ul>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/d61d4ec0b28cbf516d4d08c1550702f729a717d0"><code>d61d4ec</code></a>
    Statically build all releases (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1052">#1052</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/d9e9842d204762847c0dcf1a4fe6912084401ab0"><code>d9e9842</code></a>
    Bump the java group in /java with 2 updates (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1049">#1049</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/6dfcd591f688c70eef7220695e93345fcd56d996"><code>6dfcd59</code></a>
    Bump the go-tests group in /tests with 1 update (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1046">#1046</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/4507e91344d888ffb8c25a58a1bcd3cfa1ddab1b"><code>4507e91</code></a>
    Bump the go group with 1 update (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1045">#1045</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/d17db51f5dea639290af2ec43c3d30a33f3d26b4"><code>d17db51</code></a>
    Bump the java group in /java with 3 updates (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1047">#1047</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/87c1d2acd1404293838d7e8b7c483b4b7828ba4f"><code>87c1d2a</code></a>
    Bump the github-actions group with 1 update (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1041">#1041</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/64e2ed4f103f3cd97df154aa72e8d4084a95b0ab"><code>64e2ed4</code></a>
    Bump the java group in /java with 3 updates (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1040">#1040</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/09e4ca508946437c093b11ea81aa72ec2af21a2c"><code>09e4ca5</code></a>
    Bump the github-actions group with 3 updates (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1038">#1038</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/97f9e1f52d72da6523818314e8e13576d46b1ae8"><code>97f9e1f</code></a>
    Bump the java group in /java with 3 updates (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1035">#1035</a>)</li>
    <li><a
    href="https://github.com/bufbuild/protoc-gen-validate/commit/ca6725ea1c7b5b996b933396516ef174fde224d6"><code>ca6725e</code></a>
    Bump the go-tests group in /tests with 1 update (<a
    href="https://redirect.github.com/envoyproxy/protoc-gen-validate/issues/1036">#1036</a>)</li>
    <li>Additional commits viewable in <a
    href="https://github.com/envoyproxy/protoc-gen-validate/compare/v1.0.2...v1.0.3">compare
    view</a></li>
    </ul>
    </details>
    <br />
    
    
    [![Dependabot compatibility
    score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/envoyproxy/protoc-gen-validate&package-manager=go_modules&previous-version=1.0.2&new-version=1.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
    
    Dependabot will resolve any conflicts with this PR as long as you don't
    alter it yourself. You can also trigger a rebase manually by commenting
    `@dependabot rebase`.
    
    [//]: # (dependabot-automerge-start)
    [//]: # (dependabot-automerge-end)
    
    ---
    
    <details>
    <summary>Dependabot commands and options</summary>
    <br />
    
    You can trigger Dependabot actions by commenting on this PR:
    - `@dependabot rebase` will rebase this PR
    - `@dependabot recreate` will recreate this PR, overwriting any edits
    that have been made to it
    - `@dependabot merge` will merge this PR after your CI passes on it
    - `@dependabot squash and merge` will squash and merge this PR after
    your CI passes on it
    - `@dependabot cancel merge` will cancel a previously requested merge
    and block automerging
    - `@dependabot reopen` will reopen this PR if it is closed
    - `@dependabot close` will close this PR and stop Dependabot recreating
    it. You can achieve the same result by closing it manually
    - `@dependabot show <dependency name> ignore conditions` will show all
    of the ignore conditions of the specified dependency
    - `@dependabot ignore <dependency name> major version` will close this
    group update PR and stop Dependabot creating any more for the specific
    dependency's major version (unless you unignore this specific
    dependency's major version or upgrade to it yourself)
    - `@dependabot ignore <dependency name> minor version` will close this
    group update PR and stop Dependabot creating any more for the specific
    dependency's minor version (unless you unignore this specific
    dependency's minor version or upgrade to it yourself)
    - `@dependabot ignore <dependency name>` will close this group update PR
    and stop Dependabot creating any more for the specific dependency
    (unless you unignore this specific dependency or upgrade to it yourself)
    - `@dependabot unignore <dependency name>` will remove all of the ignore
    conditions of the specified dependency
    - `@dependabot unignore <dependency name> <ignore condition>` will
    remove the ignore condition of the specified dependency and ignore
    conditions
    
    
    </details>
    
    ---------
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Chris Roche <github@rodaine.com>
    dependabot[bot] and rodaine authored Jan 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    01ec377 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ jobs:
with:
fetch-depth: 1
- name: Install go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Test
2 changes: 1 addition & 1 deletion .github/workflows/conformance.yaml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
with:
fetch-depth: 1
- name: Install go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Test conformance
19 changes: 19 additions & 0 deletions celext/lib.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,9 @@ import (
"github.com/google/cel-go/common/types/ref"
"github.com/google/cel-go/common/types/traits"
"github.com/google/cel-go/ext"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/types/dynamicpb"
)

// DefaultEnv produces a cel.Env with the necessary cel.EnvOption and
@@ -49,6 +51,23 @@ func DefaultEnv(useUTC bool) (*cel.Env, error) {
)
}

// RequiredCELEnvOptions returns the options required to have expressions which
// rely on the provided descriptor.
func RequiredCELEnvOptions(fieldDesc protoreflect.FieldDescriptor) []cel.EnvOption {
if fieldDesc.IsMap() {
return append(
RequiredCELEnvOptions(fieldDesc.MapKey()),
RequiredCELEnvOptions(fieldDesc.MapValue())...,
)
}
if fieldDesc.Kind() == protoreflect.MessageKind {
return []cel.EnvOption{
cel.Types(dynamicpb.NewMessage(fieldDesc.Message())),
}
}
return nil
}

// lib is the collection of functions and settings required by protovalidate
// beyond the standard definitions of the CEL Specification:
//
90 changes: 36 additions & 54 deletions internal/expression/lookups.go → celext/lookups.go
Original file line number Diff line number Diff line change
@@ -12,51 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expression
package celext

import (
"github.com/google/cel-go/cel"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/dynamicpb"
)

// ProtoKindToCELType maps a protoreflect.Kind to a compatible cel.Type.
func ProtoKindToCELType(kind protoreflect.Kind) *cel.Type {
switch kind {
case
protoreflect.FloatKind,
protoreflect.DoubleKind:
return cel.DoubleType
case
protoreflect.Int32Kind,
protoreflect.Int64Kind,
protoreflect.Sint32Kind,
protoreflect.Sint64Kind,
protoreflect.Sfixed32Kind,
protoreflect.Sfixed64Kind,
protoreflect.EnumKind:
return cel.IntType
case
protoreflect.Uint32Kind,
protoreflect.Uint64Kind,
protoreflect.Fixed32Kind,
protoreflect.Fixed64Kind:
return cel.UintType
case protoreflect.BoolKind:
return cel.BoolType
case protoreflect.StringKind:
return cel.StringType
case protoreflect.BytesKind:
return cel.BytesType
case
protoreflect.MessageKind,
protoreflect.GroupKind:
return cel.DynType
default:
return cel.DynType
}
}

// ProtoFieldToCELType resolves the CEL value type for the provided
// FieldDescriptor. If generic is true, the specific subtypes of map and
// repeated fields will be replaced with cel.DynType. If forItems is true, the
@@ -92,22 +54,42 @@ func ProtoFieldToCELType(fieldDesc protoreflect.FieldDescriptor, generic, forIte
return cel.ObjectType(string(fqn))
}
}
return ProtoKindToCELType(fieldDesc.Kind())
return protoKindToCELType(fieldDesc.Kind())
}

// RequiredCELEnvOptions returns the options required to have expressions which
// rely on the provided descriptor.
func RequiredCELEnvOptions(fieldDesc protoreflect.FieldDescriptor) []cel.EnvOption {
if fieldDesc.IsMap() {
return append(
RequiredCELEnvOptions(fieldDesc.MapKey()),
RequiredCELEnvOptions(fieldDesc.MapValue())...,
)
}
if fieldDesc.Kind() == protoreflect.MessageKind {
return []cel.EnvOption{
cel.Types(dynamicpb.NewMessage(fieldDesc.Message())),
}
// protoKindToCELType maps a protoreflect.Kind to a compatible cel.Type.
func protoKindToCELType(kind protoreflect.Kind) *cel.Type {
switch kind {
case
protoreflect.FloatKind,
protoreflect.DoubleKind:
return cel.DoubleType
case
protoreflect.Int32Kind,
protoreflect.Int64Kind,
protoreflect.Sint32Kind,
protoreflect.Sint64Kind,
protoreflect.Sfixed32Kind,
protoreflect.Sfixed64Kind,
protoreflect.EnumKind:
return cel.IntType
case
protoreflect.Uint32Kind,
protoreflect.Uint64Kind,
protoreflect.Fixed32Kind,
protoreflect.Fixed64Kind:
return cel.UintType
case protoreflect.BoolKind:
return cel.BoolType
case protoreflect.StringKind:
return cel.StringType
case protoreflect.BytesKind:
return cel.BytesType
case
protoreflect.MessageKind,
protoreflect.GroupKind:
return cel.DynType
default:
return cel.DynType
}
return nil
}
36 changes: 35 additions & 1 deletion internal/expression/lookups_test.go → celext/lookups_test.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expression
package celext

import (
"testing"
@@ -89,6 +89,40 @@ func TestCache_GetCELType(t *testing.T) {
}
}

func TestProtoKindToCELType(t *testing.T) {
t.Parallel()

tests := map[protoreflect.Kind]*cel.Type{
protoreflect.FloatKind: cel.DoubleType,
protoreflect.DoubleKind: cel.DoubleType,
protoreflect.Int32Kind: cel.IntType,
protoreflect.Int64Kind: cel.IntType,
protoreflect.Uint32Kind: cel.UintType,
protoreflect.Uint64Kind: cel.UintType,
protoreflect.Sint32Kind: cel.IntType,
protoreflect.Sint64Kind: cel.IntType,
protoreflect.Fixed32Kind: cel.UintType,
protoreflect.Fixed64Kind: cel.UintType,
protoreflect.Sfixed32Kind: cel.IntType,
protoreflect.Sfixed64Kind: cel.IntType,
protoreflect.BoolKind: cel.BoolType,
protoreflect.StringKind: cel.StringType,
protoreflect.BytesKind: cel.BytesType,
protoreflect.EnumKind: cel.IntType,
protoreflect.MessageKind: cel.DynType,
protoreflect.GroupKind: cel.DynType,
protoreflect.Kind(0): cel.DynType,
}

for k, ty := range tests {
kind, typ := k, ty
t.Run(kind.String(), func(t *testing.T) {
t.Parallel()
assert.Equal(t, typ, protoKindToCELType(kind))
})
}
}

func getFieldDesc(t *testing.T, msg proto.Message, fld protoreflect.Name) protoreflect.FieldDescriptor {
t.Helper()
desc := msg.ProtoReflect().Descriptor().Fields().ByName(fld)
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ module github.com/bufbuild/protovalidate-go
go 1.19

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231115204500-e097f827e652.2
github.com/envoyproxy/protoc-gen-validate v1.0.2
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1
github.com/envoyproxy/protoc-gen-validate v1.0.4
github.com/google/cel-go v0.18.2
github.com/stretchr/testify v1.8.4
google.golang.org/protobuf v1.31.0
google.golang.org/protobuf v1.32.0
)

require (
@@ -18,7 +18,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231115204500-e097f827e652.2 h1:iEPA5SBtdLJNwQis/SrcCuDWJh5E1V0mVO4Ih7/mRbg=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231115204500-e097f827e652.2/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/cel-go v0.18.2 h1:L0B6sNBSVmt0OyECi8v6VOS74KOc9W/tLiWKfZABvf4=
github.com/google/cel-go v0.18.2/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
@@ -33,16 +33,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb h1:Isk1sSH7bovx8Rti2wZK0UZF6oraBDK74uoyLEEVFN0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3 changes: 2 additions & 1 deletion internal/constraints/cache.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ package constraints
import (
"buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
"buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate/priv"
"github.com/bufbuild/protovalidate-go/celext"
"github.com/bufbuild/protovalidate-go/internal/errors"
"github.com/bufbuild/protovalidate-go/internal/expression"
"github.com/google/cel-go/cel"
@@ -114,7 +115,7 @@ func (c *Cache) prepareEnvironment(
) (*cel.Env, error) {
env, err := env.Extend(
cel.Types(rules.Interface()),
cel.Variable("this", expression.ProtoFieldToCELType(fieldDesc, true, forItems)),
cel.Variable("this", celext.ProtoFieldToCELType(fieldDesc, true, forItems)),
cel.Variable("rules",
cel.ObjectType(string(rules.Descriptor().FullName()))),
)
36 changes: 0 additions & 36 deletions internal/constraints/lookups_test.go
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@ package constraints
import (
"testing"

"github.com/bufbuild/protovalidate-go/internal/expression"
"github.com/google/cel-go/cel"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
@@ -54,37 +52,3 @@ func TestExpectedWrapperConstraints(t *testing.T) {
})
}
}

func TestProtoKindToCELType(t *testing.T) {
t.Parallel()

tests := map[protoreflect.Kind]*cel.Type{
protoreflect.FloatKind: cel.DoubleType,
protoreflect.DoubleKind: cel.DoubleType,
protoreflect.Int32Kind: cel.IntType,
protoreflect.Int64Kind: cel.IntType,
protoreflect.Uint32Kind: cel.UintType,
protoreflect.Uint64Kind: cel.UintType,
protoreflect.Sint32Kind: cel.IntType,
protoreflect.Sint64Kind: cel.IntType,
protoreflect.Fixed32Kind: cel.UintType,
protoreflect.Fixed64Kind: cel.UintType,
protoreflect.Sfixed32Kind: cel.IntType,
protoreflect.Sfixed64Kind: cel.IntType,
protoreflect.BoolKind: cel.BoolType,
protoreflect.StringKind: cel.StringType,
protoreflect.BytesKind: cel.BytesType,
protoreflect.EnumKind: cel.IntType,
protoreflect.MessageKind: cel.DynType,
protoreflect.GroupKind: cel.DynType,
protoreflect.Kind(0): cel.DynType,
}

for k, ty := range tests {
kind, typ := k, ty
t.Run(kind.String(), func(t *testing.T) {
t.Parallel()
assert.Equal(t, typ, expression.ProtoKindToCELType(kind))
})
}
}
5 changes: 3 additions & 2 deletions internal/evaluator/builder.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"sync/atomic"

"buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
"github.com/bufbuild/protovalidate-go/celext"
"github.com/bufbuild/protovalidate-go/internal/constraints"
"github.com/bufbuild/protovalidate-go/internal/errors"
"github.com/bufbuild/protovalidate-go/internal/expression"
@@ -278,9 +279,9 @@ func (bldr *Builder) processFieldExpressions(
return nil
}

celTyp := expression.ProtoFieldToCELType(fieldDesc, false, false)
celTyp := celext.ProtoFieldToCELType(fieldDesc, false, false)
opts := append(
expression.RequiredCELEnvOptions(fieldDesc),
celext.RequiredCELEnvOptions(fieldDesc),
cel.Variable("this", celTyp),
)
compiledExpressions, err := expression.Compile(exprs, bldr.env, opts...)