Skip to content
Closed
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
27 changes: 6 additions & 21 deletions pkg/concepts/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,12 @@ func (m *Method) IsAsyncUpdate() bool {
// IsAction determined if this method is an action instead of a regular REST method.
func (m *Method) IsAction() bool {
switch {
case m.IsAdd():
return false
case m.IsAsyncAdd():
return false
case m.IsDelete():
return false
case m.IsAsyncDelete():
return false
case m.IsGet():
return false
case m.IsList():
return false
case m.IsPost():
return false
case m.IsAsyncPost():
return false
case m.IsSearch():
return false
case m.IsUpdate():
return false
case m.IsAsyncUpdate():
case m.IsAdd(), m.IsAsyncAdd(),
m.IsDelete(), m.IsAsyncDelete(),
m.IsGet(), m.IsList(),
m.IsPost(), m.IsAsyncPost(),
m.IsUpdate(), m.IsAsyncUpdate(),
m.IsSearch():
return false
default:
return true
Expand Down
4 changes: 1 addition & 3 deletions pkg/generators/golang/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ func (b *Buffer) byteArray(data []byte) string {
// `-go` suffix if present, and removing any dashes. For example, the string `ocm-sdk-go` will be
// translated into `sdk`.
func (b *Buffer) cleanPkg(name string) string {
if strings.HasSuffix(name, "-go") {
name = name[0 : len(name)-3]
}
strings.TrimSuffix(name, "-go")
index := strings.LastIndex(name, "-")
if index > 0 {
name = name[index+1:]
Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/golang/clients_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ func (g *ClientsGenerator) generateVersionMetadataClient(version *concepts.Versi
}

// Generate the code:
g.generateVersionMetadataClientSource(version)
g.generateVersionMetadataClientSource()

// Write the generated code:
return g.buffer.Write()
}

func (g *ClientsGenerator) generateVersionMetadataClientSource(version *concepts.Version) {
func (g *ClientsGenerator) generateVersionMetadataClientSource() {
g.buffer.Import("bufio", "")
g.buffer.Import("context", "")
g.buffer.Import("io", "")
Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/golang/json_alias_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package golang

import (
"fmt"

"github.com/openshift-online/ocm-api-metamodel/pkg/concepts"
"github.com/openshift-online/ocm-api-metamodel/pkg/http"
"github.com/openshift-online/ocm-api-metamodel/pkg/names"
Expand Down Expand Up @@ -308,13 +309,12 @@ func (g *JSONSupportAliasGenerator) generateListTypeAliasSupport(version *concep
g.buffer.Import(g.packages.APIVersionImport(version), g.packages.APIVersionSelector(version))

// Generate the code:
g.generateListTypeAliasSource(version, typ)
g.generateListTypeAliasSource(typ)
// Write the generated code:
return g.buffer.Write()
}

func (g *JSONSupportAliasGenerator) generateListTypeAliasSource(
version *concepts.Version,
typ *concepts.Type,
) {
var linkOwner *concepts.Version
Expand Down
154 changes: 0 additions & 154 deletions pkg/generators/golang/json_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package golang

import (
"fmt"
"strconv"

"github.com/openshift-online/ocm-api-metamodel/pkg/annotations"
"github.com/openshift-online/ocm-api-metamodel/pkg/concepts"
Expand Down Expand Up @@ -902,46 +901,6 @@ func (g *JSONSupportGenerator) generateReadValue(variable string, typ *concepts.
)
}

func (g *JSONSupportGenerator) generateWriteBodyParameter(object string,
parameter *concepts.Parameter,
) string {
typ := parameter.Type()
field := g.parameterFieldName(parameter)
tag := g.binding.BodyParameterName(parameter)
var value string
var linkOwner *concepts.Version
if typ.IsScalar() && !typ.IsInterface() {
value = g.buffer.Eval(
`*{{ .Object }}.{{ .Field }}`,
"Object", object,
"Field", field,
)
} else {
value = g.buffer.Eval(
`{{ .Object }}.{{ .Field }}`,
"Object", object,
"Field", field,
)
}
return g.buffer.Eval(`
if {{ .Object }}.{{ .Field }} != nil {
if count > 0 {
stream.WriteMore()
}
stream.WriteObjectField("{{ .Tag }}")
{{ generateWriteValue .Value .Type false .LinkOwner }}
count++
}
`,
"Object", object,
"Field", field,
"Tag", tag,
"Value", value,
"Type", typ,
"LinkOwner", linkOwner,
)
}

func (g *JSONSupportGenerator) generateWriteValue(value string,
typ *concepts.Type,
link bool,
Expand Down Expand Up @@ -1019,10 +978,6 @@ func (g *JSONSupportGenerator) typeFile(typ *concepts.Type) string {
return g.names.File(names.Cat(typ.Name(), nomenclator.Type, nomenclator.JSON))
}

func (g *JSONSupportGenerator) resourceFile(resource *concepts.Resource) string {
return g.names.File(names.Cat(resource.Name(), nomenclator.Resource, nomenclator.JSON))
}

func (g *JSONSupportGenerator) marshalTypeFunc(typ *concepts.Type) string {
name := annotations.GoName(typ)
if name == "" {
Expand Down Expand Up @@ -1073,115 +1028,6 @@ func (g *JSONSupportGenerator) fieldName(attribute *concepts.Attribute) string {
return g.names.Private(attribute.Name())
}

func (g *JSONSupportGenerator) parameterFieldName(parameter *concepts.Parameter) string {
return g.names.Private(parameter.Name())
}

func (g *JSONSupportGenerator) clientRequestName(method *concepts.Method) string {
resource := method.Owner()
var name string
if resource.IsRoot() {
name = annotations.GoName(method)
if name == "" {
name = g.names.Public(method.Name())
}
} else {
resourceName := annotations.GoName(resource)
if resourceName == "" {
resourceName = g.names.Public(resource.Name())
}
methodName := annotations.GoName(method)
if methodName == "" {
methodName = g.names.Public(method.Name())
}
name = resourceName + methodName
}
name += "Request"
return name
}

func (g *JSONSupportGenerator) clientResponseName(method *concepts.Method) string {
resource := method.Owner()
var name string
if resource.IsRoot() {
name = annotations.GoName(method)
if name == "" {
name = g.names.Public(method.Name())
}
} else {
resourceName := annotations.GoName(resource)
if resourceName == "" {
resourceName = g.names.Public(resource.Name())
}
methodName := annotations.GoName(method)
if methodName == "" {
methodName = g.names.Public(method.Name())
}
name = resourceName + methodName
}
name += "Response"
return name
}

func (g *JSONSupportGenerator) writeRequestFunc(method *concepts.Method) string {
resource := method.Owner()
var name *names.Name
if resource.IsRoot() {
name = names.Cat(
nomenclator.Write,
method.Name(),
nomenclator.Request,
)
} else {
name = names.Cat(
nomenclator.Write,
resource.Name(),
method.Name(),
nomenclator.Request,
)
}
return g.names.Private(name)
}

func (g *JSONSupportGenerator) readResponseFunc(method *concepts.Method) string {
resource := method.Owner()
var name *names.Name
if resource.IsRoot() {
name = names.Cat(
nomenclator.Read,
method.Name(),
nomenclator.Response,
)
} else {
name = names.Cat(
nomenclator.Read,
resource.Name(),
method.Name(),
nomenclator.Response,
)
}
return g.names.Private(name)
}

func (g *JSONSupportGenerator) defaultValue(parameter *concepts.Parameter) string {
switch value := parameter.Default().(type) {
case nil:
return "nil"
case bool:
return strconv.FormatBool(value)
case int:
return strconv.FormatInt(int64(value), 10)
case string:
return strconv.Quote(value)
default:
g.reporter.Errorf(
"Don't know how to render default value '%v' for parameter '%s'",
value, parameter,
)
return ""
}
}

func (g JSONSupportGenerator) selectorFromLinkOwner(linkOwner *concepts.Version) string {
if linkOwner == nil {
return ""
Expand Down
Loading