Skip to content

Commit d51704d

Browse files
feat: Drop JDK 11 support in favor of JDK 17 (#508)
1 parent 508abf3 commit d51704d

17 files changed

Lines changed: 153 additions & 114 deletions

File tree

jsonschema-examples/src/test/java/com/github/victools/jsonschema/examples/ExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testExample(Class<? extends SchemaGenerationExampleInterface> exampl
5959
private static String loadResource(String resourcePath) throws IOException {
6060
StringBuilder stringBuilder = new StringBuilder();
6161
try (InputStream inputStream = Objects.requireNonNull(ExampleTest.class.getResourceAsStream(resourcePath));
62-
Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name())) {
62+
Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8)) {
6363
while (scanner.hasNext()) {
6464
stringBuilder.append(scanner.nextLine()).append('\n');
6565
}

jsonschema-generator-parent/pom.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<role>Provided PRs #116 and #118 (part of initial Swagger2Module)</role>
6262
<role>Provided implementation for #204 (readOnly/writeOnly in JacksonModule)</role>
6363
<role>Provided PR #299 and feedback on final implementation (inheritance of validation constraint annotations)</role>
64-
<role>Provided implementation for PR #503 (avoid duplicates in required array during final clean-ups)</role>
64+
<role>Provided PR #503 (avoid duplicates in required array during final clean-ups)</role>
6565
</roles>
6666
</contributor>
6767
<contributor>
@@ -137,6 +137,12 @@
137137
<role>Provided PR #487 (support @JacksonAnnotationsInside annotations)</role>
138138
</roles>
139139
</contributor>
140+
<contributor>
141+
<url>https://github.com/hbzhou</url>
142+
<roles>
143+
<role>Provided PR #477 (drop JDK 11 support in favor of JDK 17)</role>
144+
</roles>
145+
</contributor>
140146
<contributor>
141147
<name>Filip Hrisafov</name>
142148
<url>https://github.com/filiphr</url>
@@ -149,8 +155,7 @@
149155
<properties>
150156
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
151157
<file.encoding>UTF-8</file.encoding>
152-
<maven.compiler.source>17</maven.compiler.source>
153-
<maven.compiler.target>17</maven.compiler.target>
158+
<maven.compiler.release>17</maven.compiler.release>
154159
<!-- maven plugins -->
155160
<maven.plugin.version.checkstyle>3.6.0</maven.plugin.version.checkstyle>
156161
<version.checkstyle>12.3.0</version.checkstyle>
@@ -292,9 +297,8 @@
292297
<artifactId>maven-compiler-plugin</artifactId>
293298
<version>${maven.plugin.version.compiler}</version>
294299
<configuration>
295-
<source>${maven.compiler.source}</source>
296-
<target>${maven.compiler.target}</target>
297300
<showDeprecation>true</showDeprecation>
301+
<release>${maven.compiler.release}</release>
298302
</configuration>
299303
</plugin>
300304
<plugin>

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private String deriveFieldName() {
246246
.map(prefix -> methodName.substring(prefix.length()))
247247
.filter(name -> !name.isEmpty())
248248
.findFirst();
249-
if (!possibleFieldName.isPresent()) {
249+
if (possibleFieldName.isEmpty()) {
250250
return methodName + "()";
251251
}
252252
String methodNameWithoutPrefix = possibleFieldName.get();

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public TypeContext(AnnotationConfiguration annotationConfig) {
7373
*/
7474
public TypeContext(AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig) {
7575
this(annotationConfig, generatorConfig.shouldDeriveFieldsFromArgumentFreeMethods());
76-
if (annotationConfig instanceof AnnotationConfiguration.StdConfiguration) {
76+
if (annotationConfig instanceof AnnotationConfiguration.StdConfiguration stdConfiguration) {
7777
generatorConfig.getAnnotationInclusionOverrides()
78-
.forEach(((AnnotationConfiguration.StdConfiguration) annotationConfig)::setInclusion);
78+
.forEach(stdConfiguration::setInclusion);
7979
}
8080
}
8181

@@ -327,8 +327,8 @@ public <A extends Annotation> A getTypeParameterAnnotation(Class<A> annotationCl
327327
* @since 4.30.0
328328
*/
329329
public Stream<Annotation> getTypeParameterAnnotations(AnnotatedType annotatedContainerType, Integer containerItemIndex) {
330-
if (annotatedContainerType instanceof AnnotatedParameterizedType) {
331-
AnnotatedType[] typeArguments = ((AnnotatedParameterizedType) annotatedContainerType).getAnnotatedActualTypeArguments();
330+
if (annotatedContainerType instanceof AnnotatedParameterizedType parameterizedType) {
331+
AnnotatedType[] typeArguments = parameterizedType.getAnnotatedActualTypeArguments();
332332
int itemIndex = containerItemIndex == null ? 0 : containerItemIndex;
333333
if (typeArguments.length > itemIndex) {
334334
return Stream.of(typeArguments[itemIndex].getAnnotations());
@@ -478,10 +478,10 @@ public String getMethodPropertyArgumentTypeDescription(ResolvedType type) {
478478
public <R> R performActionOnMember(MemberScope<?, ?> member, Function<FieldScope, R> fieldAction,
479479
Function<MethodScope, R> methodAction) {
480480
R result;
481-
if (member instanceof FieldScope) {
482-
result = fieldAction.apply((FieldScope) member);
483-
} else if (member instanceof MethodScope) {
484-
result = methodAction.apply((MethodScope) member);
481+
if (member instanceof FieldScope field) {
482+
result = fieldAction.apply(field);
483+
} else if (member instanceof MethodScope method) {
484+
result = methodAction.apply(method);
485485
} else {
486486
throw new IllegalStateException("Unsupported member scope of type: " + member.getClass());
487487
}

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -376,47 +376,47 @@ public AttributeCollector setEnum(ObjectNode node, Collection<?> enumValues, Sch
376376

377377
private void addRawPropertyValue(ObjectNode node, String propertyName, Object value) {
378378
// need to specifically add simple/primitive values by type
379-
if (value instanceof String) {
379+
if (value instanceof String stringValue) {
380380
// explicit inclusion as string results in wrapping quote symbols
381-
node.put(propertyName, (String) value);
382-
} else if (value instanceof BigDecimal) {
383-
node.put(propertyName, (BigDecimal) value);
384-
} else if (value instanceof BigInteger) {
385-
node.put(propertyName, (BigInteger) value);
386-
} else if (value instanceof Boolean) {
387-
node.put(propertyName, (Boolean) value);
388-
} else if (value instanceof Double) {
389-
node.put(propertyName, (Double) value);
390-
} else if (value instanceof Float) {
391-
node.put(propertyName, (Float) value);
392-
} else if (value instanceof Integer) {
393-
node.put(propertyName, (Integer) value);
381+
node.put(propertyName, stringValue);
382+
} else if (value instanceof BigDecimal decimalValue) {
383+
node.put(propertyName, decimalValue);
384+
} else if (value instanceof BigInteger intValue) {
385+
node.put(propertyName, intValue);
386+
} else if (value instanceof Boolean boolValue) {
387+
node.put(propertyName, boolValue);
388+
} else if (value instanceof Double doubleValue) {
389+
node.put(propertyName, doubleValue);
390+
} else if (value instanceof Float floatValue) {
391+
node.put(propertyName, floatValue);
392+
} else if (value instanceof Integer intValue) {
393+
node.put(propertyName, intValue);
394394
} else {
395395
// everything else is simply forwarded as-is to the JSON Schema, it's up to the configurator to ensure the value's correctness
396396
node.putPOJO(propertyName, value);
397397
}
398398
}
399399

400-
private void addRawArrayItem(ArrayNode node, Object value) {
400+
private void addRawArrayItem(ArrayNode node, Object item) {
401401
// need to specifically add simple/primitive values by type
402-
if (value instanceof String) {
402+
if (item instanceof String stringItem) {
403403
// explicit inclusion as string results in wrapping quote symbols
404-
node.add((String) value);
405-
} else if (value instanceof BigDecimal) {
406-
node.add((BigDecimal) value);
407-
} else if (value instanceof BigInteger) {
408-
node.add((BigInteger) value);
409-
} else if (value instanceof Boolean) {
410-
node.add((Boolean) value);
411-
} else if (value instanceof Double) {
412-
node.add((Double) value);
413-
} else if (value instanceof Float) {
414-
node.add((Float) value);
415-
} else if (value instanceof Integer) {
416-
node.add((Integer) value);
404+
node.add(stringItem);
405+
} else if (item instanceof BigDecimal decimalItem) {
406+
node.add(decimalItem);
407+
} else if (item instanceof BigInteger intItem) {
408+
node.add(intItem);
409+
} else if (item instanceof Boolean boolItem) {
410+
node.add(boolItem);
411+
} else if (item instanceof Double doubleItem) {
412+
node.add(doubleItem);
413+
} else if (item instanceof Float floatItem) {
414+
node.add(floatItem);
415+
} else if (item instanceof Integer intItem) {
416+
node.add(intItem);
417417
} else {
418418
// everything else is simply forwarded as-is to the JSON Schema, it's up to the configurator to ensure the value's correctness
419-
node.addPOJO(value);
419+
node.addPOJO(item);
420420
}
421421
}
422422

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ private Set<String> getTagNamesSupporting(SchemaKeyword.TagContent contentType)
188188
private void finaliseSchemaParts(List<ObjectNode> schemaNodes, Consumer<ObjectNode> performCleanUpOnSingleSchemaNode) {
189189
List<ObjectNode> nextNodesToCheck = new ArrayList<>(schemaNodes);
190190
Consumer<JsonNode> addNodeToCheck = node -> {
191-
if (node instanceof ObjectNode) {
192-
nextNodesToCheck.add((ObjectNode) node);
191+
if (node instanceof ObjectNode objectNode) {
192+
nextNodesToCheck.add(objectNode);
193193
}
194194
};
195195

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ private void generateArrayDefinition(GenericTypeDetails typeDetails, ObjectNode
435435
}
436436

437437
private JsonNode populateItemMemberSchema(TypeScope targetScope) {
438-
if (targetScope instanceof FieldScope && !((FieldScope) targetScope).isFakeContainerItemScope()) {
439-
return this.populateFieldSchema(((FieldScope) targetScope).asFakeContainerItemScope());
438+
if (targetScope instanceof FieldScope field && !field.isFakeContainerItemScope()) {
439+
return this.populateFieldSchema(field.asFakeContainerItemScope());
440440
}
441-
if (targetScope instanceof MethodScope && !((MethodScope) targetScope).isFakeContainerItemScope()) {
442-
return this.populateMethodSchema(((MethodScope) targetScope).asFakeContainerItemScope());
441+
if (targetScope instanceof MethodScope method && !method.isFakeContainerItemScope()) {
442+
return this.populateMethodSchema(method.asFakeContainerItemScope());
443443
}
444444
ObjectNode arrayItemDefinition = this.generatorConfig.createObjectNode();
445445
this.traverseGenericType(targetScope.getContainerItemType(), arrayItemDefinition);
@@ -710,9 +710,8 @@ private static boolean canExtendTypeDeclarationToIncludeNull(ObjectNode node, Sc
710710
private static void extendTypeDeclarationToIncludeNull(ObjectNode node, SchemaGeneratorConfig config) {
711711
JsonNode fixedJsonSchemaType = node.get(config.getKeyword(SchemaKeyword.TAG_TYPE));
712712
final String nullTypeName = config.getKeyword(SchemaKeyword.TAG_TYPE_NULL);
713-
if (fixedJsonSchemaType instanceof ArrayNode) {
713+
if (fixedJsonSchemaType instanceof ArrayNode arrayOfTypes) {
714714
// there are already multiple "type" values
715-
ArrayNode arrayOfTypes = (ArrayNode) fixedJsonSchemaType;
716715
// one of the existing "type" values could be null
717716
for (JsonNode arrayEntry : arrayOfTypes) {
718717
if (nullTypeName.equals(arrayEntry.stringValue())) {

jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ public SchemaDefinitionNamingStrategy getDefinitionNamingStrategy() {
238238
public <M extends MemberScope<?, ?>> CustomPropertyDefinition getCustomDefinition(M scope, SchemaGenerationContext context,
239239
CustomPropertyDefinitionProvider<M> ignoredDefinitionProvider) {
240240
CustomPropertyDefinition result;
241-
if (scope instanceof FieldScope) {
242-
result = this.getCustomDefinition(this.fieldConfigPart, (FieldScope) scope, context,
241+
if (scope instanceof FieldScope fieldScope) {
242+
result = this.getCustomDefinition(this.fieldConfigPart, fieldScope, context,
243243
(CustomPropertyDefinitionProvider<FieldScope>) ignoredDefinitionProvider);
244-
} else if (scope instanceof MethodScope) {
245-
result = this.getCustomDefinition(this.methodConfigPart, (MethodScope) scope, context,
244+
} else if (scope instanceof MethodScope methodScope) {
245+
result = this.getCustomDefinition(this.methodConfigPart, methodScope, context,
246246
(CustomPropertyDefinitionProvider<MethodScope>) ignoredDefinitionProvider);
247247
} else {
248248
throw new IllegalArgumentException("Unexpected member scope: " + (scope == null ? null : scope.getClass().getName()));

jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorAllOfCleanUpTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,25 @@ public class SchemaGeneratorAllOfCleanUpTest {
3636
static Stream<Arguments> parametersForTestAllOfCleanUp() {
3737
String differentValueInMainSchema = "{ \"type\":\"object\", \"title\":\"main schema\", \"allOf\":[{ \"title\":\"different title\" }, {}] }";
3838
String differentValueInAllOfPart = "{ \"type\":\"object\", \"allOf\":[{ \"title\":\"title X\" }, { \"title\":\"title Y\" }] }";
39-
String equalIfTagInMainSchema = "{ \"type\":\"object\", \"if\":{ \"const\": 1 }, \"then\":{}, "
40-
+ "\"allOf\":[{ \"if\":{ \"const\": 1 }, \"then\":{}, \"else\": { \"title\": \"otherwise...\" } }, {}] }";
41-
String equalIfTagInAllOfPart = "{ \"type\":\"object\", \"allOf\":[{ \"if\":{ \"const\": 1 }, \"then\":{} }, "
42-
+ "{ \"if\":{ \"const\": 1 }, \"then\":{}, \"else\": { \"title\": \"otherwise...\" } }] }";
39+
String equalIfTagInMainSchema = """
40+
{ "type":"object", "if":{ "const": 1 }, "then":{}, \
41+
"allOf":[{ "if":{ "const": 1 }, "then":{}, "else": { "title": "otherwise..." } }, {}] }\
42+
""";
43+
String equalIfTagInAllOfPart = """
44+
{ "type":"object", "allOf":[{ "if":{ "const": 1 }, "then":{} }, \
45+
{ "if":{ "const": 1 }, "then":{}, "else": { "title": "otherwise..." } }] }\
46+
""";
4347
List<Arguments> testCases = EnumSet.allOf(SchemaVersion.class).stream()
4448
.flatMap(schemaVersion -> Stream.of(
4549
Arguments.of(schemaVersion, differentValueInMainSchema, differentValueInMainSchema),
4650
Arguments.of(schemaVersion, differentValueInAllOfPart, differentValueInAllOfPart),
4751
Arguments.of(schemaVersion, equalIfTagInMainSchema, equalIfTagInMainSchema),
4852
Arguments.of(schemaVersion, equalIfTagInAllOfPart, equalIfTagInAllOfPart),
4953
Arguments.of(schemaVersion,
50-
"{ \"type\": \"object\", \"title\":\"same in all three\", "
51-
+ "\"allOf\": [{ \"title\":\"same in all three\" }, { \"title\":\"same in all three\" }] }",
54+
"""
55+
{ "type": "object", "title":"same in all three", \
56+
"allOf": [{ "title":"same in all three" }, { "title":"same in all three" }] }\
57+
""",
5258
"{ \"type\": \"object\", \"title\":\"same in all three\" }"),
5359
Arguments.of(schemaVersion,
5460
"{ \"type\": \"object\", \"allOf\": [{ \"title\":\"from allOf[0]\" }, { \"description\":\"from allOf[1]\" }] }",

jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImplTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,13 @@ public void testCreateStandardDefinitionReferenceForField_withCustomPropertyDefi
287287
public void testCreateStandardDefinition() {
288288
ResolvedType type = this.contextImpl.getTypeContext().resolve(TestClass.class);
289289
ObjectNode result = this.contextImpl.createStandardDefinition(type, null);
290-
Assertions.assertEquals("{\"type\":\"object\",\"properties\":{"
291-
+ "\"booleanField\":{\"allOf\":[{},{\"title\":\"Field Title\"}]},"
292-
+ "\"isBooleanField()\":{\"allOf\":[{},{\"title\":\"Method Title\"}]}},"
293-
+ "\"dependentRequired\":{\"booleanField\":[\"isBooleanField()\"],\"isBooleanField()\":[\"booleanField\"]}," +
294-
"\"description\":\"Type Description\"}",
290+
Assertions.assertEquals("""
291+
{"type":"object","properties":{\
292+
"booleanField":{"allOf":[{},{"title":"Field Title"}]},\
293+
"isBooleanField()":{"allOf":[{},{"title":"Method Title"}]}},\
294+
"dependentRequired":{"booleanField":["isBooleanField()"],"isBooleanField()":["booleanField"]},\
295+
"description":"Type Description"}\
296+
""",
295297
result.toString());
296298
}
297299

0 commit comments

Comments
 (0)