@@ -96,13 +96,9 @@ private static ValidationRule.Result checkNullType(SchemaWrapper schemaWrapper)
9696 // OAS spec is 3.0.x
9797 if (ModelUtils .isNullType (schema )) {
9898 result = new ValidationRule .Fail ();
99- String name = schema .getName ();
100- if (name == null ) {
101- name = schema .getTitle ();
102- }
10399 result .setDetails (String .format (Locale .ROOT ,
104100 "Schema '%s' uses a 'null' type, which is specified in OAS 3.1 and above, but OAS document is version %s" ,
105- name , schemaWrapper .getOpenAPI ().getOpenapi ()));
101+ nameOf ( schema ) , schemaWrapper .getOpenAPI ().getOpenapi ()));
106102 return result ;
107103 }
108104 }
@@ -126,20 +122,22 @@ private static ValidationRule.Result checkNullableAttribute(SchemaWrapper schema
126122 if (version .atLeast ("3.1" )) {
127123 if (ModelUtils .isNullable (schema )) {
128124 result = new ValidationRule .Fail ();
129- String name = schema .getName ();
130- if (name == null ) {
131- name = schema .getTitle ();
132- }
133125 result .setDetails (String .format (Locale .ROOT ,
134126 "OAS document is version '%s'. Schema '%s' uses 'nullable' attribute, which has been deprecated in OAS 3.1." ,
135- schemaWrapper .getOpenAPI ().getOpenapi (), name ));
127+ schemaWrapper .getOpenAPI ().getOpenapi (), nameOf ( schema ) ));
136128 return result ;
137129 }
138130 }
139131 }
140132 return result ;
141133 }
142134
135+ private static String nameOf (Schema schema ) {
136+ if (schema .getName () != null ) return schema .getName ();
137+ if (schema .getTitle () != null ) return schema .getTitle ();
138+ return "(unnamed)" ;
139+ }
140+
143141 // The set of valid OAS values for the 'type' attribute.
144142 private static Set <String > validTypes = new HashSet <String >(
145143 Arrays .asList ("null" , "boolean" , "object" , "array" , "number" , "string" , "integer" ));
@@ -157,13 +155,9 @@ private static ValidationRule.Result checkInvalidType(SchemaWrapper schemaWrappe
157155 ValidationRule .Result result = ValidationRule .Pass .empty ();
158156 if (schema .getType () != null && !validTypes .contains (schema .getType ())) {
159157 result = new ValidationRule .Fail ();
160- String name = schema .getName ();
161- if (name == null ) {
162- name = schema .getTitle ();
163- }
164158 result .setDetails (String .format (Locale .ROOT ,
165159 "Schema '%s' uses the '%s' type, which is not a valid type." ,
166- name , schema .getType ()));
160+ nameOf ( schema ) , schema .getType ()));
167161 return result ;
168162 }
169163 return result ;
0 commit comments