Go API Documentation

github.com/TykTechnologies/tyk/apidef/importer

No package summary is available.

Package

Files: 4. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

const ApiaryBluePrint APIImporterSource = "blueprint"
const SwaggerSource APIImporterSource = "swagger"
const WSDLSource APIImporterSource = "wsdl"
const (
	NS_WSDL20	= "http://www.w3.org/ns/wsdl"
	NS_WSDL		= "http://schemas.xmlsoap.org/wsdl/"
	NS_SOAP		= "http://schemas.xmlsoap.org/wsdl/soap/"
	NS_SOAP12	= "http://schemas.xmlsoap.org/wsdl/soap12/"
	NS_HTTP		= "http://schemas.xmlsoap.org/wsdl/http/"
)
const (
	PROT_HTTP	= "http"
	PROT_SOAP	= "soap"
	PROT_SOAP_12	= "soap12"
)

Vars

var bindingList = map[string]*WSDLBinding{}
var log = logger.Get()
var portName = map[string]string{}

Types

APIImporter

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type APIImporter interface {
	LoadFrom(io.Reader) error
	ConvertIntoApiVersion(bool) (apidef.VersionInfo, error)
	InsertIntoAPIDefinitionAsVersion(apidef.VersionInfo, *apidef.APIDefinition, string) error
	ToAPIDefinition(string, string, bool) (*apidef.APIDefinition, error)
}

APIImporterSource

This type doesn't have documentation.

Field name Field type Comment
type

string

No comment on field.
type APIImporterSource string

BluePrintAST

This type doesn't have documentation.

Field name Field type Comment
Version

string

No comment on field.
Description

string

No comment on field.
Metadata

[]struct { Name string `json:"name"` Value string `json:"value"` }

No comment on field.
Name

string

No comment on field.
ResourceGroups

[]struct { Description string `json:"description"` Name string `json:"name"` Resources []struct { Actions []struct { Description string `json:"description"` Examples []struct { Description string `json:"description"` Name string `json:"name"` Requests []struct { Body string `json:"body"` Description string `json:"description"` Headers []struct { Name string `json:"name"` Value string `json:"value"` } `json:"headers"` Name string `json:"name"` Schema string `json:"schema"` } `json:"requests"` Responses []struct { Body string `json:"body"` Description string `json:"description"` Headers []struct { Name string `json:"name"` Value string `json:"value"` } `json:"headers"` Name string `json:"name"` Schema string `json:"schema"` } `json:"responses"` } `json:"examples"` Method string `json:"method"` Name string `json:"name"` Parameters []struct { Default string `json:"default"` Description string `json:"description"` Example string `json:"example"` Name string `json:"name"` Required bool `json:"required"` Type string `json:"type"` Values []struct { Value string `json:"value"` } `json:"values"` } `json:"parameters"` } `json:"actions"` Description string `json:"description"` Model struct { Body string `json:"body"` Description string `json:"description"` Headers []struct { Name string `json:"name"` Value string `json:"value"` } `json:"headers"` Name string `json:"name"` Schema string `json:"schema"` } `json:"model"` Name string `json:"name"` Parameters []struct { Default string `json:"default"` Description string `json:"description"` Example string `json:"example"` Name string `json:"name"` Required bool `json:"required"` Type string `json:"type"` Values []struct { Value string `json:"value"` } `json:"values"` } `json:"parameters"` UriTemplate string `json:"uriTemplate"` } `json:"resources"` }

No comment on field.
type BluePrintAST struct {
	Version		string	`json:"_version"`
	Description	string	`json:"description"`
	Metadata	[]struct {
		Name	string	`json:"name"`
		Value	string	`json:"value"`
	}	`json:"metadata"`
	Name		string	`json:"name"`
	ResourceGroups	[]struct {
		Description	string	`json:"description"`
		Name		string	`json:"name"`
		Resources	[]struct {
			Actions	[]struct {
				Description	string	`json:"description"`
				Examples	[]struct {
					Description	string	`json:"description"`
					Name		string	`json:"name"`
					Requests	[]struct {
						Body		string	`json:"body"`
						Description	string	`json:"description"`
						Headers		[]struct {
							Name	string	`json:"name"`
							Value	string	`json:"value"`
						}	`json:"headers"`
						Name	string	`json:"name"`
						Schema	string	`json:"schema"`
					}	`json:"requests"`
					Responses	[]struct {
						Body		string	`json:"body"`
						Description	string	`json:"description"`
						Headers		[]struct {
							Name	string	`json:"name"`
							Value	string	`json:"value"`
						}	`json:"headers"`
						Name	string	`json:"name"`
						Schema	string	`json:"schema"`
					}	`json:"responses"`
				}	`json:"examples"`
				Method		string	`json:"method"`
				Name		string	`json:"name"`
				Parameters	[]struct {
					Default		string	`json:"default"`
					Description	string	`json:"description"`
					Example		string	`json:"example"`
					Name		string	`json:"name"`
					Required	bool	`json:"required"`
					Type		string	`json:"type"`
					Values		[]struct {
						Value string `json:"value"`
					}	`json:"values"`
				}	`json:"parameters"`
			}	`json:"actions"`
			Description	string	`json:"description"`
			Model		struct {
				Body		string	`json:"body"`
				Description	string	`json:"description"`
				Headers		[]struct {
					Name	string	`json:"name"`
					Value	string	`json:"value"`
				}	`json:"headers"`
				Name	string	`json:"name"`
				Schema	string	`json:"schema"`
			}	`json:"model"`
			Name		string	`json:"name"`
			Parameters	[]struct {
				Default		string	`json:"default"`
				Description	string	`json:"description"`
				Example		string	`json:"example"`
				Name		string	`json:"name"`
				Required	bool	`json:"required"`
				Type		string	`json:"type"`
				Values		[]struct {
					Value string `json:"value"`
				}	`json:"values"`
			}	`json:"parameters"`
			UriTemplate	string	`json:"uriTemplate"`
		}	`json:"resources"`
	}	`json:"resourceGroups"`
}

DefinitionObjectAST

This type doesn't have documentation.

Field name Field type Comment
Type

string

No comment on field.
Required

[]string

No comment on field.
Properties

map[string]DefinitionObjectFormatAST

No comment on field.
type DefinitionObjectAST struct {
	Type		string					`json:"type"`
	Required	[]string				`json:"required"`
	Properties	map[string]DefinitionObjectFormatAST	`json:"properties"`
}

DefinitionObjectFormatAST

This type doesn't have documentation.

Field name Field type Comment
Format

string

No comment on field.
Type

string

No comment on field.
type DefinitionObjectFormatAST struct {
	Format	string	`json:"format"`
	Type	string	`json:"type"`
}

PathItemObject

This type doesn't have documentation.

Field name Field type Comment
Get

PathMethodObject

No comment on field.
Put

PathMethodObject

No comment on field.
Post

PathMethodObject

No comment on field.
Patch

PathMethodObject

No comment on field.
Options

PathMethodObject

No comment on field.
Delete

PathMethodObject

No comment on field.
Head

PathMethodObject

