Skip to content

Commit

Permalink
Generate the SDK, implement v0.2.0
Browse files Browse the repository at this point in the history
Add the generator tool which generates a large part of the SDK
surface from the JSON schemas defined in the spec repo.

Define a new test-only event which is used to run SDK unit tests
independent from the actual events defined in the spec.

Add a new, mostly generated, examples test. This test verifies
that the SDK can be used to generate the examples defined in the
spec repository, and excercises the code automatically generated
from the schemas.

Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
  • Loading branch information
afrittoli committed Mar 28, 2023
1 parent 5fdad60 commit 918bccb
Show file tree
Hide file tree
Showing 110 changed files with 3,587 additions and 2,555 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.52
- name: Check generated code
run: make generate

test:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ get-fmt-deps: ## Install test dependencies
lint: ## Lint the code
./hack/gofmt.sh
./hack/linter.sh

.PHONY: generate # Regenerate code
generate:
./hack/generate.sh

.PHONY: all
all: fmt test lint
all: fmt test lint generate
193 changes: 0 additions & 193 deletions hack/add-event.sh

This file was deleted.

33 changes: 0 additions & 33 deletions hack/add-events.sh

This file was deleted.

11 changes: 11 additions & 0 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ fi

echo "Running validation scripts..."

function cleanupAndGenerate() {
find . -name 'zz_*' -exec rm {} +
go run tools/generator.go
GIT_STATUS=$(git status -s)
if [[ ! -z $GIT_STATUS ]]; then
echo -e "Changes detected:\n$GIT_STATUS"
return 1
fi
}

scripts=(
cleanupAndGenerate
)
fail=0
for s in "${scripts[@]}"; do
Expand Down
91 changes: 0 additions & 91 deletions main.go

This file was deleted.

15 changes: 12 additions & 3 deletions pkg/api/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,21 @@ func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
return &ce, err
}

// AsJsonString renders a CDEvent as a JSON string
func AsJsonString(event CDEventReader) (string, error) {
// AsJsonBytes renders a CDEvent as a JSON string
func AsJsonBytes(event CDEventReader) ([]byte, error) {
if event == nil {
return "", nil
return nil, nil
}
jsonBytes, err := json.Marshal(event)
if err != nil {
return nil, err
}
return jsonBytes, nil
}

// AsJsonString renders a CDEvent as a JSON string
func AsJsonString(event CDEventReader) (string, error) {
jsonBytes, err := AsJsonBytes(event)
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 918bccb

Please sign in to comment.