gowsdl

package module
v0.0.0-...-6cd6be7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

README

WSDL to Go

wsdl

Italiano

Capace di generare codice Go direttamente da un file WSDL, per coloro che si trovano a dover affrontare l'arduo compito di lavorare con SOAP. Implementazione customizzata.

Installazione

  • Scarica la release
  • Scarica e compila localmente:
    • Go 1.15: go get github.com/Andrea-Cavallo/gowsdl/...
    • Go 1.20: go install github.com/Andrea-Cavallo/gowsdl/cmd/gowsdl@latest
  • Installa con Homebrew: brew install gowsdl

Obiettivi

  • Generare codice Go idiomatico il più possibile
  • Supportare solo servizi Document/Literal wrapped, che sono conformi a WS-I
  • Supportare:
    • WSDL 1.1
    • XML Schema 1.0
    • SOAP 1.1
  • Risolvere schemi XML esterni
  • Supportare WSDL esterni e locali

Avvertenze

  • Tieni presente che il codice generato è solo un riflesso di com'è il WSDL. Se il tuo WSDL ha definizioni di tipi duplicati, il codice Go generato avrà gli stessi e potrebbe non compilare.

Uso

Uso: gowsdl [opzioni] myservice.wsdl
  -o string
        File dove verrà salvato il codice generato (predefinito "myservice.go")
  -p string
        Pacchetto sotto il quale verrà generato il codice (predefinito "myservice")
  -i    Salta la verifica TLS
  -v    Mostra la versione di gowsdl

Esempio

Per generare il codice Go da un file WSDL denominato example.wsdl e salvare l'output in example.go:

gowsdl -o example.go example.wsdl

Esempio per richiamare il metodo client.callWithResponse..

  • ctx - il context se non lo passi viene preso il background.ctx
  • soapAction - l'azione soap una stringa
  • la request che sara' poi parsata nell'envelope soap
  • custoMheaders una mappa di headers custom
  • responseObject - un puntatore alla response che ti aspetti ( se non sei sicuro della risposta potresti anche usare : &rawResponse,un puntatore a xml.RawMessage)
  • useTLS se false skippi il tls
  • XlmnNamespace altra mappa per le nostre esigenze vedi esempio

// Crei una mappa rappresentante gli XLMNS ( adesso accetta quelli custom )
xmlNamespaces := map[string]string{
"soap": "http://schemas.xmlsoap.org/soap/envelope/",
"custom1": "http://custom1.example.it",
"custom2" : "http://custom2.example.it"
}

response, err := client.callWithResponse(
ctx,
soapAction,
request,
responseObj,
customHeaders,
useTLS,
xmlNamespaces,
)

Ringraziamenti

Un sincero ringraziamento agli autori originali di questa libreria e a IlMich che mi ha illuminato su questi trick . Questo fork è stato creato per soddisfare specifiche esigenze di sviluppo personali.


English

Gitter GoDoc Build Status

Generate Go code from a WSDL file.

Installation

  • Download the release
  • Download and build locally:
    • Go 1.15: go get github.com/Andrea-Cavallo/gowsdl/...
    • Go 1.20: go install github.com/Andrea-Cavallo/gowsdl/cmd/gowsdl@latest
  • Install with Homebrew: brew install gowsdl

Goals

  • Generate idiomatic Go code as much as possible
  • Support only Document/Literal wrapped services that are WS-I compliant
  • Support:
    • WSDL 1.1
    • XML Schema 1.0
    • SOAP 1.1
  • Resolve external XML schemas
  • Support both external and local WSDLs

Warnings

  • Please note that the generated code is only a reflection of how the WSDL is. If your WSDL has duplicate type definitions, the generated Go code will have the same and may not compile.

Usage

Usage: gowsdl [options] myservice.wsdl
  -o string
        The file where the generated code will be saved (default "myservice.go")
  -p string
        The package under which the code will be generated (default "myservice")
  -i    Skip TLS verification
  -v    Show the version of gowsdl

Example

To generate Go code from a WSDL file named example.wsdl and save the output to example.go:

gowsdl -o example.go example.wsdl

Acknowledgements

A sincere thank you to the original authors of this library. This fork was created to meet my own development needs.

Contributing

If you wish to contribute to the project, follow these steps:

  1. Fork the repository.
  2. Create a branch for your changes (git checkout -b feature/feature-name).
  3. Commit your changes (git commit -am 'Added a new feature').
  4. Push the branch (git push origin feature/feature-name).
  5. Create a new Pull Request.

Support

If you have questions or need help, join our chat on Gitter or check the documentation on GoDoc.

License

This project is released under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoWSDL

type GoWSDL struct {
	// contains filtered or unexported fields
}

GoWSDL defines the struct for WSDL generator.

func NewGoWSDL

func NewGoWSDL(file, pkg string, ignoreTLS bool, exportAllTypes bool) (*GoWSDL, error)

NewGoWSDL initializes WSDL generator.

func (*GoWSDL) Start

func (g *GoWSDL) Start() (map[string][]byte, error)

Start starts the GoWSDL code generation process. It unmarshals the WSDL document, resolves complex type name collisions, and generates the necessary code for types, operations, and server based on the WSDL structure. The output is returned as a map of byte slices, where the keys represent different code files and the values contain the corresponding generated code. In case of any error during the generation process, an error is returned.

type Location

type Location struct {
	// contains filtered or unexported fields
}

A Location encapsulate information about the loc of WSDL/XSD.

It could be either URL or an absolute file path.

func ParseLocation

func ParseLocation(rawloc string) (*Location, error)

ParseLocation parses a rawloc into a Location structure.

If rawloc is URL then it should be absolute. Relative file path will be converted into absolute path.

func (*Location) Parse

func (r *Location) Parse(ref string) (*Location, error)

Parse parses path in the context of the receiver. The provided path may be relative or absolute. Parse returns nil, err on parse failure.

func (*Location) String

func (r *Location) String() string

String reassembles the Location either into a valid URL string or a file path.

type WSDL

type WSDL struct {
	Xmlns           map[string]string `xml:"-"`
	Name            string            `xml:"name,attr"`
	TargetNamespace string            `xml:"targetNamespace,attr"`
	Imports         []*WSDLImport     `xml:"import"`
	Doc             string            `xml:"documentation"`
	Types           WSDLType          `xml:"http://schemas.xmlsoap.org/wsdl/ types"`
	Messages        []*WSDLMessage    `xml:"http://schemas.xmlsoap.org/wsdl/ message"`
	PortTypes       []*WSDLPortType   `xml:"http://schemas.xmlsoap.org/wsdl/ portType"`
	Binding         []*WSDLBinding    `xml:"http://schemas.xmlsoap.org/wsdl/ binding"`
	Service         []*WSDLService    `xml:"http://schemas.xmlsoap.org/wsdl/ service"`
}

WSDL represents the global structure of a WSDL file.

func (*WSDL) UnmarshalXML

func (w *WSDL) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements interface xml.Unmarshaler for XSDSchema.

type WSDLBinding

type WSDLBinding struct {
	Name        string           `xml:"name,attr"`
	Type        string           `xml:"type,attr"`
	Doc         string           `xml:"documentation"`
	SOAPBinding WSDLSOAPBinding  `xml:"http://schemas.xmlsoap.org/wsdl/soap/ binding"`
	Operations  []*WSDLOperation `xml:"http://schemas.xmlsoap.org/wsdl/ operation"`
}

WSDLBinding defines only a SOAP binding and its operations

type WSDLFault

type WSDLFault struct {
	Name      string        `xml:"name,attr"`
	Message   string        `xml:"message,attr"`
	Doc       string        `xml:"documentation"`
	SOAPFault WSDLSOAPFault `xml:"http://schemas.xmlsoap.org/wsdl/soap/ fault"`
}

WSDLFault represents a WSDL fault message.

type WSDLImport

type WSDLImport struct {
	Namespace string `xml:"namespace,attr"`
	Location  string `xml:"location,attr"`
}

WSDLImport is the struct used for deserializing WSDL imports.

type WSDLInput

type WSDLInput struct {
	Name       string            `xml:"name,attr"`
	Message    string            `xml:"message,attr"`
	Doc        string            `xml:"documentation"`
	SOAPBody   WSDLSOAPBody      `xml:"http://schemas.xmlsoap.org/wsdl/soap/ body"`
	SOAPHeader []*WSDLSOAPHeader `xml:"http://schemas.xmlsoap.org/wsdl/soap/ header"`
}

