Skip to content

Commit

Permalink
Handle nil function input / output (fiorix#131)
Browse files Browse the repository at this point in the history
Handle nil function input
  • Loading branch information
denysvitali authored Mar 30, 2020
1 parent 3f1d7d7 commit 5100b2d
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions wsdlgo/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go/parser"
"go/token"
"io"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -712,10 +713,14 @@ func (ge *goEncoder) writeSOAPFunc(w io.Writer, d *wsdl.Definitions, op *wsdl.Op
retDefaults[len(retDefaults)-1] = "err"

// Check if we need to prefix the op with a namespace
mInput := ge.funcs[op.Name].Input
namespacedOpName := op.Name
nsSplit := strings.Split(ge.funcs[op.Name].Input.Message, ":")
if len(nsSplit) > 1 {
namespacedOpName = nsSplit[0] + ":" + namespacedOpName

if mInput != nil {
nsSplit := strings.Split(mInput.Message, ":")
if len(nsSplit) > 1 {
namespacedOpName = nsSplit[0] + ":" + namespacedOpName
}
}

// The response name is always the operation name + "Response" according to specification.
Expand Down Expand Up @@ -1362,17 +1367,27 @@ func (ge *goEncoder) genGoStruct(w io.Writer, d *wsdl.Definitions, ct *wsdl.Comp

func (ge *goEncoder) genGoOpStruct(w io.Writer, d *wsdl.Definitions, bo *wsdl.BindingOperation) error {
name := goSymbol(bo.Name)
function := ge.funcs[name]

inputMessage := ge.messages[trimns(ge.funcs[bo.Name].Input.Message)]
if function.Input == nil {
log.Printf("function input is nil! %v is %v", name, function)
} else {
message := trimns(function.Input.Message)
inputMessage := ge.messages[message]

// No-Op on operations which don't take arguments
// (These can be inlined, and don't need to pollute the file)
if len(inputMessage.Parts) > 0 {
ge.genOpStructMessage(w, d, name, inputMessage)
// No-Op on operations which don't take arguments
// (These can be inlined, and don't need to pollute the file)
if len(inputMessage.Parts) > 0 {
ge.genOpStructMessage(w, d, name, inputMessage)
}
}

// Output messages are always required
ge.genOpStructMessage(w, d, name, ge.messages[trimns(ge.funcs[bo.Name].Output.Message)])
if function.Output == nil {
log.Printf("function output is nil! %v is %v", name, function)
} else {
// Output messages are always required
ge.genOpStructMessage(w, d, name, ge.messages[trimns(ge.funcs[bo.Name].Output.Message)])
}

return nil
}
Expand Down

0 comments on commit 5100b2d

Please sign in to comment.