Skip to content

encoding/yaml: add support for YAML tags via @yaml(tag) attribute#4199

Open
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
jonas-meyer:feat/encode-yaml-tags
Open

encoding/yaml: add support for YAML tags via @yaml(tag) attribute#4199
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
jonas-meyer:feat/encode-yaml-tags

Conversation

@jonas-meyer
Copy link

This adds support for encoding YAML tags by specifying them in @yaml(tag="...") attributes on CUE fields. The tag value is applied to the encoded YAML node.

This enables generating YAML files that use custom tags, such as those required by authentik blueprints (!KeyOf, !Env, !Find, etc.) and other YAML-based tools that rely on tags for special processing.

Tags can be applied to scalars, sequences, and mappings. The implementation extracts tags from field attributes in the AST and sets them on the corresponding yaml.Node during encoding.

Fixes #2316

Copilot AI review requested due to automatic review settings November 27, 2025 17:22
@jonas-meyer jonas-meyer requested a review from cueckoo as a code owner November 27, 2025 17:22
This adds support for encoding YAML tags by specifying them in
`@yaml(tag="...")` attributes on CUE fields. The tag value is applied
to the encoded YAML node.

This enables generating YAML files that use custom tags, such as
those required by authentik blueprints (!KeyOf, !Env, !Find, etc.)
and other YAML-based tools that rely on tags for special processing.

Tags can be applied to scalars, sequences, and mappings. The
implementation extracts tags from field attributes in the AST and
sets them on the corresponding yaml.Node during encoding.

Fixes cue-lang#2316

Signed-off-by: Jonas Meyer-Ohle <19151471+jonas-meyer@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for YAML tags in CUE's YAML encoding by allowing users to specify tags via @yaml(tag="...") field attributes. This enables generating YAML files that use custom tags required by tools like authentik blueprints and other YAML-based systems that rely on tags for special processing.

  • Implements extractYAMLTag() function to parse @yaml(tag="...") attributes from field declarations
  • Applies extracted tags to the encoded YAML nodes in encodeDecls()
  • Adds comprehensive test coverage for scalars, sequences, mappings, and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/encoding/yaml/encode.go Adds extractYAMLTag() function and integrates tag extraction into the field encoding process
internal/encoding/yaml/encode_test.go Adds 6 test cases covering tag usage on scalars, sequences, mappings, mixed scenarios, verbatim tags, and attributes without tags

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@freakhill
Copy link

little bump. this would be great in order to use the atmos terraform generation/orchestration tool with cue.

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

Successfully merging this pull request may close these issues.

encoding/yaml: Support for encoding tags

2 participants