Skip to content

Commit 4a21ca7

Browse files
committed
Generates stubs for operations
1 parent a6f7a25 commit 4a21ca7

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# WSDL to Go
2+
Generates Go code from a WSDL file. This project is originally intended to generate Go clients for WS-* services.
3+
4+
### Features
5+
* Supports only Document/Literal wrapped services, which are [WS-I](http://ws-i.org/) compliant
6+
* Attempts to generate idiomatic Go code as much as possible
7+
* Generates Go code in parallel: types, operations and soap proxy
8+
* Supports:
9+
* WSDL 1.1
10+
* XML Schema 1.0
11+
* SOAP 1.1
12+
* Resolves external XML Schemas recursively, up to 5 recursions.
13+
* Supports providing WSDL HTTP URL as well as a local WSDL file
14+
15+
16+
### TODO
17+
* If WSDL file is local, resolve external XML schemas locally too instead of failing due to not having a URL to download them from.
18+
* Resolve XSD element references
19+
* Support for generating namespaces
20+
* Make code generation agnostic so generating code to other programming languages is feasible through plugins
21+
22+
23+
## License
24+
Copyright 2014 Cloudescape. All rights reserved.
25+

gowsdl.go

+32
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func (g *GoWsdl) genOperations() ([]byte, error) {
266266
"stripns": stripns,
267267
"replaceReservedWords": replaceReservedWords,
268268
"makeFieldPublic": makeFieldPublic,
269+
"findType": g.findType,
269270
}
270271

271272
data := new(bytes.Buffer)
@@ -357,6 +358,37 @@ func toGoType(xsdType string) string {
357358
return "*" + type_
358359
}
359360

361+
//I'm not very proud of this function but
362+
//it works for now and performance doesn't
363+
//seem critical at this point
364+
func (g *GoWsdl) findType(message string) string {
365+
message = stripns(message)
366+
for _, msg := range g.wsdl.Messages {
367+
if msg.Name != message {
368+
continue
369+
}
370+
371+
//Assumes document/literal wrapped WS-I
372+
part := msg.Parts[0]
373+
if part.Type != "" {
374+
return stripns(part.Type)
375+
}
376+
377+
elRef := stripns(part.Element)
378+
for _, schema := range g.wsdl.Types.Schemas {
379+
for _, el := range schema.Elements {
380+
if elRef == el.Name {
381+
if el.Type != "" {
382+
return stripns(el.Type)
383+
}
384+
return el.Name
385+
}
386+
}
387+
}
388+
}
389+
return ""
390+
}
391+
360392
//TODO: Add namespace support instead of stripping it
361393
func stripns(xsdType string) string {
362394
r := strings.Split(xsdType, ":")

operations_tmpl.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
package main
22

33
var opsTmpl = `
4-
{{range .Operations}}
4+
{{range .}}
5+
{{$portType := .Name}}
6+
type {{$portType}} struct {
7+
client *SoapClient
8+
}
9+
10+
{{range .Operations}}
11+
func (service *{{$portType}}) {{.Name}} (request *{{findType .Input.Message}}) (*{{findType .Output.Message}}, error) {
12+
return nil, nil
13+
}
14+
{{end}}
515
{{end}}
616
`

types_tmpl.go

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var typesTmpl = `
1414
1515
{{define "ComplexTypeGlobal"}}
1616
{{$name := replaceReservedWords .Name}}
17-
1817
type {{$name}} struct {
1918
{{if ne .ComplexContent.Extension.Base ""}}
2019
{{$baseType := .ComplexContent.Extension.Base}}

0 commit comments

Comments
 (0)