Skip to content

Commit

Permalink
Intermediate commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bdragon300 committed Dec 4, 2024
1 parent 26cd0cb commit b56b78b
Show file tree
Hide file tree
Showing 106 changed files with 797 additions and 795 deletions.
2 changes: 0 additions & 2 deletions cmd/go-asyncapi/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ type generatePubSubArgs struct {

ProjectModule string `arg:"-M,--project-module" help:"Project module name to use [default: extracted from go.mod file in the current working directory]" placeholder:"MODULE"`
TargetPackage string `arg:"-T,--target-package" help:"Package for generated code [default: {target-dir-name}]" placeholder:"PACKAGE"`
//PackageScope string `arg:"--package-scope" default:"type" help:"How to split up the generated code on packages. Possible values: type, all" placeholder:"SCOPE"`
//FileScope string `arg:"--file-scope" default:"name" help:"How to split up the generated code on files inside packages. Possible values: name, type" placeholder:"SCOPE"`
TemplateDir string `arg:"--template-dir" help:"Directory with custom templates" placeholder:"DIR"`
generateObjectSelectionOpts
ImplementationsOpts
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/amqp/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/amqp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/asyncapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (a AsyncAPI) Compile(ctx *common.CompileContext) error {
}

func (a AsyncAPI) build(ctx *common.CompileContext) *render.AsyncAPI {
allMessagesPrm := lang.NewListCbPromise[*render.Message](func(item common.Renderer, _ []string) bool {
allMessagesPrm := lang.NewListCbPromise[*render.Message](func(item common.Renderable, _ []string) bool {
_, ok := item.(*render.Message)
return ok
})
Expand Down
4 changes: 2 additions & 2 deletions internal/asyncapi/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func (b *Bindings) build(
ctx *common.CompileContext,
bindingsKind int,
bindingsKey string,
) (common.Renderer, error) {
) (common.Renderable, error) {
if b.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", b.Ref)
res := lang.NewRendererPromise(b.Ref, common.PromiseOriginUser)
res := lang.NewRenderablePromise(b.Ref, common.PromiseOriginUser)
ctx.PutPromise(res)
return res, nil
}
Expand Down
10 changes: 5 additions & 5 deletions internal/asyncapi/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (c Channel) Compile(ctx *common.CompileContext) error {
return nil
}

func (c Channel) buildChannels(ctx *common.CompileContext, channelKey string) ([]common.Renderer, error) {
var res []common.Renderer
func (c Channel) buildChannels(ctx *common.CompileContext, channelKey string) ([]common.Renderable, error) {
var res []common.Renderable

_, isComponent := ctx.Stack.Top().Flags[common.SchemaTagComponent]
ignore := c.XIgnore ||
Expand All @@ -51,7 +51,7 @@ func (c Channel) buildChannels(ctx *common.CompileContext, channelKey string) ([
}
if c.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", c.Ref)
prm := lang.NewRendererPromise(c.Ref, common.PromiseOriginUser)
prm := lang.NewRenderablePromise(c.Ref, common.PromiseOriginUser)
// Set a channel to be rendered if we reference it from `channels` document section
prm.DirectRender = !isComponent
ctx.PutPromise(prm)
Expand Down Expand Up @@ -95,7 +95,7 @@ func (c Channel) buildChannels(ctx *common.CompileContext, channelKey string) ([
if c.Servers != nil {
ctx.Logger.Trace("Channel servers", "names", *c.Servers)
baseChan.SpecServerNames = *c.Servers
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderer, path []string) bool {
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderable, path []string) bool {
srv, ok := item.(*render.Server)
if !ok {
return false
Expand All @@ -105,7 +105,7 @@ func (c Channel) buildChannels(ctx *common.CompileContext, channelKey string) ([
baseChan.ServersPromise = prm
} else {
ctx.Logger.Trace("Channel for all servers")
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderer, path []string) bool {
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderable, path []string) bool {
_, ok := item.(*render.Server)
return ok
})
Expand Down
4 changes: 2 additions & 2 deletions internal/asyncapi/correlationid.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c CorrelationID) Compile(ctx *common.CompileContext) error {
return nil
}

func (c CorrelationID) build(ctx *common.CompileContext, correlationIDKey string) (common.Renderer, error) {
func (c CorrelationID) build(ctx *common.CompileContext, correlationIDKey string) (common.Renderable, error) {
ignore := c.XIgnore || !ctx.CompileOpts.MessageOpts.Enable
if ignore {
ctx.Logger.Debug("CorrelationID denoted to be ignored")
Expand All @@ -41,7 +41,7 @@ func (c CorrelationID) build(ctx *common.CompileContext, correlationIDKey string
// TODO: move this ref code from everywhere to single place?
if c.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", c.Ref)
res := lang.NewRendererPromise(c.Ref, common.PromiseOriginUser)
res := lang.NewRenderablePromise(c.Ref, common.PromiseOriginUser)
ctx.PutPromise(res)
return res, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/http/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/ip/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/ip/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/kafka/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/kafka/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/asyncapi/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (m Message) Compile(ctx *common.CompileContext) error {
return nil
}

func (m Message) build(ctx *common.CompileContext, messageKey string) ([]common.Renderer, error) {
var res []common.Renderer
func (m Message) build(ctx *common.CompileContext, messageKey string) ([]common.Renderable, error) {
var res []common.Renderable

_, isComponent := ctx.Stack.Top().Flags[common.SchemaTagComponent]
ignore := m.XIgnore || (isComponent && !ctx.CompileOpts.MessageOpts.IsAllowedName(messageKey))
Expand All @@ -64,7 +64,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) ([]common.
}
if m.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", m.Ref)
prm := lang.NewRendererPromise(m.Ref, common.PromiseOriginUser)
prm := lang.NewRenderablePromise(m.Ref, common.PromiseOriginUser)
ctx.PutPromise(prm)
res = append(res, prm)
return res, nil
Expand Down Expand Up @@ -103,7 +103,7 @@ func (m Message) build(ctx *common.CompileContext, messageKey string) ([]common.
ctx.Logger.Trace(fmt.Sprintf("Message content type is %q", baseMessage.ContentType))

// Lookup servers after linking to figure out all protocols the message is used in
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderer, path []string) bool {
prm := lang.NewListCbPromise[*render.Server](func(item common.Renderable, path []string) bool {
_, ok := item.(*render.Server)
return ok
})
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/mqtt/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/mqtt/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
7 changes: 3 additions & 4 deletions internal/asyncapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ func (o Object) build(ctx *common.CompileContext, flags map[common.SchemaTag]str
nullable = nullable || lo.FromPtr(o.XNullable)
if nullable {
ctx.Logger.Trace("Object is nullable, make it pointer")
_, hasDefinition := flags[common.SchemaTagDefinition]
golangType = &lang.GoPointer{Type: golangType, HasDefinition: hasDefinition}
golangType = &lang.GoPointer{Type: golangType}
}
return golangType, nil
}
Expand Down Expand Up @@ -251,7 +250,7 @@ func (o Object) buildLangStruct(ctx *common.CompileContext, flags map[common.Sch
var messagesPrm *lang.ListPromise[*render.Message]
_, isMarshal := flags[common.SchemaTagMarshal]
if isMarshal {
messagesPrm = lang.NewListCbPromise[*render.Message](func(item common.Renderer, _ []string) bool {
messagesPrm = lang.NewListCbPromise[*render.Message](func(item common.Renderable, _ []string) bool {
_, ok := item.(*render.Message)
return ok
})
Expand Down Expand Up @@ -409,7 +408,7 @@ func (o Object) buildUnionStruct(ctx *common.CompileContext, flags map[common.Sc
}

// Collect all messages to retrieve struct field tags
messagesPrm := lang.NewListCbPromise[*render.Message](func(item common.Renderer, _ []string) bool {
messagesPrm := lang.NewListCbPromise[*render.Message](func(item common.Renderable, _ []string) bool {
_, ok := item.(*render.Message)
return ok
})
Expand Down
4 changes: 2 additions & 2 deletions internal/asyncapi/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func (p Parameter) Compile(ctx *common.CompileContext) error {
return nil
}

func (p Parameter) build(ctx *common.CompileContext, parameterKey string) (common.Renderer, error) {
func (p Parameter) build(ctx *common.CompileContext, parameterKey string) (common.Renderable, error) {
ignore := !ctx.CompileOpts.ChannelOpts.Enable
if ignore {
ctx.Logger.Debug("Parameter denoted to be ignored along with all channels")
return &render.Parameter{Dummy: true}, nil
}
if p.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", p.Ref)
res := lang.NewRendererPromise(p.Ref, common.PromiseOriginUser)
res := lang.NewRenderablePromise(p.Ref, common.PromiseOriginUser)
ctx.PutPromise(res)
return res, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/redis/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/redis/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/asyncapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s Server) Compile(ctx *common.CompileContext) error {
return nil
}

func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Renderer, error) {
func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Renderable, error) {
_, isComponent := ctx.Stack.Top().Flags[common.SchemaTagComponent]
ignore := s.XIgnore || !ctx.CompileOpts.ServerOpts.IsAllowedName(serverKey)
if ignore {
Expand All @@ -46,7 +46,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend
}
if s.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", s.Ref)
prm := lang.NewRendererPromise(s.Ref, common.PromiseOriginUser)
prm := lang.NewRenderablePromise(s.Ref, common.PromiseOriginUser)
// Set a server to be rendered if we reference it from `servers` document section
prm.DirectRender = !isComponent
ctx.PutPromise(prm)
Expand All @@ -65,7 +65,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend
}

// Channels which are connected to this server
prm := lang.NewListCbPromise[*render.Channel](func(item common.Renderer, path []string) bool {
prm := lang.NewListCbPromise[*render.Channel](func(item common.Renderable, path []string) bool {
_, ok := item.(*render.Channel)
if !ok {
return false
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s Server) build(ctx *common.CompileContext, serverKey string) (common.Rend
if err != nil {
return nil, err
}
return &render.ProtoServer{Server: &baseServer, Struct: protoStruct}, nil
return &render.ProtoServer{Server: &baseServer, Type: protoStruct}, nil
}

ctx.Logger.Trace("Server", "proto", protoBuilder.ProtocolName())
Expand Down
4 changes: 2 additions & 2 deletions internal/asyncapi/servervariable.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func (sv ServerVariable) Compile(ctx *common.CompileContext) error {
return nil
}

func (sv ServerVariable) build(ctx *common.CompileContext, serverVariableKey string) (common.Renderer, error) {
func (sv ServerVariable) build(ctx *common.CompileContext, serverVariableKey string) (common.Renderable, error) {
if sv.Ref != "" {
ctx.Logger.Trace("Ref", "$ref", sv.Ref)
res := lang.NewRendererPromise(sv.Ref, common.PromiseOriginUser)
res := lang.NewRenderablePromise(sv.Ref, common.PromiseOriginUser)
ctx.PutPromise(res)
return res, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/tcp/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/udp/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/udp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/asyncapi/ws/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func (pb ProtoBuilder) BuildChannel(ctx *common.CompileContext, channel *asyncap

return &render.ProtoChannel{
Channel: parent,
GolangNameProto: golangName,
Struct: chanStruct,
Type: chanStruct,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/asyncapi/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (pb ProtoBuilder) BuildServer(ctx *common.CompileContext, server *asyncapi.
}
return &render.ProtoServer{
Server: parent,
Struct: baseServer,
Type: baseServer,
ProtoName: pb.ProtoName,
}, nil
}
Expand Down
Loading

0 comments on commit b56b78b

Please sign in to comment.