(ut expr.UserType, req, ptr, server bool, rd *ServiceData)
| 2870 | } |
| 2871 | |
| 2872 | func (sds *ServicesData) attributeTypeData(ut expr.UserType, req, ptr, server bool, rd *ServiceData) *TypeData { |
| 2873 | if ut == expr.Empty { |
| 2874 | return nil |
| 2875 | } |
| 2876 | seen := rd.ServerTypeNames |
| 2877 | if !server { |
| 2878 | seen = rd.ClientTypeNames |
| 2879 | } |
| 2880 | if _, ok := seen[ut.Name()]; ok { |
| 2881 | return nil |
| 2882 | } |
| 2883 | seen[ut.Name()] = false |
| 2884 | |
| 2885 | var ( |
| 2886 | name string |
| 2887 | desc string |
| 2888 | validate string |
| 2889 | validateRef string |
| 2890 | |
| 2891 | att = &expr.AttributeExpr{Type: ut} |
| 2892 | hctx = httpContext(rd.Scope, req, server) |
| 2893 | ) |
| 2894 | name = rd.Scope.GoTypeName(att) |
| 2895 | ctx := "request" |
| 2896 | if !req { |
| 2897 | ctx = "response" |
| 2898 | } |
| 2899 | desc = name + " is used to define fields on " + ctx + " body types." |
| 2900 | if (req || !req && !server) && !expr.IsAlias(ut) { |
| 2901 | // Generate validations for responses client-side and for |
| 2902 | // requests server-side and CLI. |
| 2903 | // Alias types are validated inline in the parent type |
| 2904 | validate = codegen.ValidationCode(ut.Attribute(), ut, hctx, true, expr.IsAlias(ut), false, "body") |
| 2905 | } |
| 2906 | if validate != "" { |
| 2907 | validateRef = fmt.Sprintf("err = Validate%s(v)", name) |
| 2908 | } |
| 2909 | return &TypeData{ |
| 2910 | Name: ut.Name(), |
| 2911 | VarName: name, |
| 2912 | Description: desc, |
| 2913 | Def: goTypeDef(rd.Scope, ut.Attribute(), ptr, hctx.UseDefault), |
| 2914 | Ref: rd.Scope.GoTypeRef(att), |
| 2915 | ValidateDef: validate, |
| 2916 | ValidateRef: validateRef, |
| 2917 | Example: att.Example(sds.Root.API.ExampleGenerator), |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | // httpContext returns a context for attributes of types used to marshal and |
| 2922 | // unmarshal HTTP requests and responses. |
no test coverage detected