Skip to content

Allow attributes on list elements #4269

@jonas-meyer

Description

@jonas-meyer

With @yaml(,tag) (b1a58bd), CUE can emit custom YAML tags on struct fields. However, nested tags (tags on individual sequence elements) cannot be expressed because the grammar doesn't allow attributes on list elements.

Example: Authentik blueprints use !Format [pattern, !Env VAR]:

oidc_well_known_url: !Format
  - https://login.microsoftonline.com/%s/v2.0/.well-known/openid-configuration
  - !Env AZURE_TENANT_ID

The natural CUE would be:

oidc_well_known_url: [
  "https://login.microsoftonline.com/%s/v2.0/.well-known/openid-configuration",
  "AZURE_TENANT_ID" @yaml(,tag="!Env"),
] @yaml(,tag="!Format")

This is a syntax error today.

Prior issues

Proposal

Extend ElementList to allow trailing attributes, mirroring Field:

Element = Embedding { attribute } .

AST: a general AnnotatedExpr wrapper (reusable for future positions like let per #949):

type AnnotatedExpr struct {
    X     Expr
    Attrs []*Attribute
}

Parser: in parseListElement(), call parseAttributes() after the expression and wrap in AnnotatedExpr if present.

YAML encoder: in encode(), unwrap AnnotatedExpr and apply extractYAMLTag() to the resulting node.

This pattern also appears in CloudFormation (!Join containing !Ref) and other YAML-based config formats.

Purely additive, all existing CUE files remain valid, no change to evaluation semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions