@@ -25,41 +25,42 @@ func init() {
2525 strictNameRegex = regexp .MustCompile (`^([a-z]|[a-z]+((\d)|([A-Z\d][a-z\d]+))*([A-Z\d][a-z\d]*[a-z]))$` )
2626}
2727
28- type memberNameValidationMode int
28+ // MemberNameValidationMode controls how document member names are checked for correctness.
29+ type MemberNameValidationMode int
2930
3031const (
31- // defaultValidation verifies that member names are valid according to the spec in
32+ // DefaultValidation verifies that member names are valid according to the spec in
3233 // https://jsonapi.org/format/#document-member-names.
3334 //
3435 // Note that this validation mode allows for non-URL-safe member names.
35- defaultValidation memberNameValidationMode = iota
36+ DefaultValidation MemberNameValidationMode = iota
3637
37- // disableValidation turns off member name validation for convenience and performance-saving
38+ // DisableValidation turns off member name validation for convenience or performance-saving
3839 // reasons.
3940 //
40- // Note that this validation mode allows for member names to not conform to the JSON:API spec.
41- disableValidation
41+ // Note that this validation mode allows member names that do NOT conform to the JSON:API spec.
42+ DisableValidation
4243
43- // strictValidation verifies that member names are both valid according to the spec in
44+ // StrictValidation verifies that member names are valid according to the spec in
4445 // https://jsonapi.org/format/#document-member-names, and follow recommendations from
4546 // https://jsonapi.org/recommendations/#naming.
4647 //
4748 // Note that these names are always URL-safe.
48- strictValidation
49+ StrictValidation
4950)
5051
51- func isValidMemberName (name string , mode memberNameValidationMode ) bool {
52+ func isValidMemberName (name string , mode MemberNameValidationMode ) bool {
5253 switch mode {
53- case disableValidation :
54+ case DisableValidation :
5455 return true
55- case strictValidation :
56+ case StrictValidation :
5657 return strictNameRegex .MatchString (name )
5758 default :
5859 return defaultNameRegex .MatchString (name )
5960 }
6061}
6162
62- func validateMapMemberNames (m map [string ]any , mode memberNameValidationMode ) error {
63+ func validateMapMemberNames (m map [string ]any , mode MemberNameValidationMode ) error {
6364 for member , val := range m {
6465 if ! isValidMemberName (member , mode ) {
6566 return & MemberNameValidationError {member }
@@ -84,7 +85,7 @@ func validateMapMemberNames(m map[string]any, mode memberNameValidationMode) err
8485 return nil
8586}
8687
87- func validateJSONMemberNames (b []byte , mode memberNameValidationMode ) error {
88+ func validateJSONMemberNames (b []byte , mode MemberNameValidationMode ) error {
8889 var m map [string ]any
8990 if err := json .Unmarshal (b , & m ); err != nil {
9091 return fmt .Errorf ("unexpected unmarshal failure: %w" , err )
0 commit comments