From 5100b2dfdf81439df55296dc87c32b922de87789 Mon Sep 17 00:00:00 2001 From: Denys Vitali Date: Mon, 30 Mar 2020 23:02:36 +0200 Subject: [PATCH] Handle nil function input / output (#131) Handle nil function input --- wsdlgo/encoder.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/wsdlgo/encoder.go b/wsdlgo/encoder.go index 267118c..8ee752f 100644 --- a/wsdlgo/encoder.go +++ b/wsdlgo/encoder.go @@ -13,6 +13,7 @@ import ( "go/parser" "go/token" "io" + "log" "net/http" "net/url" "os" @@ -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. @@ -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 }