Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add asyncapi document version #115

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,15 @@ you can specify your own header with the option `WithVersionHeaderKey`.
vw := versioning.NewWrapper(broker, versioning.WithVersionHeaderKey("my-version-key"))
```

#### Knowing generated version

If you want to use the version of the AsyncAPI document used, you can access the constant
`AsyncAPIVersion` that is generated with the types. It is generated as followed:

```go
const AsyncAPIVersion = "{{ .Info.Version }}"
```

### AsyncAPI Extensions

#### Schema Object extensions
Expand Down Expand Up @@ -764,7 +773,7 @@ These extension properties apply to "Schema Objects" in AsyncAPI spec.
flag:
type: integer
x-go-type: mypackage.Flag
x-go-type-import:
x-go-type-import:
path: abc.xyz/repo/mypackage
```

Expand All @@ -791,7 +800,7 @@ These extension properties apply to "Schema Objects" in AsyncAPI spec.
flag:
type: integer
x-go-type: alias.Flag
x-go-type-import:
x-go-type-import:
path: abc.xyz/repo/mypackage
name: alias
```
Expand Down
3 changes: 3 additions & 0 deletions examples/helloworld/nats/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/helloworld/nats/user/user.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/ping/kafka/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/ping/kafka/user/user.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/ping/nats/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/ping/nats/user/user.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/codegen/generators/templates/types.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// AsyncAPIVersion is the version of the used AsyncAPI document
const AsyncAPIVersion = "{{ .Info.Version }}"

// controller is the controller that will be used to communicate with the broker
// It will be used internally by AppController and UserController
type controller struct {
Expand Down
3 changes: 3 additions & 0 deletions test/issues/101/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions test/issues/114/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/issues/114/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Issue: https://github.com/lerenn/asyncapi-codegen/issues/114

# AsyncAPI document version should be generated.

# This test makes sure that it does.

asyncapi: 2.6.0
info:
title: Sample App
version: 1.2.3
channels:
/status:
subscribe:
message:
payload:
type: string
21 changes: 21 additions & 0 deletions test/issues/114/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:generate go run ../../../cmd/asyncapi-codegen -g types -p issue114 -i ./asyncapi.yaml -o ./asyncapi.gen.go

package issue114

import (
"testing"

"github.com/stretchr/testify/suite"
)

func TestSuite(t *testing.T) {
suite.Run(t, new(Suite))
}

type Suite struct {
suite.Suite
}

func (suite *Suite) TestCorrectVersion() {
suite.Require().Equal("1.2.3", AsyncAPIVersion)
}
3 changes: 3 additions & 0 deletions test/issues/49/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/issues/73/v1/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/issues/73/v2/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/issues/74/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/issues/97/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/issues/99/asyncapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.