github.com/livermorium/go-swagger@v0.19.0/generator/templates/schemabody.gotmpl (about) 1 {{ define "schemaBody" }}struct { 2 {{ range .AllOf }} 3 {{ if or (and $.IsSubType .IsBaseType .IsExported) .IsAnonymous }} 4 {{ range .Properties }} 5 {{ if ne $.DiscriminatorField .Name }} 6 {{ if or (not $.IsExported) (and $.IsSubType .IsBaseType) }} 7 {{ if $.IsTuple }} 8 {{ template "privtuplefield" . }} 9 {{ else }} 10 {{template "privstructfield" . }} 11 {{ end }} 12 {{ else }} 13 {{ if $.IsTuple }} 14 {{ template "tuplefield" . }} 15 {{ else }} 16 {{template "structfield" . }} 17 {{ end }} 18 {{ end}} 19 {{ end }} 20 {{ end }} 21 {{- if .HasAdditionalProperties }} 22 {{- if .AdditionalProperties -}} 23 // {{ template "docstring" .AdditionalProperties }} 24 {{- template "propertyValidationDocString" .AdditionalProperties}} 25 {{ if and .IsExported (not .IsSubType) -}}{{ pascalize .AdditionalProperties.Name }}{{- else -}}{{ .AdditionalProperties.Name }}{{- end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 26 {{ end }} 27 {{ end}} 28 {{ if .AdditionalItems -}} 29 // {{ template "docstring" .AdditionalItems }} 30 {{- template "propertyValidationDocString" .AdditionalItems}} 31 {{ if and .IsExported (not $.IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 32 {{ end }} 33 {{ else }}{{/* named type composition */}} 34 {{ if not (and $.IsBaseType .IsExported) }}{{ .GoType }}{{ end }} 35 {{ end }} 36 {{ end }} 37 {{range .Properties}} 38 {{ if or (not $.IsExported) ($.IsBaseType) (.IsBaseType) }} 39 {{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}} 40 {{ end }} 41 {{ if .HasAdditionalProperties }} 42 {{- if .AdditionalProperties -}} 43 // {{ template "docstring" .AdditionalProperties }} 44 {{- template "propertyValidationDocString" .AdditionalProperties}} 45 {{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ pascalize .AdditionalProperties.Name }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 46 {{ end }} 47 {{- end }} 48 {{ if .AdditionalItems -}} 49 // {{ template "docstring" .AdditionalItems }} 50 {{- template "propertyValidationDocString" .AdditionalItems}} 51 {{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ pascalize .AdditionalItems.Name }}Field{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 52 {{ end }} 53 } 54 {{- end }} 55 {{ define "subTypeBody" }}struct { 56 {{ range .AllOf }} 57 {{ if or (and .IsBaseType .IsExported) .IsAnonymous }}{{ range .Properties }} 58 {{ if not $.IsExported }}{{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}} 59 {{ end }}{{ if .HasAdditionalProperties }}{{ if .AdditionalProperties }}{{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` {{end}}{{ end }} 60 {{ if .AdditionalItems }}{{ if and .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 61 {{ end }} 62 {{ else }} 63 {{ if not (and .IsBaseType .IsExported) }}{{ .GoType }}{{ end }}{{ end }} 64 {{ end }} 65 {{range .Properties}} 66 {{ if not $.IsExported }}{{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}} 67 {{end}} 68 {{ if .HasAdditionalProperties }}{{ if .AdditionalProperties }}{{ if and .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ pascalize .AdditionalProperties.Name }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`{{ end }} 69 {{ end }} 70 {{ if .AdditionalItems }}{{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ pascalize .AdditionalItems.Name }}Field{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 71 {{ end }} 72 }{{ end }} 73 {{ define "withBaseTypeBody" }}struct { 74 {{ range .AllOf }} 75 {{ if or (and .IsBaseType .IsExported) .IsAnonymous }}{{ range .Properties }} 76 {{ if not .IsExported }}{{ if .IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}} 77 {{ end }}{{ if .HasAdditionalProperties }}{{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` {{end}} 78 {{ if .AdditionalItems }}{{ if and .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 79 {{ end }} 80 {{ else }} 81 {{ if not (and .IsBaseType .IsExported) }}{{ .GoType }}{{ end }}{{ end }} 82 {{ end }} 83 {{range .Properties}}{{ if .IsBaseType }} 84 {{ if not $.IsExported }}{{ else }}{{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"`{{ end}} 85 {{end}}{{ end }} 86 {{ if .HasAdditionalProperties }}{{ if and .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ pascalize .AdditionalProperties.Name }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 87 {{ end }} 88 {{ if .AdditionalItems }}{{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ pascalize .AdditionalItems.Name }}Field{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 89 {{ end }} 90 }{{ end }} 91 92 {{ define "withoutBaseTypeBody" }}struct { 93 {{ range .AllOf }} 94 {{ if .IsAnonymous }} 95 {{ range .Properties }} 96 {{ if and .IsExported (not .IsBaseType) }} 97 {{ if .IsTuple }} 98 {{ template "tuplefield" . }} 99 {{ else }} 100 {{template "structfield" . }} 101 {{ end }} 102 {{ else }} 103 {{ pascalize .Name }} json.RawMessage `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 104 {{ end}} 105 {{ end }} 106 {{ if .HasAdditionalProperties }} 107 {{ if .AdditionalProperties }} 108 {{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 109 {{end}} 110 {{ end }} 111 {{ if .AdditionalItems }} 112 {{ if .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 113 {{ end }} 114 {{ else }} 115 {{ if not (and .IsBaseType .IsExported) }} 116 {{ .GoType }} 117 {{ end }} 118 {{ end }} 119 {{ end }} 120 {{range .Properties}} 121 {{ if not .IsBaseType }} 122 {{ if not $.IsExported }} 123 {{template "privstructfield" . }} 124 {{ else }} 125 {{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 126 {{ end}} 127 {{ else }} 128 {{ pascalize .Name }} json.RawMessage `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 129 {{end}} 130 {{ end }} 131 {{ if .HasAdditionalProperties }} 132 {{ pascalize .AdditionalProperties.Name }}{{ if .IsExported }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 133 {{ end }} 134 }{{ end }} 135 136 {{ define "withoutBaseTypeBodyOrNonExported" }}struct { 137 {{ range .AllOf }} 138 {{ if .IsAnonymous }} 139 {{ range .Properties }} 140 {{ if and .IsExported (not .IsBaseType) }} 141 {{ if .IsTuple }} 142 {{ template "tuplefield" . }} 143 {{ else }} 144 {{template "structfield" . }} 145 {{ end }} 146 {{ end}} 147 {{ end }} 148 {{ if .HasAdditionalProperties }} 149 {{ if .AdditionalProperties }} 150 {{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 151 {{end}} 152 {{ end }} 153 {{ if .AdditionalItems }} 154 {{ if .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"` 155 {{ end }} 156 {{ else }} 157 {{ if not (and .IsBaseType .IsExported) }} 158 {{ .GoType }} 159 {{ end }} 160 {{ end }} 161 {{ end }} 162 {{range .Properties}} 163 {{ if not .IsBaseType }} 164 {{ if not .IsExported }} 165 {{template "privstructfield" . }} 166 {{ else }} 167 {{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 168 {{ end}} 169 {{end}} 170 {{ end }} 171 {{ if .HasAdditionalProperties }} 172 {{ pascalize .AdditionalProperties.Name }}{{ if .IsExported }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"` 173 {{ end }}}{ 174 {{ range .AllOf }} 175 {{ if .IsAnonymous }} 176 {{ range .Properties }} 177 {{ if not .IsBaseType }} 178 {{ pascalize .Name }}: {{ .ReceiverName}}.{{ pascalize .Name }}, 179 {{ end }} 180 {{ end }} 181 {{ else }} 182 {{ if not (and .IsBaseType .IsExported) }} 183 {{ .GoType }}: {{ .ReceiverName }}.{{ .GoType }}, 184 {{ end }} 185 {{ end }} 186 {{ end }} 187 {{ range .Properties }} 188 {{ if and (not .IsBaseType) .IsExported }} 189 {{ pascalize .Name }}: {{ .ReceiverName }}.{{ pascalize .Name }}, 190 {{ end }} 191 {{ end }} 192 }, 193 {{ end }} 194 195 {{ define "withBaseTypeBodyAndNonExported" }}struct{ 196 {{ range .AllOf }} 197 {{ range .Properties }} 198 {{ if .IsBaseType }} 199 {{ pascalize .Name }} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 200 {{ end }} 201 {{ end }} 202 {{ end }} 203 {{ range .Properties }} 204 {{ if or (not .IsExported) .IsBaseType }} 205 {{ pascalize .Name }} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}"` 206 {{ end }} 207 {{end}}} { 208 {{ range .AllOf }} 209 {{ range .Properties }} 210 {{ if .IsBaseType }} 211 {{ pascalize .Name }}: 212 {{ if ne .DiscriminatorField .Name }} 213 {{ .ReceiverName }}.{{ if .IsSubType}}{{ camelize .Name }}Field{{ else }}{{ pascalize .Name }}(){{ end }}, 214 {{ else }} 215 {{ .ReceiverName }}.{{pascalize .Name}}(), 216 {{ end }} 217 {{ end }} 218 {{ end }} 219 {{ end }} 220 {{ range .Properties }} 221 {{ if or (not .IsExported) .IsBaseType }} 222 {{ pascalize .Name }}: {{ .ReceiverName }}.{{ if .IsBaseType}}{{ camelize .Name }}Field{{ else }}{{ pascalize .Name }}{{ end }}, 223 {{ end }} 224 {{ end }} }, 225 {{ end }} 226 227 {{ define "withoutAdditionalBody" }}struct { 228 {{ range .AllOf }} 229 {{ if or (and $.IsSubType .IsBaseType .IsExported) .IsAnonymous }}{{ range .Properties }} 230 {{ if ne $.DiscriminatorField .Name }}{{ if or (not $.IsExported) (and $.IsSubType .IsBaseType) }}{{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}}{{ end }} 231 {{ end }} 232 {{ else }} 233 {{ if not (and .IsBaseType .IsExported) }}{{ .GoType }}{{ end }}{{ end }} 234 {{ end }} 235 {{range .Properties}} 236 {{ if or (not $.IsExported) (and $.IsSubType .IsBaseType) }}{{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}} 237 {{end}} 238 }{{end}} 239 240 {{ define "JustBaseTypeBody" }}struct { 241 /* Just the base type fields. Used for unmashalling polymorphic types.*/ 242 {{ range .AllOf }} 243 {{ if .IsBaseType }} 244 {{ range .Properties }} 245 {{ if .IsExported }} 246 {{ if .IsTuple }} 247 {{ template "tuplefield" . }} 248 {{ else }} 249 {{template "structfield" . }} 250 {{ end }} 251 {{ end }} 252 {{ end }} 253 {{ end }} 254 {{ end }} 255 }{{end}} 256