Skip to content

Commit

Permalink
Add patch for generated file kind/Stack.go to support YAML for connec…
Browse files Browse the repository at this point in the history
…tion objects.

Signed-off-by: Timothy Rule (VM/EMT3) <Timothy.Rule@de.bosch.com>
  • Loading branch information
timrulebosch committed Feb 27, 2025
1 parent 1edc136 commit 9e8478d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 46 deletions.
97 changes: 51 additions & 46 deletions code/go/dse/Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0


YAML_DIR = ../../../schemas/yaml
KIND_YAML_FILES = $(shell cd $(YAML_DIR); ls *.yaml)
KIND_YAML_FILES := $(filter-out Simulation.yaml, $(KIND_YAML_FILES))
KIND_GO_FILES = $(subst .yaml,.go, $(KIND_YAML_FILES))
KIND_FILES = $(addprefix kind/, $(KIND_GO_FILES))
AST_FILES = ast/Simulation.go ast/metadata.go


.PHONY: generate
generate: clean kind ast


kind: $(KIND_FILES)
@echo "package kind" > kind/kind.go
kind/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@

ast: $(AST_FILES)
@echo "package ast" > ast/ast.go
ast/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@


.PHONY: clean
clean:
@rm -f kind/*.go
@rm -f ast/*.go
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0


YAML_DIR = ../../../schemas/yaml
KIND_YAML_FILES = $(shell cd $(YAML_DIR); ls *.yaml)
KIND_YAML_FILES := $(filter-out Simulation.yaml, $(KIND_YAML_FILES))
KIND_GO_FILES = $(subst .yaml,.go, $(KIND_YAML_FILES))
KIND_FILES = $(addprefix kind/, $(KIND_GO_FILES))
AST_FILES = ast/Simulation.go ast/metadata.go
PATCH_FILES = patch/marshal_yaml.patch

.PHONY: generate
generate: clean kind ast patch


kind: $(KIND_FILES)
@echo "package kind" > kind/kind.go
kind/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@

ast: $(AST_FILES)
@echo "package ast" > ast/ast.go
ast/%.go: $(YAML_DIR)/%.yaml
@echo "$$(basename $<) --> $@"
@~/go/bin/oapi-codegen -config $(@D)/config.yaml $< > $@
@sed -i '/delete_this_line/d' $@
@sed -i '/\/\//d' $@
@sed -i '/./!d' $@
@sed -i -e 's/externalRef[[:digit:]]*\.//g' $@
@sed -i -e 's/`json:"/`yaml:"/g' $@
@go fmt $@

.PHONY: $(PATCH_FILES)
patch: $(PATCH_FILES)
$(PATCH_FILES):
@echo "Apply Patch: $@ --> "
@git apply $@

.PHONY: clean
clean:
@rm -f kind/*.go
@rm -f ast/*.go
9 changes: 9 additions & 0 deletions code/go/dse/kind/Stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package kind

import (
"encoding/json"
"strings"

"github.com/oapi-codegen/runtime"
)

Expand Down Expand Up @@ -135,3 +137,10 @@ func (t *StackSpec_Connection_Transport) UnmarshalJSON(b []byte) error {
err := t.union.UnmarshalJSON(b)
return err
}
func (t StackSpec_Connection_Transport) MarshalYAML() (interface{}, error) {
b, err := t.union.MarshalJSON()
b = []byte(strings.ToLower(string(b)))
r := make(map[string]interface{})
json.Unmarshal(b, &r)
return r, err
}
24 changes: 24 additions & 0 deletions code/go/dse/patch/marshal_yaml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/code/go/dse/kind/Stack.go b/code/go/dse/kind/Stack.go
index 2022842..d3b0fb8 100644
--- a/code/go/dse/kind/Stack.go
+++ b/code/go/dse/kind/Stack.go
@@ -2,6 +2,8 @@ package kind

import (
"encoding/json"
+ "strings"
+
"github.com/oapi-codegen/runtime"
)

@@ -135,3 +137,10 @@ func (t *StackSpec_Connection_Transport) UnmarshalJSON(b []byte) error {
err := t.union.UnmarshalJSON(b)
return err
}
+func (t StackSpec_Connection_Transport) MarshalYAML() (interface{}, error) {
+ b, err := t.union.MarshalJSON()
+ b = []byte(strings.ToLower(string(b)))
+ r := make(map[string]interface{})
+ json.Unmarshal(b, &r)
+ return r, err
+}

0 comments on commit 9e8478d

Please sign in to comment.