(att *expr.AttributeExpr, seen map[string]struct{})
| 1030 | } |
| 1031 | |
| 1032 | func makeHTTPTypeRecursive(att *expr.AttributeExpr, seen map[string]struct{}) *expr.AttributeExpr { |
| 1033 | switch dt := att.Type.(type) { |
| 1034 | case expr.UserType: |
| 1035 | if _, ok := dt.(*expr.ResultTypeExpr); !ok && !expr.IsObject(dt) { |
| 1036 | // Aliased user type. Use the underlying aliased type instead of |
| 1037 | // generating new types in the client and server packages |
| 1038 | att.Type = dt.Attribute().Type |
| 1039 | if v := dt.Attribute().Validation; v != nil { |
| 1040 | if att.Validation == nil { |
| 1041 | att.Validation = v |
| 1042 | } else { |
| 1043 | att.Validation.Merge(v) |
| 1044 | } |
| 1045 | } |
| 1046 | att.DefaultValue = dt.Attribute().DefaultValue |
| 1047 | att.UserExamples = dt.Attribute().UserExamples |
| 1048 | } |
| 1049 | if _, ok := seen[dt.ID()]; ok { |
| 1050 | return att |
| 1051 | } |
| 1052 | seen[dt.ID()] = struct{}{} |
| 1053 | dt.SetAttribute(makeHTTPTypeRecursive(dt.Attribute(), seen)) |
| 1054 | case *expr.Array: |
| 1055 | dt.ElemType = makeHTTPTypeRecursive(dt.ElemType, seen) |
| 1056 | case *expr.Map: |
| 1057 | dt.KeyType = makeHTTPTypeRecursive(dt.KeyType, seen) |
| 1058 | dt.ElemType = makeHTTPTypeRecursive(dt.ElemType, seen) |
| 1059 | case *expr.Object: |
| 1060 | obj := make(expr.Object, len(*dt)) |
| 1061 | for i, nat := range *dt { |
| 1062 | obj[i] = &expr.NamedAttributeExpr{Name: nat.Name, Attribute: makeHTTPTypeRecursive(nat.Attribute, seen)} |
| 1063 | } |
| 1064 | att.Type = &obj |
| 1065 | case *expr.Union: |
| 1066 | // Unions are represented as first-class sum types; HTTP uses the same |
| 1067 | // type for request and response bodies. |
| 1068 | } |
| 1069 | return att |
| 1070 | } |
| 1071 | |
| 1072 | // buildPayloadData returns the data structure used to describe the endpoint |
| 1073 | // payload including the HTTP request details. It also returns the user types |
no test coverage detected