Skip to content

Native types: Allow adding a type including all its nested subtypes #885

@alvaroaleman

Description

@alvaroaleman

Change
Summary of the proposed change and some details about what problem
it helps solve.

The ext.NativeTypes constructor only adds types directly passed to it but not subtypes within those types. This means that sub-fields that are part of a different type can not be accessed. I found this surprising and ended up having to write some reflect code to get my type including all its nested types added. I would think that this is a relatively common usecase, so IMHO having the ability to this directly in cel-go would be helpful.

Example

type MyType struct {
SomeField Bar
}

type Bar struct {
  First string
}

When adding MyType using ext.NativeTypes, trying to access MyType.SomeField.First in a CEL expression will fail.

Alternatives considered
Briefly list alternative designs, or an example of the functionality to be replaced.

  • Not doing this in ext.NativeTypes but a new constructor like ext.NativeTypesRecursive or such
  • Telling users to do this through reflect themselves

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions