MCPcopy Create free account
hub / github.com/goadesign/goa / attributeTypeData

Method attributeTypeData

http/codegen/service_data.go:2872–2919  ·  view source on GitHub ↗
(ut expr.UserType, req, ptr, server bool, rd *ServiceData)

Source from the content-addressed store, hash-verified

2870}
2871
2872func (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.

Callers 2

analyzeMethod · 0.95
buildResponseBodyTypeMethod · 0.95

Calls 9

IsAliasFunction · 0.92
ValidationCodeFunction · 0.92
httpContextFunction · 0.85
goTypeDefFunction · 0.85
GoTypeNameMethod · 0.80
GoTypeRefMethod · 0.80
NameMethod · 0.65
AttributeMethod · 0.65
ExampleMethod · 0.65

Tested by

no test coverage detected