From 4a21ca72e29ebf734420fe53a8541ca13bc872cf Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Thu, 9 Jan 2014 16:44:57 -0500 Subject: [PATCH] Generates stubs for operations --- README.md | 25 +++++++++++++++++++++++++ gowsdl.go | 32 ++++++++++++++++++++++++++++++++ operations_tmpl.go | 12 +++++++++++- types_tmpl.go | 1 - 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e69de29..73e086e 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,25 @@ +# WSDL to Go +Generates Go code from a WSDL file. This project is originally intended to generate Go clients for WS-* services. + +### Features +* Supports only Document/Literal wrapped services, which are [WS-I](http://ws-i.org/) compliant +* Attempts to generate idiomatic Go code as much as possible +* Generates Go code in parallel: types, operations and soap proxy +* Supports: + * WSDL 1.1 + * XML Schema 1.0 + * SOAP 1.1 +* Resolves external XML Schemas recursively, up to 5 recursions. +* Supports providing WSDL HTTP URL as well as a local WSDL file + + +### TODO +* If WSDL file is local, resolve external XML schemas locally too instead of failing due to not having a URL to download them from. +* Resolve XSD element references +* Support for generating namespaces +* Make code generation agnostic so generating code to other programming languages is feasible through plugins + + +## License +Copyright 2014 Cloudescape. All rights reserved. + diff --git a/gowsdl.go b/gowsdl.go index 1e66ecb..724a359 100644 --- a/gowsdl.go +++ b/gowsdl.go @@ -266,6 +266,7 @@ func (g *GoWsdl) genOperations() ([]byte, error) { "stripns": stripns, "replaceReservedWords": replaceReservedWords, "makeFieldPublic": makeFieldPublic, + "findType": g.findType, } data := new(bytes.Buffer) @@ -357,6 +358,37 @@ func toGoType(xsdType string) string { return "*" + type_ } +//I'm not very proud of this function but +//it works for now and performance doesn't +//seem critical at this point +func (g *GoWsdl) findType(message string) string { + message = stripns(message) + for _, msg := range g.wsdl.Messages { + if msg.Name != message { + continue + } + + //Assumes document/literal wrapped WS-I + part := msg.Parts[0] + if part.Type != "" { + return stripns(part.Type) + } + + elRef := stripns(part.Element) + for _, schema := range g.wsdl.Types.Schemas { + for _, el := range schema.Elements { + if elRef == el.Name { + if el.Type != "" { + return stripns(el.Type) + } + return el.Name + } + } + } + } + return "" +} + //TODO: Add namespace support instead of stripping it func stripns(xsdType string) string { r := strings.Split(xsdType, ":") diff --git a/operations_tmpl.go b/operations_tmpl.go index 75dfc82..21da12e 100644 --- a/operations_tmpl.go +++ b/operations_tmpl.go @@ -1,6 +1,16 @@ package main var opsTmpl = ` -{{range .Operations}} +{{range .}} + {{$portType := .Name}} + type {{$portType}} struct { + client *SoapClient + } + + {{range .Operations}} + func (service *{{$portType}}) {{.Name}} (request *{{findType .Input.Message}}) (*{{findType .Output.Message}}, error) { + return nil, nil + } + {{end}} {{end}} ` diff --git a/types_tmpl.go b/types_tmpl.go index 9af7af2..7ad5586 100644 --- a/types_tmpl.go +++ b/types_tmpl.go @@ -14,7 +14,6 @@ var typesTmpl = ` {{define "ComplexTypeGlobal"}} {{$name := replaceReservedWords .Name}} - type {{$name}} struct { {{if ne .ComplexContent.Extension.Base ""}} {{$baseType := .ComplexContent.Extension.Base}}