WSDLInput represents a WSDL input message.

type WSDLMessage

type WSDLMessage struct {
	Name  string      `xml:"name,attr"`
	Doc   string      `xml:"documentation"`
	Parts []*WSDLPart `xml:"http://schemas.xmlsoap.org/wsdl/ part"`
}

WSDLMessage represents a function, which in turn has one or more parameters.

type WSDLOperation

type WSDLOperation struct {
	Name          string            `xml:"name,attr"`
	Doc           string            `xml:"documentation"`
	Input         WSDLInput         `xml:"input"`
	Output        WSDLOutput        `xml:"output"`
	Faults        []*WSDLFault      `xml:"fault"`
	SOAPOperation WSDLSOAPOperation `xml:"http://schemas.xmlsoap.org/wsdl/soap/ operation"`
}

WSDLOperation represents the contract of an entire operation or function.

type WSDLOutput

type WSDLOutput struct {
	Name       string            `xml:"name,attr"`
	Message    string            `xml:"message,attr"`
	Doc        string            `xml:"documentation"`
	SOAPBody   WSDLSOAPBody      `xml:"http://schemas.xmlsoap.org/wsdl/soap/ body"`
	SOAPHeader []*WSDLSOAPHeader `xml:"http://schemas.xmlsoap.org/wsdl/soap/ header"`
}

WSDLOutput represents a WSDL output message.

type WSDLPart

type WSDLPart struct {
	Name    string `xml:"name,attr"`
	Element string `xml:"element,attr"`
	Type    string `xml:"type,attr"`
}

WSDLPart defines the struct for a function parameter within a WSDL.

type WSDLPort

type WSDLPort struct {
	Name        string          `xml:"name,attr"`
	Binding     string          `xml:"binding,attr"`
	Doc         string          `xml:"documentation"`
	SOAPAddress WSDLSOAPAddress `xml:"http://schemas.xmlsoap.org/wsdl/soap/ address"`
}

WSDLPort defines the properties for a SOAP port only.

type WSDLPortType

type WSDLPortType struct {
	Name       string           `xml:"name,attr"`
	Doc        string           `xml:"documentation"`
	Operations []*WSDLOperation `xml:"http://schemas.xmlsoap.org/wsdl/ operation"`
}

WSDLPortType defines the service, operations that can be performed and the messages involved. A port type can be compared to a function library, module or class.

type WSDLSOAPAddress

type WSDLSOAPAddress struct {
	Location string `xml:"location,attr"`
}

WSDLSOAPAddress defines the location for the SOAP service.

type WSDLSOAPBinding

type WSDLSOAPBinding struct {
	Style     string `xml:"style,attr"`
	Transport string `xml:"transport,attr"`
}

WSDLSOAPBinding represents a SOAP binding to the web service.

type WSDLSOAPBody

type WSDLSOAPBody struct {
	Parts         string `xml:"parts,attr"`
	Use           string `xml:"use,attr"`
	EncodingStyle string `xml:"encodingStyle,attr"`
	Namespace     string `xml:"namespace,attr"`
}

WSDLSOAPBody defines SOAP body characteristics.

type WSDLSOAPFault

type WSDLSOAPFault struct {
	Parts         string `xml:"parts,attr"`
	Use           string `xml:"use,attr"`
	EncodingStyle string `xml:"encodingStyle,attr"`
	Namespace     string `xml:"namespace,attr"`
}

WSDLSOAPFault defines a SOAP fault message characteristics.

type WSDLSOAPHeader

type WSDLSOAPHeader struct {
	Message       string                 `xml:"message,attr"`
	Part          string                 `xml:"part,attr"`
	Use           string                 `xml:"use,attr"`
	EncodingStyle string                 `xml:"encodingStyle,attr"`
	Namespace     string                 `xml:"namespace,attr"`
	HeadersFault  []*WSDLSOAPHeaderFault `xml:"headerfault"`
}

WSDLSOAPHeader defines the header for a SOAP service.

type WSDLSOAPHeaderFault

