Skip to content

Conversation

@networmix
Copy link
Owner

vars - YAML Anchors and Variables

The vars section provides a designated space for YAML anchor definitions. YAML anchors (&name) and aliases (*name) follow the YAML 1.1 specification and are processed by PyYAML during parsing, before NetGraph validation.

Anchor Types:

  • Scalar anchors: Reference primitive values (strings, numbers, booleans)
  • Sequence anchors: Reference arrays/lists
  • Mapping anchors: Reference objects/dictionaries
  • Merge keys (<<): Merge mapping properties with override capability

Minimal Example:

vars:
  default_cap: &cap 10000
  base_attrs: &attrs {cost: 100, region: "dc1"}

network:
  nodes:
    N1: {attrs: {<<: *attrs, capacity: *cap}}
    N2: {attrs: {<<: *attrs, capacity: *cap, region: "dc2"}}

Processing Behavior:

  • Anchors are resolved during YAML parsing, before schema validation
  • The vars section itself is ignored by NetGraph runtime logic
  • Anchors can be defined in any section, not just vars
  • Merge operations follow YAML 1.1 semantics (later keys override earlier ones)

@networmix networmix self-assigned this Aug 6, 2025
Copilot AI review requested due to automatic review settings August 6, 2025 23:18
@networmix networmix added the enhancement New feature or request label Aug 6, 2025
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 a vars section in YAML schema files to provide a designated space for YAML anchor definitions and variable reuse. The change enables users to define reusable values, attributes, and configurations using YAML anchors and aliases, following YAML 1.1 specification.

Key changes:

  • Added vars section to JSON schema with optional object type
  • Updated scenario parsing to recognize and allow the vars top-level key
  • Added comprehensive test coverage for YAML anchor functionality

Reviewed Changes

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

Show a summary per file
File Description
schemas/scenario.json Adds vars property to JSON schema as optional object for anchor definitions
ngraph/scenario.py Updates recognized keys list and docstring to include vars section
tests/test_schema_validation.py Adds test to verify schema validation of vars section
tests/test_scenario.py Adds comprehensive tests for YAML anchor and alias functionality
docs/reference/dsl.md Documents vars section usage, anchor types, and processing behavior
docs/reference/api-full.md Updates documentation generation timestamp

@networmix networmix merged commit 5404c08 into main Aug 6, 2025
7 checks passed
@networmix networmix deleted the feature branch August 6, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants