encoding/yaml: add support for YAML tags via @yaml(tag) attribute#4199
Open
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
Open
encoding/yaml: add support for YAML tags via @yaml(tag) attribute#4199jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
jonas-meyer wants to merge 1 commit intocue-lang:masterfrom
Conversation
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>
30726af to
5f6048a
Compare
There was a problem hiding this comment.
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.
|
little bump. this would be great in order to use the atmos terraform generation/orchestration tool with cue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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