Skip to content

Commit 93f942e

Browse files
committed
feat(s2dm): simplify vspec metadata annotation with sidecar lookup spec file
Signed-off-by: JD Alvarez <8550265+jdacoello@users.noreply.github.com>
1 parent f63becd commit 93f942e

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/vss_tools/exporters/s2dm/graphql_directive_processor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,16 @@ def _process_field_directives(self, lines: list[str], vspec_comments: dict) -> l
246246

247247
# Add extended attributes metadata
248248
for key, value in vss_info.items():
249-
if key not in ["element", "fqn", "instantiate"]:
249+
if key not in ["element", "fqn", "instantiate", "metadata"]:
250250
# Escape quotes in value
251251
escaped_value = str(value).replace('"', '\\\\"')
252252
metadata_entries.append(f'{{key: "{key}", value: "{escaped_value}"}}')
253253

254+
# Add structured metadata list entries (e.g. unit)
255+
for entry in vss_info.get("metadata", []):
256+
escaped_value = str(entry["value"]).replace('"', '\\\\"')
257+
metadata_entries.append(f'{{key: "{entry["key"]}", value: "{escaped_value}"}}')
258+
254259
# Build directive
255260
if metadata_entries:
256261
metadata_str = ", ".join(metadata_entries)

src/vss_tools/exporters/s2dm/predefined_elements/directives.graphql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ enum VspecElement {
3535
}
3636

3737

38-
#enum FuelTypeEnum @vspec(element:"ATTRIBUTE", fqn:"Vehicle.Powertrain.FuelType", metadata:[{key:"allowed", value:"[GASOLINE, DIESEL, ELECTRIC, HYBRID]"}]) {
39-
# GASOLINE
40-
# DIESEL
41-
# ELECTRIC
42-
# HYBRID
43-
#}
44-
4538
directive @range(min: Float, max: Float) on FIELD_DEFINITION
4639

4740
directive @instanceTag on OBJECT

src/vss_tools/exporters/s2dm/type_builders.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
GraphQLEnumType,
3030
GraphQLEnumValue,
3131
GraphQLField,
32-
GraphQLID,
3332
GraphQLList,
3433
GraphQLNonNull,
3534
GraphQLObjectType,
@@ -513,8 +512,6 @@ def get_fields() -> dict[str, GraphQLField]:
513512
fields = {}
514513

515514
# System fields
516-
if type_name == "Vehicle" or branch_row.get("instances"):
517-
fields["id"] = GraphQLField(GraphQLNonNull(GraphQLID))
518515
if instance_tag_type := vspec_comments.get("instance_tag_types", {}).get(type_name):
519516
if instance_tag_type in types_registry:
520517
fields["instanceTag"] = GraphQLField(types_registry[instance_tag_type])
@@ -537,10 +534,7 @@ def get_fields() -> dict[str, GraphQLField]:
537534

538535
if leaf_type := _get_vss_type_if_valid(leaf_row):
539536
field_metadata = {"element": leaf_type, "fqn": child_fqn}
540-
541-
# Capture extended attributes if present
542537
field_metadata.update(_extract_extended_attributes(leaf_row, extended_attributes))
543-
544538
vspec_comments["field_vss_types"][field_path] = field_metadata
545539

546540
if pd.notna(leaf_row.get("min")) or pd.notna(leaf_row.get("max")):
@@ -597,8 +591,12 @@ def get_fields() -> dict[str, GraphQLField]:
597591
{"fqn": child_fqn, "plural_field_name": plural_field_name, "path_in_graphql_model": field_path}
598592
)
599593
else:
594+
field_path = build_field_path(type_name, field_name)
600595
fields[field_name] = GraphQLField(child_type)
601596

597+
# Annotate field with @vspec directive (shared for both cases)
598+
vspec_comments["field_vss_types"][field_path] = {"element": "BRANCH", "fqn": child_fqn}
599+
602600
return fields
603601

604602
# Store type-level metadata including extended attributes
@@ -652,10 +650,7 @@ def get_hoisted_fields(
652650
"fqn": leaf_fqn,
653651
"instantiate": False,
654652
}
655-
656-
# Capture extended attributes if present
657653
field_metadata.update(_extract_extended_attributes(leaf_row, extended_attributes))
658-
659654
vspec_comments["field_vss_types"][field_path] = field_metadata
660655

661656
if pd.notna(leaf_row.get("min")) or pd.notna(leaf_row.get("max")):

0 commit comments

Comments
 (0)