From 45740f9e7be9135772d8aaa115bfb47108151c1f Mon Sep 17 00:00:00 2001 From: Alexandre Fiori Date: Mon, 21 Mar 2016 22:59:25 -0400 Subject: [PATCH] Add json and yaml tags --- wsdlgo/encoder.go | 8 ++++---- wsdlgo/testdata/memcache.golden | 22 +++++++++++----------- wsdlgo/testdata/w3example1.golden | 12 ++++++------ wsdlgo/testdata/w3example2.golden | 8 ++++---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/wsdlgo/encoder.go b/wsdlgo/encoder.go index 02a4cf0..44b64e7 100644 --- a/wsdlgo/encoder.go +++ b/wsdlgo/encoder.go @@ -666,7 +666,7 @@ func (ge *goEncoder) genGoStruct(w io.Writer, ct *wsdl.ComplexType) error { ge.writeComments(w, ct.Name, ct.Doc) fmt.Fprintf(w, "type %s struct {\n", strings.Title(ct.Name)) if tag, exists := ge.needsNSTag[ct.Name]; exists { - fmt.Fprintf(w, "XMLName xml.Name `xml:\"ns:%s\" json:\"-\"`\n", tag) + fmt.Fprintf(w, "XMLName xml.Name `xml:\"ns:%s\" json:\"-\" yaml:\"-\"`\n", tag) } err := ge.genStructFields(w, ct) if err != nil { @@ -747,11 +747,11 @@ func (ge *goEncoder) genElementField(w io.Writer, el *wsdl.Element) { } } typ := ge.wsdl2goType(el.Type, "") - fmt.Fprintf(w, "%s `xml:\"%s", typ, tag) if el.Nillable || el.Min == 0 { - fmt.Fprintf(w, ",omitempty") + tag += ",omitempty" } - fmt.Fprintf(w, "\"`\n") + fmt.Fprintf(w, "%s `xml:\"%s\" json:\"%s\" yaml:\"%s\"`\n", + typ, tag, tag, tag) } // writeComments writes comments to w, capped at ~80 columns. diff --git a/wsdlgo/testdata/memcache.golden b/wsdlgo/testdata/memcache.golden index b7a0e21..cac4e64 100644 --- a/wsdlgo/testdata/memcache.golden +++ b/wsdlgo/testdata/memcache.golden @@ -18,7 +18,7 @@ func Get(cli soap.RoundTripper, α string) (β *GetResponse, err error) { } }{} if err = cli.RoundTrip(α, &γ); err != nil { - return &GetResponse{}, err + return nil, err } return &γ.Body.M, nil } @@ -46,7 +46,7 @@ func GetMulti(cli soap.RoundTripper, α *GetMultiRequest) (β *GetMultiResponse, } }{} if err = cli.RoundTrip(α, &γ); err != nil { - return &GetMultiResponse{}, err + return nil, err } return &γ.Body.M, nil } @@ -56,25 +56,25 @@ type Duration string // GetMultiRequest was auto-generated from WSDL. type GetMultiRequest struct { - XMLName xml.Name `xml:"ns:GetMultiRequest" json:"-"` - Keys []string `xml:"Keys"` + XMLName xml.Name `xml:"ns:GetMultiRequest" json:"-" yaml:"-"` + Keys []string `xml:"Keys" json:"Keys" yaml:"Keys"` } // GetMultiResponse was auto-generated from WSDL. type GetMultiResponse struct { - Values []*GetResponse `xml:"Values,omitempty"` + Values []*GetResponse `xml:"Values,omitempty" json:"Values,omitempty" yaml:"Values,omitempty"` } // GetResponse carries value and TTL. type GetResponse struct { - Value string `xml:"Value,omitempty"` - TTL Duration `xml:"TTL,omitempty"` + Value string `xml:"Value,omitempty" json:"Value,omitempty" yaml:"Value,omitempty"` + TTL Duration `xml:"TTL,omitempty" json:"TTL,omitempty" yaml:"TTL,omitempty"` } // SetRequest carries a key-value pair. type SetRequest struct { - XMLName xml.Name `xml:"ns:SetRequest" json:"-"` - Key string `xml:"Key"` - Value string `xml:"Value"` - Expiration Duration `xml:"Expiration,omitempty"` + XMLName xml.Name `xml:"ns:SetRequest" json:"-" yaml:"-"` + Key string `xml:"Key" json:"Key" yaml:"Key"` + Value string `xml:"Value" json:"Value" yaml:"Value"` + Expiration Duration `xml:"Expiration,omitempty" json:"Expiration,omitempty" yaml:"Expiration,omitempty"` } diff --git a/wsdlgo/testdata/w3example1.golden b/wsdlgo/testdata/w3example1.golden index 519d08b..7eb84de 100644 --- a/wsdlgo/testdata/w3example1.golden +++ b/wsdlgo/testdata/w3example1.golden @@ -18,24 +18,24 @@ func GetEndorsingBoarder(cli soap.RoundTripper, α *GetEndorsingBoarderRequest) } }{} if err = cli.RoundTrip(α, &γ); err != nil { - return &GetEndorsingBoarderResponse{}, err + return nil, err } return &γ.Body.M, nil } // GetEndorsingBoarderFault was auto-generated from WSDL. type GetEndorsingBoarderFault struct { - ErrorMessage string `xml:"errorMessage,omitempty"` + ErrorMessage string `xml:"errorMessage,omitempty" json:"errorMessage,omitempty" yaml:"errorMessage,omitempty"` } // GetEndorsingBoarderRequest was auto-generated from WSDL. type GetEndorsingBoarderRequest struct { - XMLName xml.Name `xml:"ns:GetEndorsingBoarder" json:"-"` - Manufacturer string `xml:"manufacturer,omitempty"` - Model string `xml:"model,omitempty"` + XMLName xml.Name `xml:"ns:GetEndorsingBoarder" json:"-" yaml:"-"` + Manufacturer string `xml:"manufacturer,omitempty" json:"manufacturer,omitempty" yaml:"manufacturer,omitempty"` + Model string `xml:"model,omitempty" json:"model,omitempty" yaml:"model,omitempty"` } // GetEndorsingBoarderResponse was auto-generated from WSDL. type GetEndorsingBoarderResponse struct { - EndorsingBoarder string `xml:"endorsingBoarder,omitempty"` + EndorsingBoarder string `xml:"endorsingBoarder,omitempty" json:"endorsingBoarder,omitempty" yaml:"endorsingBoarder,omitempty"` } diff --git a/wsdlgo/testdata/w3example2.golden b/wsdlgo/testdata/w3example2.golden index 62ddb1c..21ff547 100644 --- a/wsdlgo/testdata/w3example2.golden +++ b/wsdlgo/testdata/w3example2.golden @@ -18,18 +18,18 @@ func GetLastTradePrice(cli soap.RoundTripper, α *TradePriceRequest) (β *TradeP } }{} if err = cli.RoundTrip(α, &γ); err != nil { - return &TradePriceResponse{}, err + return nil, err } return &γ.Body.M, nil } // TradePriceRequest was auto-generated from WSDL. type TradePriceRequest struct { - XMLName xml.Name `xml:"ns:TradePriceRequest" json:"-"` - TickerSymbol string `xml:"tickerSymbol,omitempty"` + XMLName xml.Name `xml:"ns:TradePriceRequest" json:"-" yaml:"-"` + TickerSymbol string `xml:"tickerSymbol,omitempty" json:"tickerSymbol,omitempty" yaml:"tickerSymbol,omitempty"` } // TradePriceResponse was auto-generated from WSDL. type TradePriceResponse struct { - Price float64 `xml:"price,omitempty"` + Price float64 `xml:"price,omitempty" json:"price,omitempty" yaml:"price,omitempty"` }