You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
♻️ Migrate use of extra_links to Schema-Based Access (#1638)
This PR migrates all post-config-resolution uses of
`needs_config.extra_links` to use `needs_schema` methods, centralizing
link type configuration in the schema system,
similar to how fields are used.
## Key Changes
### Schema Enhancements (`needs_schema.py`)
- **Added `LinkDisplayConfig`** dataclass for link rendering
configuration:
- `incoming`, `outgoing` (required): Display titles for link directions
- `color`, `style`, `style_part`, `style_start`, `style_end`: Diagram
styling with sensible defaults
- **Extended `LinkSchema`** with new attributes:
- `display: LinkDisplayConfig` - Rendering configuration (required)
- `copy: bool` - Whether to copy links to common `links` field
- `allow_dead_links: bool` - Whether to allow dead links without warning
### Configuration Changes (`config.py`, `needs.py`)
- Renamed `extra_links` → `_extra_links` (internal use only, for config
resolution phase)
- Schema creation in `needs.py` now populates `LinkDisplayConfig` from
link config, using dataclass defaults when values aren't explicitly set
### Updated Modules
Migrated from dict-based `needs_config.extra_links` access to schema
methods:
| Module | Change |
|--------|--------|
| `layout.py` | Use `schema.iter_link_fields()` and `link.display.*` |
| `api/need.py` | Use `schema.iter_link_fields()` and `link.copy` |
| `directives/need.py` | Use schema for `allow_dead_links` lookup |
| `directives/needtable.py` | Use `LinkSchema` objects instead of dicts
|
| `directives/needflow/_plantuml.py` | Use schema for link types and
display config |
| `directives/needflow/_graphviz.py` | Use schema for link types and
display config |
| `directives/needgantt.py` | Use schema for link type validation |
| `directives/needsequence.py` | Use schema for link type names |
| `directives/needreport.py` | Convert schema to dict for template
compatibility |
| `directives/list2need.py` | Use schema for link type list |
| `roles/need_outgoing.py` | Use schema for `allow_dead_links` check |
| `utils.py` | Use schema for link field iteration |
## Migration Pattern
**Before:**
```python
for link_type in needs_config.extra_links:
name = link_type["option"]
outgoing = link_type["outgoing"]
```
**After:**
```python
for link in needs_schema.iter_link_fields():
name = link.name
outgoing = link.display.outgoing
```
## Benefits
- **Single source of truth**: Link configuration is centralized in the
schema after config resolution
- **Type safety**: `LinkSchema` and `LinkDisplayConfig` provide typed
access to link properties
- **Cleaner separation**: `_extra_links` is internal for config merging;
schema is the public API
- **Consistent defaults**: `LinkDisplayConfig` dataclass defaults are
used consistently
0 commit comments