type WSDLSOAPHeaderFault struct {
	Message       string `xml:"message,attr"`
	Part          string `xml:"part,attr"`
	Use           string `xml:"use,attr"`
	EncodingStyle string `xml:"encodingStyle,attr"`
	Namespace     string `xml:"namespace,attr"`
}

WSDLSOAPHeaderFault defines a SOAP fault header.

type WSDLSOAPOperation

type WSDLSOAPOperation struct {
	SOAPAction string `xml:"soapAction,attr"`
	Style      string `xml:"style,attr"`
}

WSDLSOAPOperation represents a service operation in SOAP terms.

type WSDLService

type WSDLService struct {
	Name  string      `xml:"name,attr"`
	Doc   string      `xml:"documentation"`
	Ports []*WSDLPort `xml:"http://schemas.xmlsoap.org/wsdl/ port"`
}

WSDLService defines the list of SOAP services associated with the WSDL.

type WSDLType

type WSDLType struct {
	Doc     string       `xml:"documentation"`
	Schemas []*XSDSchema `xml:"schema"`
}

WSDLType represents the entry point for deserializing XSD schemas used by the WSDL file.

type XSDAny

type XSDAny struct {
	XMLName         xml.Name `xml:"any"`
	Doc             string   `xml:"annotation>documentation"`
	MinOccurs       string   `xml:"minOccurs,attr"`
	MaxOccurs       string   `xml:"maxOccurs,attr"`
	Namespace       string   `xml:"namespace,attr"`
	ProcessContents string   `xml:"processContents,attr"`
}

XSDAny represents a Schema element.

type XSDAttribute

type XSDAttribute struct {
	Doc        string         `xml:"annotation>documentation"`
	Name       string         `xml:"name,attr"`
	Ref        string         `xml:"ref,attr"`
	Type       string         `xml:"type,attr"`
	Use        string         `xml:"use,attr"`
	Fixed      string         `xml:"fixed,attr"`
	SimpleType *XSDSimpleType `xml:"simpleType"`
}

XSDAttribute represent an element attribute. Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type.

type XSDComplexContent

type XSDComplexContent struct {
	XMLName   xml.Name     `xml:"complexContent"`
	Extension XSDExtension `xml:"extension"`
}

XSDComplexContent element defines extensions or restrictions on a complex type that contains mixed content or elements only.

type XSDComplexType

type XSDComplexType struct {
	XMLName        xml.Name          `xml:"complexType"`
	Abstract       bool              `xml:"abstract,attr"`
	Name           string            `xml:"name,attr"`
	Mixed          bool              `xml:"mixed,attr"`
	Sequence       []*XSDElement     `xml:"sequence>element"`
	Choice         []*XSDElement     `xml:"choice>element"`
	SequenceChoice []*XSDElement     `xml:"sequence>choice>element"`
	All            []*XSDElement     `xml:"all>element"`
	ComplexContent XSDComplexContent `xml:"complexContent"`
	SimpleContent  XSDSimpleContent  `xml:"simpleContent"`
	Attributes     []*XSDAttribute   `xml:"attribute"`
	Any            []*XSDAny         `xml:"sequence>any"`
}

XSDComplexType represents a Schema complex type.

type XSDElement

type XSDElement struct {
	XMLName     xml.Name        `xml:"element"`
	Name        string          `xml:"name,attr"`
	Doc         string          `xml:"annotation>documentation"`
	Nillable    bool            `xml:"nillable,attr"`
	Type        string          `xml:"type,attr"`
	Ref         string          `xml:"ref,attr"`
	MinOccurs   string          `xml:"minOccurs,attr"`
	MaxOccurs   string          `xml:"maxOccurs,attr"`
	ComplexType *XSDComplexType `xml:"complexType"` // local
	SimpleType  *XSDSimpleType  `xml:"simpleType"`
	Groups      []*XSDGroup     `xml:"group"`
}

XSDElement represents a Schema element.

type XSDExtension

type XSDExtension struct {
	XMLName        xml.Name        `xml:"extension"`
	Base           string          `xml:"base,attr"`
	Attributes     []*XSDAttribute `xml:"attribute"`
	Sequence       []*XSDElement   `xml:"sequence>element"`
	Choice         []*XSDElement   `xml:"choice>element"`
	SequenceChoice []*XSDElement   `xml:"sequence>choice>element"`
}

