github.com/go-swagger/go-swagger@v0.31.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) }}
    26              {{ pascalize .AdditionalProperties.Name }}
    27            {{- else if or (not .AdditionalProperties.IsExported) (.AdditionalProperties.IsBaseType) }}
    28              {{ camelize .AdditionalProperties.Name }}Field
    29            {{- else }}
    30              {{ .AdditionalProperties.Name }}
    31            {{- end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
    32          {{- end }}
    33        {{- end }}
    34        {{- if .AdditionalItems }}
    35          // {{ template "docstring" .AdditionalItems }}
    36          {{- template "propertyValidationDocString" .AdditionalItems}}
    37          {{- if and .IsExported (not $.IsSubType) }}{{/* TODO(fred): make sure inherited AdditionalItems are camelized */}}
    38            {{ pascalize .AdditionalItems.Name }}
    39          {{- else }}
    40            {{ .AdditionalItems.Name }}
    41          {{- end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
    42        {{- end }}
    43      {{ else }}{{/* named type composition */}}
    44        {{ if not (and $.IsBaseType .IsExported) }}{{ .GoType }}{{ end }}
    45      {{ end }}
    46    {{ end }}
    47    {{range .Properties}}
    48      {{ if or (not $.IsExported) ($.IsBaseType) (.IsBaseType) }}
    49        {{ if $.IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}}
    50    {{ end }}
    51    {{ if .HasAdditionalProperties }}
    52      {{- if .AdditionalProperties }}
    53      // {{ template "docstring" .AdditionalProperties }}
    54      {{- template "propertyValidationDocString" .AdditionalProperties}}
    55        {{- if and .IsExported (not .IsSubType) }}
    56          {{ pascalize .AdditionalProperties.Name }}
    57        {{- else }}
    58        {{ pascalize .AdditionalProperties.Name }}Field
    59        {{- end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
    60      {{ end }}
    61    {{- end }}
    62    {{- if .AdditionalItems }}
    63      // {{ template "docstring" .AdditionalItems }}
    64      {{- template "propertyValidationDocString" .AdditionalItems}}
    65      {{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ pascalize .AdditionalItems.Name }}Field{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
    66    {{ end }}
    67  }
    68  {{- end }}
    69  
    70  {{ define "subTypeBody" }}struct {
    71    {{- range .AllOf }}
    72      {{- if or (and .IsBaseType .IsExported) .IsAnonymous }}
    73        {{- range .Properties }}
    74          {{- if not $.IsExported }}
    75            {{- if $.IsTuple }}
    76              {{- template "privtuplefield" . }}
    77            {{- else }}
    78              {{- template "privstructfield" . }}
    79            {{- end }}
    80          {{- else }}
    81            {{- if $.IsTuple }}
    82              {{- template "tuplefield" . }}
    83            {{- else }}
    84              {{- template "structfield" . }}
    85            {{- end }}
    86          {{- end }}
    87        {{- end }}
    88        {{- if .HasAdditionalProperties }}
    89          {{- if .AdditionalProperties }}
    90            {{- if .IsExported }}
    91              {{ pascalize .AdditionalProperties.Name }}
    92            {{- else }}
    93              {{ .AdditionalProperties.Name }}
    94            {{- end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
    95          {{- end }}
    96        {{- end }}
    97        {{- if .AdditionalItems }}
    98          {{- if .IsExported }}
    99            {{ pascalize .AdditionalItems.Name }}
   100          {{- else }}
   101            {{ .AdditionalItems.Name }}
   102          {{- end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   103        {{- end }}
   104      {{- else }}
   105        {{- if not (and .IsBaseType .IsExported) }}
   106          {{ .GoType }}
   107        {{- end }}
   108      {{- end }}
   109    {{- end }}
   110    {{ range .Properties }}
   111      {{- if not $.IsExported }}
   112        {{- if $.IsTuple }}
   113          {{ template "privtuplefield" . }}
   114        {{- else }}
   115          {{ template "privstructfield" . }}
   116        {{- end }}
   117      {{- else }}
   118        {{- if $.IsTuple }}
   119          {{ template "tuplefield" . }}
   120        {{- else }}
   121          {{ template "structfield" . }}
   122        {{- end }}
   123      {{- end}}
   124    {{- end }}
   125    {{- if .HasAdditionalProperties }}
   126      {{- if .AdditionalProperties }}
   127        {{- if and .IsExported }}
   128          {{ pascalize .AdditionalProperties.Name }}
   129        {{- else }}
   130        {{ pascalize .AdditionalProperties.Name }}Field
   131        {{- end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   132      {{- end }}
   133    {{- end }}
   134    {{- if .AdditionalItems }}
   135      {{- if and .IsExported (not .IsSubType) }}
   136        {{ pascalize .AdditionalItems.Name }}
   137      {{- else }}
   138        {{ pascalize .AdditionalItems.Name }}Field
   139      {{- end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   140    {{- end }}
   141  }
   142  {{- end }}
   143  
   144  {{ define "withBaseTypeBody" }}struct {
   145    {{ range .AllOf }}
   146    {{ if or (and .IsBaseType .IsExported) .IsAnonymous }}{{ range .Properties }}
   147    {{ if not .IsExported }}{{ if .IsTuple }}{{ template "privtuplefield" . }}{{ else }}{{template "privstructfield" . }}{{ end }}{{ else }}{{ if $.IsTuple }}{{ template "tuplefield" . }}{{ else }}{{template "structfield" . }}{{ end }}{{ end}}
   148    {{ end }}{{ if .HasAdditionalProperties }}{{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`  {{end}}
   149    {{ if .AdditionalItems }}{{ if and .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   150    {{ end }}
   151    {{ else }}
   152    {{ if not (and .IsBaseType .IsExported) }}{{ .GoType }}{{ end }}{{ end }}
   153    {{ end }}
   154    {{range .Properties}}{{ if .IsBaseType }}
   155    {{ if not $.IsExported }}{{ else }}{{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`{{ end}}
   156    {{end}}{{ end }}
   157    {{ if .HasAdditionalProperties }}{{ if and .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ pascalize .AdditionalProperties.Name }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   158    {{ end }}
   159    {{ if .AdditionalItems }}{{ if and .IsExported (not .IsSubType) }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ pascalize .AdditionalItems.Name }}Field{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   160    {{ end }}
   161  }
   162  {{- end }}
   163  
   164  {{ define "withoutBaseTypeBody" }}struct {
   165    {{ range .AllOf }}
   166      {{ if .IsAnonymous }}
   167        {{ range .Properties }}
   168          {{ if and .IsExported (not .IsBaseType) }}
   169            {{ if .IsTuple }}
   170              {{ template "tuplefield" . }}
   171            {{ else }}
   172              {{template "structfield" . }}
   173            {{ end }}
   174          {{ else }}
   175            {{ pascalize .Name }} json.RawMessage `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   176          {{ end}}
   177        {{ end }}
   178        {{ if .HasAdditionalProperties }}
   179          {{ if .AdditionalProperties }}
   180            {{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   181          {{end}}
   182        {{ end }}
   183        {{ if .AdditionalItems }}
   184          {{ if .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   185        {{ end }}
   186      {{ else }}
   187        {{ if not (and .IsBaseType .IsExported) }}
   188          {{ .GoType }}
   189        {{ end }}
   190      {{ end }}
   191    {{ end }}
   192    {{range .Properties}}
   193      {{ if not .IsBaseType }}
   194        {{ if not $.IsExported }}
   195          {{template "privstructfield" . }}
   196        {{ else }}
   197          {{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   198        {{ end}}
   199      {{ else }}
   200        {{ pascalize .Name }} json.RawMessage `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   201      {{end}}
   202    {{ end }}
   203    {{ if .HasAdditionalProperties }}
   204      {{ pascalize .AdditionalProperties.Name }}{{ if .IsExported }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   205    {{ end }}
   206  }
   207  {{- end }}
   208  
   209  {{ define "withoutBaseTypeBodyOrNonExported" }}struct {
   210    {{ range .AllOf }}
   211      {{ if .IsAnonymous }}
   212        {{ range .Properties }}
   213          {{ if and .IsExported (not .IsBaseType) }}
   214            {{ if .IsTuple }}
   215              {{ template "tuplefield" . }}
   216            {{ else }}
   217              {{template "structfield" . }}
   218            {{ end }}
   219          {{ end}}
   220        {{ end }}
   221        {{ if .HasAdditionalProperties }}
   222          {{ if .AdditionalProperties }}
   223            {{ if .IsExported }}{{ pascalize .AdditionalProperties.Name }}{{ else }}{{ .AdditionalProperties.Name }}{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   224          {{end}}
   225        {{ end }}
   226        {{ if .AdditionalItems }}
   227          {{ if .IsExported }}{{ pascalize .AdditionalItems.Name }}{{ else }}{{ .AdditionalItems.Name }}{{ end }} []{{ template "schemaType" .AdditionalItems }} `json:"-"`
   228        {{ end }}
   229        {{ else }}
   230          {{ if not (and .IsBaseType .IsExported) }}
   231            {{ .GoType }}
   232          {{ end }}
   233        {{ end }}
   234      {{ end }}
   235    {{range .Properties}}
   236      {{ if not .IsBaseType }}
   237        {{ if not .IsExported }}
   238          {{template "privstructfield" . }}
   239        {{ else }}
   240          {{ pascalize .Name}} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   241        {{ end}}
   242      {{end}}
   243    {{ end }}
   244    {{ if .HasAdditionalProperties }}
   245      {{ pascalize .AdditionalProperties.Name }}{{ if .IsExported }}Field{{ end }} map[string]{{ template "schemaType" .AdditionalProperties }} `json:"-"`
   246    {{ end }}}{
   247    {{ range .AllOf }}
   248      {{ if .IsAnonymous }}
   249        {{ range .Properties }}
   250          {{ if not .IsBaseType }}
   251            {{ pascalize .Name }}: {{ .ReceiverName}}.{{ pascalize .Name }},
   252          {{ end }}
   253        {{ end }}
   254      {{ else }}
   255        {{ if not (and .IsBaseType .IsExported) }}
   256          {{ .GoType }}: {{ .ReceiverName }}.{{ .GoType }},
   257        {{ end }}
   258      {{ end }}
   259    {{ end }}
   260    {{ range .Properties }}
   261      {{ if and (not .IsBaseType) .IsExported }}
   262        {{ pascalize .Name }}: {{ .ReceiverName }}.{{ pascalize .Name }},
   263      {{ end }}
   264    {{ end }}
   265    },
   266  {{- end }}
   267  
   268  {{ define "withBaseTypeBodyAndNonExported" }}struct{
   269    {{ range .AllOf }}
   270      {{ range .Properties }}
   271        {{ if .IsBaseType }}
   272          {{ pascalize .Name }} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   273        {{ end }}
   274      {{ end }}
   275    {{ end }}
   276    {{ range .Properties }}
   277      {{ if or (not .IsExported) .IsBaseType }}
   278        {{ pascalize .Name }} {{ template "schemaType" . }} `json:"{{ .Name }}{{ if and (not .Required) .IsEmptyOmitted }},omitempty{{ end }}{{ if .IsJSONString }},string{{ end }}"`
   279      {{ end }}
   280    {{end}}} {
   281    {{ range .AllOf }}
   282      {{ range .Properties }}
   283       {{ if .IsBaseType }}
   284         {{ pascalize .Name }}:
   285         {{ if ne .DiscriminatorField .Name }}
   286           {{ .ReceiverName }}.{{ if .IsSubType}}{{ camelize .Name }}Field{{ else }}{{ pascalize .Name }}(){{ end }},
   287         {{ else }}
   288           {{ .ReceiverName }}.{{pascalize .Name}}(),
   289         {{ end }}
   290       {{ end }}
   291      {{ end }}
   292    {{ end }}
   293    {{ range .Properties }}
   294      {{ if or (not .IsExported) .IsBaseType }}
   295        {{ pascalize .Name }}: {{ .ReceiverName }}.{{ if .IsBaseType}}{{ camelize .Name }}Field{{ else }}{{ pascalize .Name }}{{ end }},
   296      {{ end }}
   297    {{ end }} },
   298  {{- end }}
   299  
   300  {{ define "withoutAdditionalBody" }}struct {
   301    {{ range .AllOf }}
   302    {{ if or (and $.IsSubType .IsBaseType .IsExported) .IsAnonymous }}{{ range .Properties }}
   303    {{ 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 }}
   304    {{ end }}
   305    {{ else }}
   306    {{ if not (and .IsBaseType .IsExported) }}{{ .GoType }}{{ end }}{{ end }}
   307    {{ end }}
   308    {{range .Properties}}
   309    {{ 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}}
   310    {{end}}
   311  }
   312  {{- end }}
   313  
   314  {{ define "JustBaseTypeBody" }}struct {
   315    /* Just the base type fields. Used for unmashalling polymorphic types.*/
   316    {{ range .AllOf }}
   317      {{ if .IsBaseType }}
   318        {{ range .Properties }}
   319          {{ if .IsExported }}
   320            {{ if .IsTuple }}
   321              {{ template "tuplefield" . }}
   322            {{ else }}
   323              {{template "structfield" . }}
   324            {{ end }}
   325          {{ end }}
   326        {{ end }}
   327      {{ end }}
   328    {{ end }}
   329  }
   330  {{- end }}