github.com/6543-forks/go-swagger@v0.26.0/generator/templates/schemapolymorphic.gotmpl (about) 1 {{ define "schemaPolymorphic" }} 2 type {{ pascalize .Name }} interface { 3 {{- if not (or .IsInterface .IsStream) }}{{/* 4 A base type is always Validatable. 5 Under normal conditions, we can't have a base type rendered a .IsStream or .IsInterface: this check is just for sanity check). 6 7 In the definition of the base type itself, this means that the unexported struct holding 8 the definition of the base type has a Validate() func. 9 */}} 10 runtime.Validatable 11 {{- end }} 12 {{ range .AllOf }} 13 {{- if .IsAnonymous }} 14 {{ range .Properties }} 15 {{ if $.IsTuple }}{{ template "tuplefieldIface" . }}{{ else }}{{template "structfieldIface" . }}{{ end }} 16 {{- end }} 17 {{ template "mapOrSliceGetter" . }} 18 {{- else }} 19 {{ .GoType }} 20 {{- end }} 21 {{- end }} 22 {{ range .Properties }} 23 {{- if $.IsTuple }} 24 {{ template "tuplefieldIface" . }} 25 {{- else }} 26 {{ template "structfieldIface" . }} 27 {{- end }} 28 {{- end }} 29 {{ template "mapOrSliceGetter" . }} 30 } 31 32 type {{ camelize .Name }} {{ template "schemaBody" . }}{{/* unexported implementation of the interface (TODO(fred): atm, this is not used, issue #232) */}} 33 {{- range .Properties }} 34 35 // {{ pascalize .Name}} gets the {{ humanize .Name }} of this polymorphic type 36 func ({{ $.ReceiverName}} *{{ camelize $.Name}}) {{ pascalize .Name}}() {{ template "schemaType" . }}{ 37 {{- if eq $.DiscriminatorField .Name }} 38 return {{ printf "%q" $.DiscriminatorValue }} 39 {{- else }} 40 return {{ $.ReceiverName }}.{{camelize .Name}}Field 41 {{- end }} 42 } 43 44 // Set{{ pascalize .Name}} sets the {{ humanize .Name }} of this polymorphic type 45 func ({{ $.ReceiverName}} *{{ camelize $.Name}}) Set{{ pascalize .Name}}(val {{ template "schemaType" . }}) { 46 {{- if ne $.DiscriminatorField .Name }} 47 {{ $.ReceiverName }}.{{camelize .Name}}Field = val 48 {{- end }} 49 } 50 {{- end }}{{/* TODO(fred): AdditionalProperties */}} 51 {{ template "polymorphicSerializer" . }} 52 {{- end }}