XSDExtension element extends an existing simpleType or complexType element.

type XSDGroup

type XSDGroup struct {
	Name     string       `xml:"name,attr"`
	Ref      string       `xml:"ref,attr"`
	Sequence []XSDElement `xml:"sequence>element"`
	Choice   []XSDElement `xml:"choice>element"`
	All      []XSDElement `xml:"all>element"`
}

XSDGroup element is used to define a group of elements to be used in complex type definitions.

type XSDImport

type XSDImport struct {
	XMLName        xml.Name `xml:"import"`
	SchemaLocation string   `xml:"schemaLocation,attr"`
	Namespace      string   `xml:"namespace,attr"`
}

XSDImport represents XSD imports within the main schema.

type XSDInclude

type XSDInclude struct {
	SchemaLocation string `xml:"schemaLocation,attr"`
}

XSDInclude represents schema includes.

type XSDList

type XSDList struct {
	Doc        string         `xml:"annotation>documentation"`
	ItemType   string         `xml:"itemType,attr"`
	SimpleType *XSDSimpleType `xml:"simpleType"`
}

XSDList represents a element list

type XSDRestriction

type XSDRestriction struct {
	Base         string                `xml:"base,attr"`
	Enumeration  []XSDRestrictionValue `xml:"enumeration"`
	Pattern      XSDRestrictionValue   `xml:"pattern"`
	MinInclusive XSDRestrictionValue   `xml:"minInclusive"`
	MaxInclusive XSDRestrictionValue   `xml:"maxInclusive"`
	WhiteSpace   XSDRestrictionValue   `xml:"whitespace"`
	Length       XSDRestrictionValue   `xml:"length"`
	MinLength    XSDRestrictionValue   `xml:"minLength"`
	MaxLength    XSDRestrictionValue   `xml:"maxLength"`
}

XSDRestriction defines restrictions on a simpleType, simpleContent, or complexContent definition.

type XSDRestrictionValue

type XSDRestrictionValue struct {
	Doc   string `xml:"annotation>documentation"`
	Value string `xml:"value,attr"`
}

XSDRestrictionValue represents a restriction value.

type XSDSchema

type XSDSchema struct {
	XMLName            xml.Name          `xml:"schema"`
	Xmlns              map[string]string `xml:"-"`
	Tns                string            `xml:"xmlns tns,attr"`
	Xs                 string            `xml:"xmlns xs,attr"`
	Version            string            `xml:"version,attr"`
	TargetNamespace    string            `xml:"targetNamespace,attr"`
	ElementFormDefault string            `xml:"elementFormDefault,attr"`
	Includes           []*XSDInclude     `xml:"include"`
	Imports            []*XSDImport      `xml:"import"`
	Elements           []*XSDElement     `xml:"element"`
	Attributes         []*XSDAttribute   `xml:"attribute"`
	ComplexTypes       []*XSDComplexType `xml:"complexType"` // global
	SimpleType         []*XSDSimpleType  `xml:"simpleType"`
}

XSDSchema represents an entire Schema structure.

func (*XSDSchema) UnmarshalXML

func (s *XSDSchema) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements interface xml.Unmarshaler for XSDSchema.

type XSDSimpleContent

type XSDSimpleContent struct {
	XMLName   xml.Name     `xml:"simpleContent"`
	Extension XSDExtension `xml:"extension"`
}

XSDSimpleContent element contains extensions or restrictions on a text-only complex type or on a simple type as content and contains no elements.

type XSDSimpleType

type XSDSimpleType struct {
	Name        string         `xml:"name,attr"`
	Doc         string         `xml:"annotation>documentation"`
	Restriction XSDRestriction `xml:"restriction"`
	List        XSDList        `xml:"list"`
	Union       XSDUnion       `xml:"union"`
	Final       string         `xml:"final"`
}

XSDSimpleType element defines a simple type and specifies the constraints and information about the values of attributes or text-only elements.

type XSDUnion

type XSDUnion struct {
	SimpleType  []*XSDSimpleType `xml:"simpleType,omitempty"`
	MemberTypes string           `xml:"memberTypes,attr"`
}

XSDUnion represents a union element

Directories

Path Synopsis
cmd
gowsdl
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL