Skip to content

Commit

Permalink
Generates stubs for operations
Browse files Browse the repository at this point in the history
  • Loading branch information
c4milo committed Jan 9, 2014
1 parent a6f7a25 commit 4a21ca7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

32 changes: 32 additions & 0 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (g *GoWsdl) genOperations() ([]byte, error) {
"stripns": stripns,
"replaceReservedWords": replaceReservedWords,
"makeFieldPublic": makeFieldPublic,
"findType": g.findType,
}

data := new(bytes.Buffer)
Expand Down Expand Up @@ -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, ":")
Expand Down
12 changes: 11 additions & 1 deletion operations_tmpl.go
Original file line number Diff line number Diff line change
@@ -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}}
`
1 change: 0 additions & 1 deletion types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var typesTmpl = `
{{define "ComplexTypeGlobal"}}
{{$name := replaceReservedWords .Name}}
type {{$name}} struct {
{{if ne .ComplexContent.Extension.Base ""}}
{{$baseType := .ComplexContent.Extension.Base}}
Expand Down

0 comments on commit 4a21ca7

Please sign in to comment.