No comment on field.
type PathItemObject struct {
	Get	PathMethodObject	`json:"get"`
	Put	PathMethodObject	`json:"put"`
	Post	PathMethodObject	`json:"post"`
	Patch	PathMethodObject	`json:"patch"`
	Options	PathMethodObject	`json:"options"`
	Delete	PathMethodObject	`json:"delete"`
	Head	PathMethodObject	`json:"head"`
}

PathMethodObject

This type doesn't have documentation.

Field name Field type Comment
Description

string

No comment on field.
OperationID

string

No comment on field.
Responses

map[string]ResponseCodeObjectAST

No comment on field.
type PathMethodObject struct {
	Description	string					`json:"description"`
	OperationID	string					`json:"operationId"`
	Responses	map[string]ResponseCodeObjectAST	`json:"responses"`
}

ResponseCodeObjectAST

This type doesn't have documentation.

Field name Field type Comment
Description

string

No comment on field.
Schema

struct { Items map[string]interface{} `json:"items"` Type string `json:"type"` }

No comment on field.
type ResponseCodeObjectAST struct {
	Description	string	`json:"description"`
	Schema		struct {
		Items	map[string]interface{}	`json:"items"`
		Type	string			`json:"type"`
	}	`json:"schema"`
}

SwaggerAST

This type doesn't have documentation.

Field name Field type Comment
BasePath

string

No comment on field.
Consumes

[]string

No comment on field.
Definitions

map[string]DefinitionObjectAST

No comment on field.
Host

string

No comment on field.
Info

struct { Contact struct { Email string `json:"email"` Name string `json:"name"` URL string `json:"url"` } `json:"contact"` Description string `json:"description"` License struct { Name string `json:"name"` URL string `json:"url"` } `json:"license"` TermsOfService string `json:"termsOfService"` Title string `json:"title"` Version string `json:"version"` }

No comment on field.
Paths

map[string]PathItemObject

No comment on field.
Produces

[]string

No comment on field.
Schemes

[]string

No comment on field.
Swagger

string

No comment on field.
type SwaggerAST struct {
	BasePath	string				`json:"basePath"`
	Consumes	[]string			`json:"consumes"`
	Definitions	map[string]DefinitionObjectAST	`json:"definitions"`
	Host		string				`json:"host"`
	Info		struct {
		Contact	struct {
			Email	string	`json:"email"`
			Name	string	`json:"name"`
			URL	string	`json:"url"`
		}	`json:"contact"`
		Description	string	`json:"description"`
		License		struct {
			Name	string	`json:"name"`
			URL	string	`json:"url"`
		}	`json:"license"`
		TermsOfService	string	`json:"termsOfService"`
		Title		string	`json:"title"`
		Version		string	`json:"version"`
	}	`json:"info"`
	Paths		map[string]PathItemObject	`json:"paths"`
	Produces	[]string			`json:"produces"`
	Schemes		[]string			`json:"schemes"`
	Swagger		string				`json:"swagger"`
}

WSDL

This type doesn't have documentation.

Field name Field type Comment
Services

[]*WSDLService

No comment on field.
Bindings

[]*WSDLBinding

No comment on field.
type WSDL struct {
	Services	[]*WSDLService	`xml:"http://schemas.xmlsoap.org/wsdl/ service"`
	Bindings	[]*WSDLBinding	`xml:"http://schemas.xmlsoap.org/wsdl/ binding"`
}

WSDLAddress

This type doesn't have documentation.

Field name Field type Comment
Location

string

No comment on field.
type WSDLAddress struct {
	Location string `xml:"location,attr"`
}

WSDLBinding

This type doesn't have documentation.

Field name Field type Comment
Name

string

No comment on field.
Operations

[]*WSDLOperation

No comment on field.
Protocol

string

No comment on field.
Method

string

No comment on field.
isSupportedProtocol

bool

No comment on field.
type WSDLBinding struct {
	Name			string			`xml:"name,attr"`
	Operations		[]*WSDLOperation	`xml:"http://schemas.xmlsoap.org/wsdl/ operation"`
	Protocol		string
	Method			string
	isSupportedProtocol	bool
}

WSDLDef

This type doesn't have documentation.

Field name Field type Comment
Definition

WSDL

No comment on field.
type WSDLDef struct {
	Definition WSDL `xml:"http://schemas.xmlsoap.org/wsdl/ definitions"`
}

WSDLOperation

This type doesn't have documentation.

Field name Field type Comment
Name

string

No comment on field.
Endpoint

string

No comment on field.
IsUrlReplacement

bool

No comment on field.
type WSDLOperation struct {
	Name			string	`xml:"name,attr"`
	Endpoint		string
	IsUrlReplacement	bool
}

WSDLPort

This type doesn't have documentation.

Field name Field type Comment
Name

string

No comment on field.
Binding

string

No comment on field.
Address

WSDLAddress

No comment on field.
type WSDLPort struct {
	Name	string		`xml:"name,attr"`
	Binding	string		`xml:"binding,attr"`
	Address	WSDLAddress	`xml:"address"`
}

WSDLService

This type doesn't have documentation.

Field name Field type Comment
Name

string

No comment on field.
Ports

[]*WSDLPort

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

Functions

func GetImporterForSource

func GetImporterForSource(source APIImporterSource) (APIImporter, error) {
	// Extend to add new importers
	switch source {
	case ApiaryBluePrint:
		return &BluePrintAST{}, nil
	case SwaggerSource:
		return &SwaggerAST{}, nil
	case WSDLSource:
		return &WSDLDef{}, nil
	default:
		return nil, errors.New("source not matched, failing")
	}
}

Cognitive complexity: 8, Cyclomatic complexity: 5

Uses: errors.New.

func ReplaceWildCards

func ReplaceWildCards(endpoint string) string {
	var result []rune
	var inside bool

	for _, s := range endpoint {
		if s == '{' {
			inside = true
			continue
		} else if s == '}' {
			inside = false
			result = append(result, '.', '*')
			continue
		}

		if inside == false {
			result = append(result, s)
		}
	}
	return string(result)
}

Cognitive complexity: 9, Cyclomatic complexity: 5

func (*BluePrintAST) ConvertIntoApiVersion

func (b *BluePrintAST) ConvertIntoApiVersion(asMock bool) (apidef.VersionInfo, error) {
	versionInfo := apidef.VersionInfo{}
	versionInfo.UseExtendedPaths = true
	versionInfo.Name = b.Name

	if len(b.ResourceGroups) < 1 {
		return versionInfo, errors.New("There are no resource groups defined in this blueprint, are you sure it is correctly formatted?")
	}

	for _, resourceGroup := range b.ResourceGroups {
		if len(resourceGroup.Resources) < 1 {
			return versionInfo, errors.New("no resources defined in the resource group")
		}

		for _, resource := range resourceGroup.Resources {
			newMetaData := apidef.EndPointMeta{}
			newMetaData.Path = resource.UriTemplate
			newMetaData.MethodActions = make(map[string]apidef.EndpointMethodMeta)

			for _, action := range resource.Actions {
				if len(action.Examples) == 0 || len(action.Examples[0].Responses) == 0 {
					continue
				}
				endPointMethodMeta := apidef.EndpointMethodMeta{}
				code, err := strconv.Atoi(action.Examples[0].Responses[0].Name)
				if err != nil {
					log.Warning("Could not generate response code from Name field, using 200")
					code = 200
				}
				endPointMethodMeta.Code = code

				if asMock {
					endPointMethodMeta.Action = apidef.Reply
				} else {
					endPointMethodMeta.Action = apidef.NoAction
				}

				for _, h := range action.Examples[0].Responses[0].Headers {
					endPointMethodMeta.Headers = make(map[string]string)
					endPointMethodMeta.Headers[h.Name] = h.Value
				}
				endPointMethodMeta.Data = action.Examples[0].Responses[0].Body
				newMetaData.MethodActions[action.Method] = endPointMethodMeta
			}

			// Add it to the version
			versionInfo.ExtendedPaths.WhiteList = make([]apidef.EndPointMeta, 0)
			versionInfo.ExtendedPaths.WhiteList = append(versionInfo.ExtendedPaths.WhiteList, newMetaData)
		}

	}

	return versionInfo, nil
}

Cognitive complexity: 27, Cyclomatic complexity: 11

Uses: apidef.EndPointMeta, apidef.EndpointMethodMeta, apidef.NoAction, apidef.Reply, apidef.VersionInfo, errors.New, strconv.Atoi.

func (*BluePrintAST) InsertIntoAPIDefinitionAsVersion

func (b *BluePrintAST) InsertIntoAPIDefinitionAsVersion(version apidef.VersionInfo, def *apidef.APIDefinition, versionName string) error {
	def.VersionData.NotVersioned = false
	def.VersionData.Versions[versionName] = version
	return nil
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*BluePrintAST) LoadFrom

func (b *BluePrintAST) LoadFrom(r io.Reader) error {
	return json.NewDecoder(r).Decode(&b)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: json.NewDecoder.

func (*BluePrintAST) ToAPIDefinition

func (b *BluePrintAST) ToAPIDefinition(orgID, upstreamURL string, asMock bool) (*apidef.APIDefinition, error) {
	ad := apidef.APIDefinition{
		Name:			b.Name,
		Active:			true,
		UseKeylessAccess:	true,
		APIID:			uuid.NewHex(),
		OrgID:			orgID,
	}
	ad.VersionDefinition.Key = "version"
	ad.VersionDefinition.Location = "header"
	ad.VersionData.Versions = make(map[string]apidef.VersionInfo)
	ad.Proxy.ListenPath = "/" + ad.APIID + "/"
	ad.Proxy.StripListenPath = true
	ad.Proxy.TargetURL = upstreamURL

	versionData, err := b.ConvertIntoApiVersion(asMock)
	if err != nil {
		return nil, err
	}

	err = b.InsertIntoAPIDefinitionAsVersion(versionData, &ad, strings.Trim(b.Name, " "))
	return &ad, err
}

Cognitive complexity: 3, Cyclomatic complexity: 2

Uses: apidef.APIDefinition, apidef.VersionInfo, strings.Trim, uuid.NewHex.

func (*SwaggerAST) ConvertIntoApiVersion

func (s *SwaggerAST) ConvertIntoApiVersion(asMock bool) (apidef.VersionInfo, error) {
	versionInfo := apidef.VersionInfo{}

	if asMock {
		return versionInfo, errors.New("Swagger mocks not supported")
	}

	versionInfo.UseExtendedPaths = true
	versionInfo.Name = s.Info.Version

	if len(s.Paths) == 0 {
		return versionInfo, errors.New("no paths defined in swagger file")
	}
	for pathName, pathSpec := range s.Paths {
		whitelistMeta := apidef.EndPointMeta{
			Path:		pathName,
			MethodActions:	map[string]apidef.EndpointMethodMeta{},
		}

		trackMeta := apidef.TrackEndpointMeta{
			Path: pathName,
		}

		// We just want the paths here, no mocks
		methods := map[string]PathMethodObject{
			"GET":		pathSpec.Get,
			"PUT":		pathSpec.Put,
			"POST":		pathSpec.Post,
			"HEAD":		pathSpec.Head,
			"PATCH":	pathSpec.Patch,
			"OPTIONS":	pathSpec.Options,
			"DELETE":	pathSpec.Delete,
		}

		for methodName, m := range methods {
			// skip methods that are not defined
			if len(m.Responses) == 0 && m.Description == "" && m.OperationID == "" {
				continue
			}

			whitelistMeta.MethodActions[methodName] = apidef.EndpointMethodMeta{
				Action:	apidef.NoAction,
				Code:	http.StatusOK,
			}

			trackMeta.Method = methodName
			versionInfo.ExtendedPaths.TrackEndpoints = append(versionInfo.ExtendedPaths.TrackEndpoints, trackMeta)
		}

		versionInfo.ExtendedPaths.WhiteList = append(versionInfo.ExtendedPaths.WhiteList, whitelistMeta)
	}

	return versionInfo, nil
}

Cognitive complexity: 18, Cyclomatic complexity: 8

Uses: apidef.EndPointMeta, apidef.EndpointMethodMeta, apidef.NoAction, apidef.TrackEndpointMeta, apidef.VersionInfo, errors.New, http.StatusOK.

func (*SwaggerAST) InsertIntoAPIDefinitionAsVersion

func (s *SwaggerAST) InsertIntoAPIDefinitionAsVersion(version apidef.VersionInfo, def *apidef.APIDefinition, versionName string) error {
	def.VersionData.NotVersioned = false
	def.VersionData.Versions[versionName] = version
	return nil
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*SwaggerAST) LoadFrom

func (s *SwaggerAST) LoadFrom(r io.Reader) error {
	return json.NewDecoder(r).Decode(&s)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: json.NewDecoder.

func (*SwaggerAST) ToAPIDefinition

func (s *SwaggerAST) ToAPIDefinition(orgId, upstreamURL string, as_mock bool) (*apidef.APIDefinition, error) {
	ad := apidef.APIDefinition{
		Name:			s.Info.Title,
		Active:			true,
		UseKeylessAccess:	true,
		APIID:			uuid.NewHex(),
		OrgID:			orgId,
	}
	ad.VersionDefinition.Key = "version"
	ad.VersionDefinition.Location = "header"
	ad.VersionData.Versions = make(map[string]apidef.VersionInfo)
	ad.Proxy.ListenPath = "/" + ad.APIID + "/"
	ad.Proxy.StripListenPath = true
	ad.Proxy.TargetURL = upstreamURL

	if as_mock {
		log.Warning("Mocks not supported for Swagger definitions, ignoring option")
	}
	versionData, err := s.ConvertIntoApiVersion(false)
	if err != nil {
		return nil, err
	}

	s.InsertIntoAPIDefinitionAsVersion(versionData, &ad, strings.Trim(s.Info.Version, " "))

	return &ad, nil
}

Cognitive complexity: 5, Cyclomatic complexity: 3

Uses: apidef.APIDefinition, apidef.VersionInfo, strings.Trim, uuid.NewHex.

func (*WSDLBinding) UnmarshalXML

func (b *WSDLBinding) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	//Get value of name attribute
	for _, attr := range start.Attr {
		if attr.Name.Local == "name" {
			b.Name = attr.Value
			break
		}
	}

	if b.Name == "" {
		return errors.New("Binding name is empty. Malformed wsdl")
	}

	//Fetch protocol specific data
	//If soap/soap12 is used, set Method to POST
	//If http is used, get value of verb attribute
	//If any other protocol is used, then skip
	for {
		tok, err := d.Token()
		if err != nil {
			log.Error("Error will parsing WSDL file: ", err)
			return err
		}

		switch t := tok.(type) {
		case xml.StartElement:
			{
				switch t.Name.Local {
				case "binding":
					{
						switch t.Name.Space {
						case NS_SOAP, NS_SOAP12:
							{
								b.isSupportedProtocol = true
								if t.Name.Space == NS_SOAP {
									b.Protocol = PROT_SOAP
								} else {
									b.Protocol = PROT_SOAP_12
								}

								//Get transport protocol
								//TODO if transport protocol is different from http
								var transport string
								for _, attr := range t.Attr {
									if attr.Name.Local == "transport" {
										transport = attr.Value
										break
									}
								}
								parts := strings.Split(transport, "/")
								if parts[len(parts)-1] == "http" {
									b.Method = http.MethodPost
								} else {
									b.isSupportedProtocol = false
								}

							}
						case NS_HTTP:
							{
								b.isSupportedProtocol = true
								b.Protocol = PROT_HTTP
								for _, attr := range t.Attr {
									if attr.Name.Local == "verb" {
										b.Method = attr.Value
										break
									}
								}

							}
						default:
							{
								log.Debugf("Unsupported binding protocol is used %s:%s", t.Name.Space, t.Name.Local)
								b.isSupportedProtocol = false
								return nil
							}
						}
					}
				case "operation":
					{
						if t.Name.Space == NS_WSDL && b.isSupportedProtocol {
							op := new(WSDLOperation)
							if err := d.DecodeElement(op, &t); err != nil {
								return err
							}
							b.Operations = append(b.Operations, op)
						}
					}
				default:
					{
						if err := d.Skip(); err != nil {
							return err
						}
					}
				}
			}
		case xml.EndElement:
			{
				if t.Name.Space == NS_WSDL && t.Name.Local == "binding" {
					bindingList[b.Name] = b
					return nil
				}
			}
		}
	}
}

Cognitive complexity: 57, Cyclomatic complexity: 27

Uses: errors.New, http.MethodPost, strings.Split, xml.EndElement, xml.StartElement.

func (*WSDLDef) ConvertIntoApiVersion

func (def *WSDLDef) ConvertIntoApiVersion(bool) (apidef.VersionInfo, error) {
	versionInfo := apidef.VersionInfo{}
	versionInfo.UseExtendedPaths = true
	versionInfo.Name = "1.0.0"
	versionInfo.ExtendedPaths.TrackEndpoints = make([]apidef.TrackEndpointMeta, 0)
	versionInfo.ExtendedPaths.URLRewrite = make([]apidef.URLRewriteMeta, 0)
	versionInfo.ExtendedPaths.Internal = make([]apidef.InternalMeta, 0)

	var foundPort bool
	var serviceCount int

	for _, service := range def.Definition.Services {
		foundPort = false
		if service.Name == "" {
			continue
		}
		for _, port := range service.Ports {
			portName := portName[service.Name]
			if portName == "" {
				portName = service.Ports[0].Name
			}
			if port.Name == portName {
				foundPort = true

				bindingName := trimNamespace(port.Binding)

				binding := bindingList[bindingName]
				if binding == nil {
					log.Errorf("Binding for port %s of service %s not found. Termination processing of the service", port.Name, service.Name)

					foundPort = false
					break
				}

				if !binding.isSupportedProtocol {
					log.Errorf("Unsupported transport protocol. Skipping process of the service %s", service.Name)
					foundPort = false
					break
				}

				if len(binding.Operations) == 0 {
					log.Errorf("No operation found for binding %s of service %s\n", binding.Name, service.Name)
					break
				}

				serviceCount++
				method := binding.Method

				//Create endpoints for each operation
				for _, op := range binding.Operations {
					operationTrackEndpoint := apidef.TrackEndpointMeta{}
					operationUrlRewrite := apidef.URLRewriteMeta{}
					path := ""

					if binding.Protocol == PROT_HTTP {
						if op.Endpoint[0] == '/' {
							path = service.Name + op.Endpoint
						} else {
							path = service.Name + "/" + op.Endpoint
						}
					} else {
						path = service.Name + "/" + op.Name
					}

					//Add each operation in trackendpoint
					operationTrackEndpoint.Path = path
					operationTrackEndpoint.Method = method

					versionInfo.ExtendedPaths.TrackEndpoints = append(versionInfo.ExtendedPaths.TrackEndpoints, operationTrackEndpoint)

					//Rewrite operation to service endpoint
					operationUrlRewrite.Method = method
					operationUrlRewrite.Path = path

					if binding.Protocol == PROT_HTTP {
						if op.IsUrlReplacement == true {
							pattern := ReplaceWildCards(op.Endpoint)
							operationUrlRewrite.MatchPattern = "(" + pattern + ")"
						} else {
							operationUrlRewrite.MatchPattern = "(" + op.Endpoint + ".*)"
						}
						operationUrlRewrite.RewriteTo = port.Address.Location + "$1"
					} else {
						operationUrlRewrite.MatchPattern = path
						operationUrlRewrite.RewriteTo = port.Address.Location
					}

					versionInfo.ExtendedPaths.URLRewrite = append(versionInfo.ExtendedPaths.URLRewrite, operationUrlRewrite)
				}

				break
			}
		}

		if foundPort == false {
			log.Errorf("Port for service %s not found. Skiping processing of the service", service.Name)
		}
	}

	if serviceCount == 0 {
		return versionInfo, errors.New("Error processing wsdl file")
	}

	return versionInfo, nil
}

Cognitive complexity: 44, Cyclomatic complexity: 16

Uses: apidef.InternalMeta, apidef.TrackEndpointMeta, apidef.URLRewriteMeta, apidef.VersionInfo, errors.New.

func (*WSDLDef) InsertIntoAPIDefinitionAsVersion

func (def *WSDLDef) InsertIntoAPIDefinitionAsVersion(version apidef.VersionInfo, apidef *apidef.APIDefinition, versionName string) error {
	apidef.VersionData.NotVersioned = false
	apidef.VersionData.Versions[versionName] = version
	return nil
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*WSDLDef) LoadFrom

func (s *WSDLDef) LoadFrom(r io.Reader) error {
	return xml.NewDecoder(r).Decode(&s)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: xml.NewDecoder.

func (*WSDLDef) SetServicePortMapping

func (*WSDLDef) SetServicePortMapping(input map[string]string) {
	for k, v := range input {
		portName[k] = v
	}
}

Cognitive complexity: 3, Cyclomatic complexity: 2

func (*WSDLDef) ToAPIDefinition

func (def *WSDLDef) ToAPIDefinition(orgId, upstreamURL string, as_mock bool) (*apidef.APIDefinition, error) {
	ad := apidef.APIDefinition{
		Name:			def.Definition.Services[0].Name,
		Active:			true,
		UseKeylessAccess:	true,
		OrgID:			orgId,
		APIID:			uuid.NewHex(),
	}

	ad.VersionDefinition.Key = "version"
	ad.VersionDefinition.Location = "header"
	ad.VersionData.Versions = make(map[string]apidef.VersionInfo)
	ad.Proxy.ListenPath = "/" + def.Definition.Services[0].Name + "/"
	ad.Proxy.StripListenPath = true
	ad.Proxy.TargetURL = upstreamURL

	if as_mock {
		log.Warning("Mocks not supported for WSDL definitions, ignoring option")
	}

	versionData, err := def.ConvertIntoApiVersion(false)
	if err != nil {
		return nil, err
	}

	def.InsertIntoAPIDefinitionAsVersion(versionData, &ad, "1.0.0")
	ad.VersionData.DefaultVersion = "1.0.0"
	return &ad, nil
}

Cognitive complexity: 5, Cyclomatic complexity: 3

Uses: apidef.APIDefinition, apidef.VersionInfo, uuid.NewHex.

func (*WSDLDef) UnmarshalXML

func (def *WSDLDef) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	if start.Name.Space == NS_WSDL20 {
		return errors.New("WSDL 2.0 is not supported")
	} else if start.Name.Space == NS_WSDL && start.Name.Local == "definitions" {
		return d.DecodeElement(&def.Definition, &start)
	} else {
		return errors.New("Invalid WSDL file. WSDL definition must start contain <definitions> element")
	}
}

Cognitive complexity: 6, Cyclomatic complexity: 4

Uses: errors.New.

func (*WSDLOperation) UnmarshalXML

func (op *WSDLOperation) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	for _, attr := range start.Attr {
		if attr.Name.Local == "name" {
			op.Name = attr.Value
			break
		}
	}

	if op.Name == "" {
		return errors.New("Operation name is empty. Malformed wsdl")
	}

	var protocol string

	for {
		tok, err := d.Token()
		if err != nil {
			return err
		}

		switch t := tok.(type) {
		case xml.StartElement:
			{
				if t.Name.Local == "operation" {
					switch t.Name.Space {
					case NS_SOAP, NS_SOAP12:
						{
							protocol = PROT_SOAP
							break
						}
					case NS_HTTP:
						{
							protocol = PROT_HTTP
							for _, attr := range t.Attr {
								if attr.Name.Local == "location" {
									op.Endpoint = attr.Value
									break
								}
							}
							break
						}
					default:
						{
							if err := d.Skip(); err != nil {
								return err
							}
						}

					}
				}

				if protocol == PROT_HTTP {
					if t.Name.Local == "urlReplacement" {
						op.IsUrlReplacement = true
						endpoint := op.Endpoint
						tmp := strings.Replace(endpoint, "(", "{", -1)
						new_endpoint := strings.Replace(tmp, ")", "}", -1)

						op.Endpoint = new_endpoint

					}
				} else {
					if err := d.Skip(); err != nil {
						return err
					}
				}
			}
		case xml.EndElement:
			{
				if t.Name.Space == NS_WSDL && t.Name.Local == "operation" {
					return nil
				}
			}
		}

	}
}

Cognitive complexity: 43, Cyclomatic complexity: 21

Uses: errors.New, strings.Replace, xml.EndElement, xml.StartElement.

Private functions

func trimNamespace

trimNamespace (s string) string
References: strings.SplitN.


Tests

Files: 2. Third party imports: 1. Imports from organisation: 0. Tests: 2. Benchmarks: 0.

Vars

var holidayService string = `
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.holidaywebservice.com/HolidayService_v2/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.holidaywebservice.com/HolidayService_v2/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Web service that calculates holiday dates. (Version 2.0.1)</wsdl:documentation>
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://www.holidaywebservice.com/HolidayService_v2/">
      <s:element name="GetCountriesAvailable">
        <s:complexType/>
      </s:element>
      <s:element name="GetCountriesAvailableResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetCountriesAvailableResult" type="tns:ArrayOfCountryCode"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfCountryCode">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="CountryCode" nillable="true" type="tns:CountryCode"/>
        </s:sequence>
      </s:complexType>
      <s:complexType name="CountryCode">
        <s:complexContent mixed="false">
          <s:extension base="tns:CodeDescriptionBase"/>
        </s:complexContent>
      </s:complexType>
      <s:complexType name="CodeDescriptionBase" abstract="true">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="Code" type="s:string"/>
          <s:element minOccurs="0" maxOccurs="1" name="Description" type="s:string"/>
        </s:sequence>
      </s:complexType>
      <s:element name="GetHolidaysAvailable">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="countryCode" type="tns:Country"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:simpleType name="Country">
        <s:restriction base="s:string">
          <s:enumeration value="Canada"/>
          <s:enumeration value="GreatBritain"/>
          <s:enumeration value="IrelandNorthern"/>
          <s:enumeration value="IrelandRepublicOf"/>
          <s:enumeration value="Scotland"/>
          <s:enumeration value="UnitedStates"/>
        </s:restriction>
      </s:simpleType>
      <s:element name="GetHolidaysAvailableResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetHolidaysAvailableResult" type="tns:ArrayOfHolidayCode"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfHolidayCode">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="HolidayCode" nillable="true" type="tns:HolidayCode"/>
        </s:sequence>
      </s:complexType>
      <s:complexType name="HolidayCode">
        <s:complexContent mixed="false">
          <s:extension base="tns:CodeDescriptionBase"/>
        </s:complexContent>
      </s:complexType>
      <s:element name="GetHolidayDate">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="countryCode" type="tns:Country"/>
            <s:element minOccurs="0" maxOccurs="1" name="holidayCode" type="s:string"/>
            <s:element minOccurs="1" maxOccurs="1" name="year" type="s:int"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidayDateResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="GetHolidayDateResult" type="s:dateTime"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidaysForDateRange">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="countryCode" type="tns:Country"/>
            <s:element minOccurs="1" maxOccurs="1" name="startDate" type="s:dateTime"/>
            <s:element minOccurs="1" maxOccurs="1" name="endDate" type="s:dateTime"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidaysForDateRangeResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetHolidaysForDateRangeResult" type="tns:ArrayOfHoliday"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfHoliday">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="Holiday" nillable="true" type="tns:Holiday"/>
        </s:sequence>
      </s:complexType>
      <s:complexType name="Holiday">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="Country" type="tns:Country"/>
          <s:element minOccurs="0" maxOccurs="1" name="HolidayCode" type="s:string"/>
          <s:element minOccurs="0" maxOccurs="1" name="Descriptor" type="s:string"/>
          <s:element minOccurs="1" maxOccurs="1" name="HolidayType" type="tns:HolidayType"/>
          <s:element minOccurs="1" maxOccurs="1" name="DateType" type="tns:HolidayDateType"/>
          <s:element minOccurs="1" maxOccurs="1" name="BankHoliday" type="tns:BankHoliday"/>
          <s:element minOccurs="1" maxOccurs="1" name="Date" type="s:dateTime"/>
          <s:element minOccurs="0" maxOccurs="1" name="RelatedHolidayCode" type="s:string"/>
          <s:element minOccurs="0" maxOccurs="1" name="ApplicableRegions" type="tns:ArrayOfRegionCode"/>
        </s:sequence>
      </s:complexType>
      <s:simpleType name="HolidayType">
        <s:restriction base="s:string">
          <s:enumeration value="Notable"/>
          <s:enumeration value="Religious"/>
          <s:enumeration value="NotableReligious"/>
          <s:enumeration value="Other"/>
        </s:restriction>
      </s:simpleType>
      <s:simpleType name="HolidayDateType">
        <s:restriction base="s:string">
          <s:enumeration value="Observed"/>
          <s:enumeration value="Actual"/>
          <s:enumeration value="ObservedActual"/>
        </s:restriction>
      </s:simpleType>
      <s:simpleType name="BankHoliday">
        <s:restriction base="s:string">
          <s:enumeration value="Recognized"/>
          <s:enumeration value="NotRecognized"/>
        </s:restriction>
      </s:simpleType>
      <s:complexType name="ArrayOfRegionCode">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="RegionCode" nillable="true" type="tns:RegionCode"/>
        </s:sequence>
      </s:complexType>
      <s:complexType name="RegionCode">
        <s:complexContent mixed="false">
          <s:extension base="tns:CodeDescriptionBase"/>
        </s:complexContent>
      </s:complexType>
      <s:element name="GetHolidaysForYear">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="countryCode" type="tns:Country"/>
            <s:element minOccurs="1" maxOccurs="1" name="year" type="s:int"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidaysForYearResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetHolidaysForYearResult" type="tns:ArrayOfHoliday"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidaysForMonth">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="countryCode" type="tns:Country"/>
            <s:element minOccurs="1" maxOccurs="1" name="year" type="s:int"/>
            <s:element minOccurs="1" maxOccurs="1" name="month" type="s:int"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="GetHolidaysForMonthResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetHolidaysForMonthResult" type="tns:ArrayOfHoliday"/>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ArrayOfCountryCode" nillable="true" type="tns:ArrayOfCountryCode"/>
      <s:element name="ArrayOfHolidayCode" nillable="true" type="tns:ArrayOfHolidayCode"/>
      <s:element name="dateTime" type="s:dateTime"/>
      <s:element name="ArrayOfHoliday" nillable="true" type="tns:ArrayOfHoliday"/>
    </s:schema>
  </wsdl:types>
  <wsdl:message name="GetCountriesAvailableSoapIn">
    <wsdl:part name="parameters" element="tns:GetCountriesAvailable"/>
  </wsdl:message>
  <wsdl:message name="GetCountriesAvailableSoapOut">
    <wsdl:part name="parameters" element="tns:GetCountriesAvailableResponse"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableSoapIn">
    <wsdl:part name="parameters" element="tns:GetHolidaysAvailable"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableSoapOut">
    <wsdl:part name="parameters" element="tns:GetHolidaysAvailableResponse"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateSoapIn">
    <wsdl:part name="parameters" element="tns:GetHolidayDate"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateSoapOut">
    <wsdl:part name="parameters" element="tns:GetHolidayDateResponse"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeSoapIn">
    <wsdl:part name="parameters" element="tns:GetHolidaysForDateRange"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeSoapOut">
    <wsdl:part name="parameters" element="tns:GetHolidaysForDateRangeResponse"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearSoapIn">
    <wsdl:part name="parameters" element="tns:GetHolidaysForYear"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearSoapOut">
    <wsdl:part name="parameters" element="tns:GetHolidaysForYearResponse"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthSoapIn">
    <wsdl:part name="parameters" element="tns:GetHolidaysForMonth"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthSoapOut">
    <wsdl:part name="parameters" element="tns:GetHolidaysForMonthResponse"/>
  </wsdl:message>
  <wsdl:message name="GetCountriesAvailableHttpGetIn"/>
  <wsdl:message name="GetCountriesAvailableHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfCountryCode"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableHttpGetIn">
    <wsdl:part name="countryCode" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfHolidayCode"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateHttpGetIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="holidayCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateHttpGetOut">
    <wsdl:part name="Body" element="tns:dateTime"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeHttpGetIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="startDate" type="s:string"/>
    <wsdl:part name="endDate" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearHttpGetIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthHttpGetIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
    <wsdl:part name="month" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:message name="GetCountriesAvailableHttpPostIn"/>
  <wsdl:message name="GetCountriesAvailableHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfCountryCode"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableHttpPostIn">
    <wsdl:part name="countryCode" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysAvailableHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfHolidayCode"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateHttpPostIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="holidayCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidayDateHttpPostOut">
    <wsdl:part name="Body" element="tns:dateTime"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeHttpPostIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="startDate" type="s:string"/>
    <wsdl:part name="endDate" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForDateRangeHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearHttpPostIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForYearHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthHttpPostIn">
    <wsdl:part name="countryCode" type="s:string"/>
    <wsdl:part name="year" type="s:string"/>
    <wsdl:part name="month" type="s:string"/>
  </wsdl:message>
  <wsdl:message name="GetHolidaysForMonthHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfHoliday"/>
  </wsdl:message>
  <wsdl:portType name="HolidayService2Soap">
    <wsdl:operation name="GetCountriesAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available countries.</wsdl:documentation>
      <wsdl:input message="tns:GetCountriesAvailableSoapIn"/>
      <wsdl:output message="tns:GetCountriesAvailableSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available holidays for a specified country.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysAvailableSoapIn"/>
      <wsdl:output message="tns:GetHolidaysAvailableSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the date of a specific holiday.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidayDateSoapIn"/>
      <wsdl:output message="tns:GetHolidayDateSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a date range.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForDateRangeSoapIn"/>
      <wsdl:output message="tns:GetHolidaysForDateRangeSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for an entire year.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForYearSoapIn"/>
      <wsdl:output message="tns:GetHolidaysForYearSoapOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a specific month.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForMonthSoapIn"/>
      <wsdl:output message="tns:GetHolidaysForMonthSoapOut"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="HolidayService2HttpGet">
    <wsdl:operation name="GetCountriesAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available countries.</wsdl:documentation>
      <wsdl:input message="tns:GetCountriesAvailableHttpGetIn"/>
      <wsdl:output message="tns:GetCountriesAvailableHttpGetOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available holidays for a specified country.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysAvailableHttpGetIn"/>
      <wsdl:output message="tns:GetHolidaysAvailableHttpGetOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the date of a specific holiday.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidayDateHttpGetIn"/>
      <wsdl:output message="tns:GetHolidayDateHttpGetOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a date range.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForDateRangeHttpGetIn"/>
      <wsdl:output message="tns:GetHolidaysForDateRangeHttpGetOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for an entire year.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForYearHttpGetIn"/>
      <wsdl:output message="tns:GetHolidaysForYearHttpGetOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a specific month.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForMonthHttpGetIn"/>
      <wsdl:output message="tns:GetHolidaysForMonthHttpGetOut"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="HolidayService2HttpPost">
    <wsdl:operation name="GetCountriesAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available countries.</wsdl:documentation>
      <wsdl:input message="tns:GetCountriesAvailableHttpPostIn"/>
      <wsdl:output message="tns:GetCountriesAvailableHttpPostOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the available holidays for a specified country.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysAvailableHttpPostIn"/>
      <wsdl:output message="tns:GetHolidaysAvailableHttpPostOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the date of a specific holiday.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidayDateHttpPostIn"/>
      <wsdl:output message="tns:GetHolidayDateHttpPostOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a date range.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForDateRangeHttpPostIn"/>
      <wsdl:output message="tns:GetHolidaysForDateRangeHttpPostOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for an entire year.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForYearHttpPostIn"/>
      <wsdl:output message="tns:GetHolidaysForYearHttpPostOut"/>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get the holidays for a specific month.</wsdl:documentation>
      <wsdl:input message="tns:GetHolidaysForMonthHttpPostIn"/>
      <wsdl:output message="tns:GetHolidaysForMonthHttpPostOut"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="HolidayService2Soap" type="tns:HolidayService2Soap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetCountriesAvailable">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetCountriesAvailable" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysAvailable" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidayDate" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForDateRange" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForYear" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <soap:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForMonth" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="HolidayService2Soap12" type="tns:HolidayService2Soap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetCountriesAvailable">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetCountriesAvailable" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysAvailable" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidayDate" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForDateRange" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForYear" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <soap12:operation soapAction="http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysForMonth" style="document"/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="HolidayService2HttpGet" type="tns:HolidayService2HttpGet">
    <http:binding verb="GET"/>
    <wsdl:operation name="GetCountriesAvailable">
      <http:operation location="/GetCountriesAvailable"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <http:operation location="/GetHolidaysAvailable"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <http:operation location="/GetHolidayDate"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <http:operation location="/GetHolidaysForDateRange"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <http:operation location="/GetHolidaysForYear"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <http:operation location="/GetHolidaysForMonth"/>
      <wsdl:input>
        <http:urlEncoded/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="HolidayService2HttpPost" type="tns:HolidayService2HttpPost">
    <http:binding verb="POST"/>
    <wsdl:operation name="GetCountriesAvailable">
      <http:operation location="/GetCountriesAvailable"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysAvailable">
      <http:operation location="/GetHolidaysAvailable"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidayDate">
      <http:operation location="/GetHolidayDate"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForDateRange">
      <http:operation location="/GetHolidaysForDateRange"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForYear">
      <http:operation location="/GetHolidaysForYear"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="GetHolidaysForMonth">
      <http:operation location="/GetHolidaysForMonth"/>
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded"/>
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="HolidayService2">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Web service that calculates holiday dates. (Version 2.0.1)</wsdl:documentation>
    <wsdl:port name="HolidayService2Soap" binding="tns:HolidayService2Soap">
      <soap:address location="http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx"/>
    </wsdl:port>
    <wsdl:port name="HolidayService2Soap12" binding="tns:HolidayService2Soap12">
      <soap12:address location="http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx"/>
    </wsdl:port>
    <wsdl:port name="HolidayService2HttpGet" binding="tns:HolidayService2HttpGet">
      <http:address location="http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx"/>
    </wsdl:port>
    <wsdl:port name="HolidayService2HttpPost" binding="tns:HolidayService2HttpPost">
      <http:address location="http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
`
var petstoreJSON string = `{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "host": "petstore.swagger.io",
  "basePath": "/v1",
  "schemes": [
    "http"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/pets": {
      "get": {
        "summary": "List all pets",
        "operationId": "listPets",
        "tags": [
          "pets"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "type": "integer",
            "format": "int32"
          }
        ],
        "responses": {
          "200": {
            "description": "An paged array of pets",
            "headers": {
              "x-next": {
                "type": "string",
                "description": "A link to the next page of responses"
              }
            },
            "schema": {
              "$ref": "#/definitions/Pets"
            }
          },
          "default": {
            "description": "unexpected error",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      },
      "post": {
        "summary": "Create a pet",
        "operationId": "createPets",
        "tags": [
          "pets"
        ],
        "responses": {
          "201": {
            "description": "Null response"
          },
          "default": {
            "description": "unexpected error",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      }
    },
    "/pets/{petId}": {
      "get": {
        "summary": "Info for a specific pet",
        "operationId": "showPetById",
        "tags": [
          "pets"
        ],
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "description": "The id of the pet to retrieve",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Expected response to a valid request",
            "schema": {
              "$ref": "#/definitions/Pets"
            }
          },
          "default": {
            "description": "unexpected error",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Pet": {
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        }
      }
    },
    "Pets": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Pet"
      }
    },
    "Error": {
      "required": [
        "code",
        "message"
      ],
      "properties": {
        "code": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      }
    }
  }
}`
var smtpExample string = `<?xml version="1.0"?>
<definitions name="StockQuote"
          targetNamespace="http://example.com/stockquote.wsdl"
          xmlns:tns="http://example.com/stockquote.wsdl"
          xmlns:xsd1="http://example.com/stockquote.xsd"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns="http://schemas.xmlsoap.org/wsdl/">

    <message name="SubscribeToQuotes">
        <part name="body" element="xsd1:SubscribeToQuotes"/>
        <part name="subscribeheader" element="xsd1:SubscriptionHeader"/>
    </message>

    <portType name="StockQuotePortType">
        <operation name="SubscribeToQuotes">
           <input message="tns:SubscribeToQuotes"/>
        </operation>
    </portType>

    <binding name="StockQuoteSoap" type="tns:StockQuotePortType">
        <soap:binding style="document" transport="http://example.com/smtp"/>
        <operation name="SubscribeToQuotes">
           <input message="tns:SubscribeToQuotes">
               <soap:body parts="body" use="literal"/>
               <soap:header message="tns:SubscribeToQuotes" part="subscribeheader" use="literal"/>
           </input>
        </operation>
    </binding>

    <service name="StockQuoteService">
        <port name="StockQuotePort" binding="tns:StockQuoteSoap">
           <soap:address location="mailto:subscribe@example.com"/>
        </port>
    </service>

    <types>
        <schema targetNamespace="http://example.com/stockquote.xsd"
               xmlns="http://www.w3.org/2000/10/XMLSchema">
           <element name="SubscribeToQuotes">
               <complexType>
                   <all>
                       <element name="tickerSymbol" type="string"/>
                   </all>
               </complexType>
           </element>
           <element name="SubscriptionHeader" type="uriReference"/>
        </schema>
    </types>
</definitions>

`
var testData = []testWSDLInput{
	{
		wsdlDefinition:	holidayService,
		data: []testWSDLData{
			{
				servicePortNameMapping:	map[string]string{"HolidayService2": "HolidayService2Soap"},
				noOfEndpoints:		6,
				endpoints: []endpointData{
					{
						path:		"HolidayService2/GetHolidaysForDateRange",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForDateRange",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetCountriesAvailable",
						method:		"POST",
						matchPattern:	"HolidayService2/GetCountriesAvailable",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysAvailable",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysAvailable",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysForMonth",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForMonth",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysForYear",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForYear",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidayDate",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidayDate",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
				},
			},
			{
				servicePortNameMapping:	map[string]string{"HolidayService2": "HolidayService2HttpGet"},
				noOfEndpoints:		6,
				endpoints: []endpointData{
					{
						path:		"HolidayService2/GetHolidaysForDateRange",
						method:		"GET",
						matchPattern:	"(/GetHolidaysForDateRange.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetCountriesAvailable",
						method:		"GET",
						matchPattern:	"(/GetCountriesAvailable.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysAvailable",
						method:		"GET",
						matchPattern:	"(/GetHolidaysAvailable.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysForMonth",
						method:		"GET",
						matchPattern:	"(/GetHolidaysForMonth.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysForYear",
						method:		"GET",
						matchPattern:	"(/GetHolidaysForYear.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidayDate",
						method:		"GET",
						matchPattern:	"(/GetHolidayDate.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
				},
			},
			{
				servicePortNameMapping:	map[string]string{"HolidayService2": "HolidayService2HttpPost"},
				noOfEndpoints:		6,
				endpoints: []endpointData{
					{
						path:		"HolidayService2/GetHolidaysForDateRange",
						method:		"POST",
						matchPattern:	"(/GetHolidaysForDateRange.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetCountriesAvailable",
						method:		"POST",
						matchPattern:	"(/GetCountriesAvailable.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysAvailable",
						method:		"POST",
						matchPattern:	"(/GetHolidaysAvailable.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysForMonth",
						method:		"POST",
						matchPattern:	"(/GetHolidaysForMonth.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidaysForYear",
						method:		"POST",
						matchPattern:	"(/GetHolidaysForYear.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
					{
						path:		"HolidayService2/GetHolidayDate",
						method:		"POST",
						matchPattern:	"(/GetHolidayDate.*)",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx$1",
					},
				},
			},
			{
				servicePortNameMapping:	map[string]string{"HolidayService2": ""},
				noOfEndpoints:		6,
				endpoints: []endpointData{
					{
						path:		"HolidayService2/GetHolidaysForDateRange",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForDateRange",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetCountriesAvailable",
						method:		"POST",
						matchPattern:	"HolidayService2/GetCountriesAvailable",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysAvailable",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysAvailable",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysForMonth",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForMonth",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidaysForYear",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidaysForYear",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
					{
						path:		"HolidayService2/GetHolidayDate",
						method:		"POST",
						matchPattern:	"HolidayService2/GetHolidayDate",
						rewritePath:	"http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx",
					},
				},
			},
			{
				//invalid portName is provided
				//should throw an error
				servicePortNameMapping:	map[string]string{"HolidayService2": "something"},
				returnErr:		true,
			},
		},
	},
	{
		//smtp protocol is not supported
		//should throw error
		wsdlDefinition:	smtpExample,
		data: []testWSDLData{
			{
				servicePortNameMapping:	map[string]string{"StockQuoteService": "StockQuotePort"},
				returnErr:		true,
			},
		},
	},
	{
		//Invalid input
		wsdlDefinition:	"<ghfsdfjadhfkadf>",
		isInvalidInput:	true,
	},
	{
		//Invalid input
		wsdlDefinition:	wsdl_2_0_example,
		isInvalidInput:	true,
	},
}
var wsdl_2_0_example = `
<?xml version = "1.0" encoding = "utf-8" ?>
<description
    xmlns = "http://www.w3.org/ns/wsdl"
    targetNamespace = "http://yoursite.com/MyService"
    xmlns:tns = "http://yoursite.com/MyService"
    xmlns:stns = "http://yoursite.com/MyService/schema"
    xmlns:wsoap = "http://www.w3.org/ns/wsdl/soap"
    xmlns:soap = "http://www.w3.org/2003/05/soap-envelope"
    xmlns:wsdlx = "http://www.w3.org/ns/wsdl-extensions">
 
    <documentation>
        This document describes my Service. You can find additional information in
        the following web page: http://yoursite.com/MyService/help.html
    </documentation>
 
    <types>
        <xs:schema
        xmlns:xs = "http://www.w3.org/2001/XMLSchema"
        targetNamespace = "http://yoursite.com/MyService/schema"
        xmlns = "http://yoursite.com/MyService/schema" >
            <xs:element name = "checkServiceStatus" type="tCheckServiceStatus" />
            <xs:complexType name = "tCheckServiceStatus" >
                <xs:sequence>
                    <xs:element name = "checkDate" type = "xs:date" />
                    <xs:element name = "serviceName" type = "xs:string" />
                </xs:sequence>
            </xs:complexType>
            <xs:element name = " checkServiceStatusResponse" type = "xs:double" />
            <xs:element name = "dataError" type = "xs:string" />
        </xs:schema>
    </types>
 
    <interface name = "myServiceInterface">
        <fault name = "dataFault" element = "stns:dataError" />
        <operation name = "checkServiceStatusOp"
            pattern = "http://www.w3.org/ns/wsdl/in-out"
            style= " http://www.w3.org/ns/wsdl/style/iri"
            wsdlx:safe = "true">
            <input messageLabel = "In" element = "stns:checkServiceStatus" />
            <output messageLabel = "Out" element = "stns:checkServiceStatusResponse"/>
            <outfault messageLabel = "Out" ref = "tns:dataFault" />
        </operation>
    </interface>
 
    <binding name = "myServiceInterfaceSOAPBinding" 
          interface = "tns:myServiceInterface"
          type = "http://www.w3.org/ns/wsdl/soap"
          wsoap:protocol = "http://www.w3.org/2003/05/soap/bindings/HTTP/">
        <operation ref = "tns:checkServiceStatusOp" 
      wsoap:mep = "http://www.w3.org/2003/05/soap/mep/soap-response"/>
        <fault ref = "tns:dataFault" 
      wsoap:code = "soap:Sender"/>
    </binding>
 
    <service name = "myService" 
       interface = "tns:myServiceInterface">
        <endpoint name = "myServiceEndpoint" 
               binding = "tns:myServiceInterfaceSOAPBinding"
               address = "http://yoursite.com/MyService"/>
    </service>
</description>
`

Types

endpointData

This type doesn't have documentation.

Field name Field type Comment
method

string

No comment on field.
path

string

No comment on field.
matchPattern

string

No comment on field.
rewritePath

string

No comment on field.
type endpointData struct {
	method		string
	path		string
	matchPattern	string
	rewritePath	string
}

testWSDLData

This type doesn't have documentation.

Field name Field type Comment
servicePortNameMapping

map[string]string

No comment on field.
noOfEndpoints

int

No comment on field.
endpoints

[]endpointData

No comment on field.
returnErr

bool

No comment on field.
type testWSDLData struct {
	servicePortNameMapping	map[string]string
	noOfEndpoints		int
	endpoints		[]endpointData
	returnErr		bool
}

testWSDLInput

This type doesn't have documentation.

Field name Field type Comment
wsdlDefinition

string

No comment on field.
isInvalidInput

bool

No comment on field.
data

[]testWSDLData

No comment on field.
type testWSDLInput struct {
	wsdlDefinition	string
	isInvalidInput	bool
	data		[]testWSDLData
}

Test functions

TestToAPIDefinition_Swagger

References: assert.Equal, assert.Len, bytes.NewBufferString.

TestToAPIDefinition_WSDL

References: bytes.NewBufferString.