Skip to content

Commit

Permalink
Add json and yaml tags
Browse files Browse the repository at this point in the history
  • Loading branch information
fiorix committed Mar 22, 2016
1 parent b7f311f commit 45740f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions wsdlgo/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 11 additions & 11 deletions wsdlgo/testdata/memcache.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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"`
}
12 changes: 6 additions & 6 deletions wsdlgo/testdata/w3example1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
8 changes: 4 additions & 4 deletions wsdlgo/testdata/w3example2.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 45740f9

Please sign in to comment.