Skip to content

Commit ea1f6f1

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: add embedded spec FS and ParseSpec/ParseOverlay functions
Add spec.Java and spec.Overlays as embed.FS for accessing YAML spec files without filesystem paths. Add ParseSpec and ParseOverlay functions that accept []byte, enabling consumers to load specs from embedded data or other non-filesystem sources.
1 parent 3d2e247 commit ea1f6f1

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

spec/specs.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Package spec embeds the Java API spec and overlay YAML files.
2+
package spec
3+
4+
import "embed"
5+
6+
// Java contains the Java API spec YAML files.
7+
//
8+
//go:embed java/*.yaml
9+
var Java embed.FS
10+
11+
// Overlays contains the overlay YAML files.
12+
//
13+
//go:embed overlays/java/*.yaml
14+
var Overlays embed.FS

tools/pkg/javagen/overlay.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ func LoadOverlay(path string) (*Overlay, error) {
2727
}
2828
return nil, fmt.Errorf("read overlay %s: %w", path, err)
2929
}
30+
return ParseOverlay(data)
31+
}
3032

33+
// ParseOverlay parses an overlay from YAML data.
34+
func ParseOverlay(data []byte) (*Overlay, error) {
3135
var ov Overlay
3236
if err := yaml.Unmarshal(data, &ov); err != nil {
33-
return nil, fmt.Errorf("parse overlay %s: %w", path, err)
37+
return nil, fmt.Errorf("parse overlay: %w", err)
3438
}
35-
3639
return &ov, nil
3740
}

tools/pkg/javagen/spec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ func LoadSpec(path string) (*Spec, error) {
1616
if err != nil {
1717
return nil, fmt.Errorf("read %s: %w", path, err)
1818
}
19+
return ParseSpec(data)
20+
}
1921

22+
// ParseSpec validates and parses a Java API spec from YAML data.
23+
func ParseSpec(data []byte) (*Spec, error) {
2024
var spec Spec
2125
if err := yaml.Unmarshal(data, &spec); err != nil {
22-
return nil, fmt.Errorf("parse %s: %w", path, err)
26+
return nil, fmt.Errorf("parse spec: %w", err)
2327
}
2428

2529
if err := validateSpec(&spec); err != nil {
26-
return nil, fmt.Errorf("validate %s: %w", path, err)
30+
return nil, fmt.Errorf("validate spec: %w", err)
2731
}
2832

2933
return &spec, nil

0 commit comments

Comments
 (0)