github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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 and a ContextValitate() func. 9 */}} 10 runtime.Validatable 11 runtime.ContextValidatable 12 {{- end }} 13 {{ range .AllOf }} 14 {{- if .IsAnonymous }} 15 {{ range .Properties }} 16 {{ if $.IsTuple }}{{ template "tuplefieldIface" . }}{{ else }}{{template "structfieldIface" . }}{{ end }} 17 {{- end }} 18 {{ template "mapOrSliceGetter" . }} 19 {{- else }} 20 {{ .GoType }} 21 {{- end }} 22 {{- end }} 23 {{ range .Properties }} 24 {{- if $.IsTuple }} 25 {{ template "tuplefieldIface" . }} 26 {{- else }} 27 {{ template "structfieldIface" . }} 28 {{- end }} 29 {{- end }} 30 {{ template "mapOrSliceGetter" . }} 31 } 32 33 type {{ camelize .Name }} {{ template "schemaBody" . }}{{/* unexported implementation of the interface (TODO(fred): atm, this is not used, issue #232) */}} 34 {{- range .Properties }} 35 36 // {{ pascalize .Name}} gets the {{ humanize .Name }} of this polymorphic type 37 func ({{ $.ReceiverName}} *{{ camelize $.Name}}) {{ pascalize .Name}}() {{ template "schemaType" . }}{ 38 {{- if eq $.DiscriminatorField .Name }} 39 return {{ printf "%q" $.DiscriminatorValue }} 40 {{- else }} 41 return {{ $.ReceiverName }}.{{camelize .Name}}Field 42 {{- end }} 43 } 44 45 // Set{{ pascalize .Name}} sets the {{ humanize .Name }} of this polymorphic type 46 func ({{ $.ReceiverName}} *{{ camelize $.Name}}) Set{{ pascalize .Name}}(val {{ template "schemaType" . }}) { 47 {{- if ne $.DiscriminatorField .Name }} 48 {{ $.ReceiverName }}.{{camelize .Name}}Field = val 49 {{- end }} 50 } 51 {{- end }}{{/* TODO(fred): AdditionalProperties */}} 52 {{ template "polymorphicSerializer" . }} 53 {{- end }}