@@ -87,9 +87,10 @@ public List<String> getAnnotations(MappingContext mappingContext, String graphQL
87
87
}
88
88
}
89
89
90
- // 2. Add custom annotations from the configuration
91
- List <String > typeAnnotations = getTypeAnnotations (mappingContext , graphQLTypeName , name , parentTypeName );
92
- annotations .addAll (typeAnnotations );
90
+ // 2.1. Add custom annotations from the configuration for: GraphQLObjectName.fieldName
91
+ annotations .addAll (getTypeAnnotationsForKey (mappingContext , parentTypeName + "." + name ));
92
+ // 2.2. Add custom annotations from the configuration for: GraphQLTypeName
93
+ annotations .addAll (getTypeAnnotationsForKey (mappingContext , graphQLTypeName ));
93
94
94
95
// 3. Add Jackson-related annotations
95
96
annotations .addAll (getJacksonTypeIdAnnotations (mappingContext , def ));
@@ -110,40 +111,22 @@ public List<String> getAnnotations(MappingContext mappingContext, String graphQL
110
111
return annotations ;
111
112
}
112
113
113
- private List <String > getTypeAnnotations (MappingContext mappingContext ,
114
- String graphQLType ,
115
- String fieldName ,
116
- String parentTypeName ) {
114
+ private static List <String > getTypeAnnotationsForKey (MappingContext mappingContext ,
115
+ String key ) {
116
+ List <String > result = new ArrayList <>();
117
117
Map <String , List <String >> customAnnotationsMapping = mappingContext .getCustomAnnotationsMapping ();
118
-
119
- List <String > typeAnnotations = new ArrayList <>();
120
-
121
- if (parentTypeName != null ) {
122
- String typeNameKey = parentTypeName + "." + fieldName ;
123
- List <String > fullTypeAnnotations = customAnnotationsMapping .get (typeNameKey );
124
- if (!Utils .isEmpty (fullTypeAnnotations )) {
125
- typeAnnotations .addAll (fullTypeAnnotations );
126
- } else {
127
- // try finding if there's a RegEx present for this type
128
- for (Map .Entry <String , List <String >> entry : customAnnotationsMapping .entrySet ()) {
129
- if (typeNameKey .matches (entry .getKey ()) && !Utils .isEmpty (entry .getValue ())) {
130
- typeAnnotations .addAll (entry .getValue ());
131
- }
132
- }
133
- }
134
- }
135
- List <String > specificTypeAnnotations = customAnnotationsMapping .get (graphQLType );
136
- if (!Utils .isEmpty (specificTypeAnnotations )) {
137
- typeAnnotations .addAll (specificTypeAnnotations );
118
+ List <String > typeAnnotations = customAnnotationsMapping .get (key );
119
+ if (!Utils .isEmpty (typeAnnotations )) {
120
+ result .addAll (typeAnnotations );
138
121
} else {
139
122
// try finding if there's a RegEx present for this type
140
123
for (Map .Entry <String , List <String >> entry : customAnnotationsMapping .entrySet ()) {
141
- if (graphQLType .matches (entry .getKey ()) && !Utils .isEmpty (entry .getValue ())) {
142
- typeAnnotations .addAll (entry .getValue ());
124
+ if (key .matches (entry .getKey ()) && !Utils .isEmpty (entry .getValue ())) {
125
+ result .addAll (entry .getValue ());
143
126
}
144
127
}
145
128
}
146
- return typeAnnotations ;
129
+ return result ;
147
130
}
148
131
149
132
private String getModelValidationAnnotation (MappingContext mappingContext , String graphQLTypeName ) {
0 commit comments