From bea66c6e3343446f0d2a202d1ec3c03a401d53ef Mon Sep 17 00:00:00 2001 From: "Rule Timothy (VM/EMT3)" Date: Wed, 21 Feb 2024 19:03:14 +0100 Subject: [PATCH] Reworked Go code generation. Signed-off-by: Rule Timothy (VM/EMT3) --- code/go/dse/Makefile | 20 +++--- code/go/dse/README.md | 13 ++++ code/go/dse/kind/Manifest.go | 71 +++++++++++++++++++ code/go/dse/kind/{Model.yaml.go => Model.go} | 0 code/go/dse/kind/Network.go | 34 +++++++++ .../{ParameterSet.yaml.go => ParameterSet.go} | 0 .../{Propagator.yaml.go => Propagator.go} | 0 .../kind/{Runnable.yaml.go => Runnable.go} | 0 .../{SignalGroup.yaml.go => SignalGroup.go} | 0 code/go/dse/kind/{Stack.yaml.go => Stack.go} | 0 .../dse/kind/{channel.yaml.go => channel.go} | 0 code/go/dse/{ => kind}/config.yaml | 0 code/go/dse/kind/kind.go | 2 +- .../kind/{metadata.yaml.go => metadata.go} | 0 14 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 code/go/dse/README.md create mode 100644 code/go/dse/kind/Manifest.go rename code/go/dse/kind/{Model.yaml.go => Model.go} (100%) create mode 100644 code/go/dse/kind/Network.go rename code/go/dse/kind/{ParameterSet.yaml.go => ParameterSet.go} (100%) rename code/go/dse/kind/{Propagator.yaml.go => Propagator.go} (100%) rename code/go/dse/kind/{Runnable.yaml.go => Runnable.go} (100%) rename code/go/dse/kind/{SignalGroup.yaml.go => SignalGroup.go} (100%) rename code/go/dse/kind/{Stack.yaml.go => Stack.go} (100%) rename code/go/dse/kind/{channel.yaml.go => channel.go} (100%) rename code/go/dse/{ => kind}/config.yaml (100%) rename code/go/dse/kind/{metadata.yaml.go => metadata.go} (100%) diff --git a/code/go/dse/Makefile b/code/go/dse/Makefile index 849c7aa..57355d4 100644 --- a/code/go/dse/Makefile +++ b/code/go/dse/Makefile @@ -8,22 +8,22 @@ KIND_YAML_FILES = $(shell ls $(KIND_YAML_DIR)/*.yaml) .PHONY: generate -generate: kind +generate: clean kind kind: $(KIND_YAML_FILES) + @echo "package kind" > kind/kind.go .PHONY: $(KIND_YAML_FILES) $(KIND_YAML_FILES): @echo $$(basename $@) - @mkdir -p kind - @~/go/bin/oapi-codegen -config config.yaml $@ > kind/$$(basename $@).go - @sed -i '/delete_this_line/d' kind/$$(basename $@).go - @sed -i '/\/\//d' kind/$$(basename $@).go - @sed -i '/./!d' kind/$$(basename $@).go - @sed -i -e 's/externalRef[[:digit:]]*\.//g' kind/$$(basename $@).go - @sed -i -e 's/`json:"/`yaml:"/g' kind/$$(basename $@).go - @go fmt kind/$$(basename $@).go + @~/go/bin/oapi-codegen -config kind/config.yaml $@ > kind/$$(basename $@ .yaml).go + @sed -i '/delete_this_line/d' kind/$$(basename $@ .yaml).go + @sed -i '/\/\//d' kind/$$(basename $@ .yaml).go + @sed -i '/./!d' kind/$$(basename $@ .yaml).go + @sed -i -e 's/externalRef[[:digit:]]*\.//g' kind/$$(basename $@ .yaml).go + @sed -i -e 's/`json:"/`yaml:"/g' kind/$$(basename $@ .yaml).go + @go fmt kind/$$(basename $@ .yaml).go .PHONY: clean clean: - @rm -rf kind + @rm -f kind/*.go diff --git a/code/go/dse/README.md b/code/go/dse/README.md new file mode 100644 index 0000000..a4b8bb0 --- /dev/null +++ b/code/go/dse/README.md @@ -0,0 +1,13 @@ +## Install the Module + +```bash +# Latest version. +$ export GOPRIVATE=github.com/boschglobal +$ go get github.com/boschglobal/dse.schemas/code/go/dse + +# Specific tagged version. +$ go get github.com/boschglobal/dse.schemas/code/go/dse@vX.Y.Z + +# Debug for go get command +$ go get -x github.com/boschglobal/dse.schemas/code/go/dse +``` diff --git a/code/go/dse/kind/Manifest.go b/code/go/dse/kind/Manifest.go new file mode 100644 index 0000000..b50f348 --- /dev/null +++ b/code/go/dse/kind/Manifest.go @@ -0,0 +1,71 @@ +package kind + +import () + +const ( + ManifestKindManifest ManifestKind = "Manifest" +) +const ( + Redispubsub SimulationParametersTransport = "redispubsub" +) + +type File struct { + Generate *string `yaml:"generate,omitempty"` + Modelc *bool `yaml:"modelc,omitempty"` + Name string `yaml:"name"` + Processing *string `yaml:"processing,omitempty"` + Repo *string `yaml:"repo,omitempty"` + Uri *string `yaml:"uri,omitempty"` +} +type Manifest struct { + Kind ManifestKind `yaml:"kind"` + Metadata *ObjectMetadata `yaml:"metadata,omitempty"` + Spec ManifestSpec `yaml:"spec"` +} +type ManifestKind string +type ManifestSpec struct { + Documentation *[]File `yaml:"documentation,omitempty"` + Models []Model `yaml:"models"` + Repos []Repo `yaml:"repos"` + Simulations []Simulation `yaml:"simulations"` + Tools []Tool `yaml:"tools"` +} +type Model struct { + Arch *string `yaml:"arch,omitempty"` + Channels *[]Channel `yaml:"channels,omitempty"` + Name string `yaml:"name"` + Repo string `yaml:"repo"` + Schema *string `yaml:"schema,omitempty"` + Version string `yaml:"version"` +} +type ModelInstanceDefinition struct { + Channels []Channel `yaml:"channels"` + Files *[]File `yaml:"files,omitempty"` + Model string `yaml:"model"` + Name string `yaml:"name"` +} +type Repo struct { + Name string `yaml:"name"` + Path *string `yaml:"path,omitempty"` + Registry *string `yaml:"registry,omitempty"` + Repo *string `yaml:"repo,omitempty"` + Token string `yaml:"token"` + User string `yaml:"user"` +} +type Simulation struct { + Files *[]File `yaml:"files,omitempty"` + Models []ModelInstanceDefinition `yaml:"models"` + Name string `yaml:"name"` + Parameters *struct { + Environment *map[string]string `yaml:"environment,omitempty"` + Transport SimulationParametersTransport `yaml:"transport"` + } `yaml:"parameters,omitempty"` +} +type SimulationParametersTransport string +type Tool struct { + Arch *[]string `yaml:"arch,omitempty"` + Name string `yaml:"name"` + Repo *string `yaml:"repo,omitempty"` + Schema *string `yaml:"schema,omitempty"` + Version string `yaml:"version"` +} diff --git a/code/go/dse/kind/Model.yaml.go b/code/go/dse/kind/Model.go similarity index 100% rename from code/go/dse/kind/Model.yaml.go rename to code/go/dse/kind/Model.go diff --git a/code/go/dse/kind/Network.go b/code/go/dse/kind/Network.go new file mode 100644 index 0000000..9e561c3 --- /dev/null +++ b/code/go/dse/kind/Network.go @@ -0,0 +1,34 @@ +package kind + +import () + +const ( + NetworkKindNetwork NetworkKind = "Network" +) + +type Function struct { + Annotations *Annotations `yaml:"annotations,omitempty"` + Function string `yaml:"function"` +} +type Message struct { + Annotations *Annotations `yaml:"annotations,omitempty"` + Functions *struct { + Decode *[]Function `yaml:"decode,omitempty"` + Encode *[]Function `yaml:"encode,omitempty"` + } `yaml:"functions,omitempty"` + Message string `yaml:"message"` + Signals *[]NetworkSignal `yaml:"signals,omitempty"` +} +type Network struct { + Kind NetworkKind `yaml:"kind"` + Metadata *ObjectMetadata `yaml:"metadata,omitempty"` + Spec NetworkSpec `yaml:"spec"` +} +type NetworkKind string +type NetworkSignal struct { + Annotations *Annotations `yaml:"annotations,omitempty"` + Signal string `yaml:"signal"` +} +type NetworkSpec struct { + Messages []Message `yaml:"messages"` +} diff --git a/code/go/dse/kind/ParameterSet.yaml.go b/code/go/dse/kind/ParameterSet.go similarity index 100% rename from code/go/dse/kind/ParameterSet.yaml.go rename to code/go/dse/kind/ParameterSet.go diff --git a/code/go/dse/kind/Propagator.yaml.go b/code/go/dse/kind/Propagator.go similarity index 100% rename from code/go/dse/kind/Propagator.yaml.go rename to code/go/dse/kind/Propagator.go diff --git a/code/go/dse/kind/Runnable.yaml.go b/code/go/dse/kind/Runnable.go similarity index 100% rename from code/go/dse/kind/Runnable.yaml.go rename to code/go/dse/kind/Runnable.go diff --git a/code/go/dse/kind/SignalGroup.yaml.go b/code/go/dse/kind/SignalGroup.go similarity index 100% rename from code/go/dse/kind/SignalGroup.yaml.go rename to code/go/dse/kind/SignalGroup.go diff --git a/code/go/dse/kind/Stack.yaml.go b/code/go/dse/kind/Stack.go similarity index 100% rename from code/go/dse/kind/Stack.yaml.go rename to code/go/dse/kind/Stack.go diff --git a/code/go/dse/kind/channel.yaml.go b/code/go/dse/kind/channel.go similarity index 100% rename from code/go/dse/kind/channel.yaml.go rename to code/go/dse/kind/channel.go diff --git a/code/go/dse/config.yaml b/code/go/dse/kind/config.yaml similarity index 100% rename from code/go/dse/config.yaml rename to code/go/dse/kind/config.yaml diff --git a/code/go/dse/kind/kind.go b/code/go/dse/kind/kind.go index 08c931c..eb1ae7c 100644 --- a/code/go/dse/kind/kind.go +++ b/code/go/dse/kind/kind.go @@ -1 +1 @@ -package kind +package kind diff --git a/code/go/dse/kind/metadata.yaml.go b/code/go/dse/kind/metadata.go similarity index 100% rename from code/go/dse/kind/metadata.yaml.go rename to code/go/dse/kind/metadata.go