anz-bank / sysl-go

Communication library used by SYSL-generated code written in Go.
Apache License 2.0
10 stars 14 forks source link

Json validation tags differ from base struct #169

Closed andrewemeryanz closed 4 years ago

andrewemeryanz commented 4 years ago

The json tags on public type structs and type structs used for json validation are inconsistent.

If the PostRequest type is modified in simple.sysl to:

!type PostRequest:
    Bt <: bool?:
        @json_tag = "Bt"
    Dt <: datetime:
        @json_tag = "Dt"
    St <: string:
        @json_tag = "St"
    Lower <: string:
        @json_tag = "lower"
    Upper <: string:
        @json_tag = "UPPER"

Then the following is generated:

// PostRequest ...
type PostRequest struct {
    Bt    *bool            `json:"Bt,omitempty"`
    Dt    convert.JSONTime `json:"Dt"`
    St    string           `json:"St"`
    Lower string           `json:"lower"`
    Upper string           `json:"upper"`  // incorrect, should be `json:"UPPER,omitempty"`
}

func (t *PostRequest) UnmarshalJSON(data []byte) error {
    inner := struct {
        Bt    *bool             `json:"Bt,omitempty"`
        Dt    *convert.JSONTime `json:"Dt,omitempty"`
        St    *string           `json:"St,omitempty"`
        Lower *string           `json:"Lower,omitempty"`  // incorrect, should be `json:"lower,omitempty"`
        Upper *string           `json:"Upper,omitempty"`  // incorrect, should be `json:"UPPER,omitempty"`
    }
...
}