diff --git a/jsonschema-examples/src/test/java/com/github/victools/jsonschema/examples/ExampleTest.java b/jsonschema-examples/src/test/java/com/github/victools/jsonschema/examples/ExampleTest.java
index de442338..aebbd84c 100644
--- a/jsonschema-examples/src/test/java/com/github/victools/jsonschema/examples/ExampleTest.java
+++ b/jsonschema-examples/src/test/java/com/github/victools/jsonschema/examples/ExampleTest.java
@@ -59,7 +59,7 @@ public void testExample(Class extends SchemaGenerationExampleInterface> exampl
private static String loadResource(String resourcePath) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
try (InputStream inputStream = Objects.requireNonNull(ExampleTest.class.getResourceAsStream(resourcePath));
- Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name())) {
+ Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8)) {
while (scanner.hasNext()) {
stringBuilder.append(scanner.nextLine()).append('\n');
}
diff --git a/jsonschema-generator-parent/pom.xml b/jsonschema-generator-parent/pom.xml
index 1ac10de3..f17e1311 100644
--- a/jsonschema-generator-parent/pom.xml
+++ b/jsonschema-generator-parent/pom.xml
@@ -61,7 +61,7 @@
Provided PRs #116 and #118 (part of initial Swagger2Module)
Provided implementation for #204 (readOnly/writeOnly in JacksonModule)
Provided PR #299 and feedback on final implementation (inheritance of validation constraint annotations)
- Provided implementation for PR #503 (avoid duplicates in required array during final clean-ups)
+ Provided PR #503 (avoid duplicates in required array during final clean-ups)
@@ -137,6 +137,12 @@
Provided PR #487 (support @JacksonAnnotationsInside annotations)
+
+ https://github.com/hbzhou
+
+ Provided PR #477 (drop JDK 11 support in favor of JDK 17)
+
+
Filip Hrisafov
https://github.com/filiphr
@@ -149,8 +155,7 @@
UTF-8
UTF-8
- 17
- 17
+ 17
3.6.0
12.3.0
@@ -292,9 +297,8 @@
maven-compiler-plugin
${maven.plugin.version.compiler}
- ${maven.compiler.source}
- ${maven.compiler.target}
true
+ ${maven.compiler.release}
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java
index 2631daee..fbd1316d 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java
@@ -246,7 +246,7 @@ private String deriveFieldName() {
.map(prefix -> methodName.substring(prefix.length()))
.filter(name -> !name.isEmpty())
.findFirst();
- if (!possibleFieldName.isPresent()) {
+ if (possibleFieldName.isEmpty()) {
return methodName + "()";
}
String methodNameWithoutPrefix = possibleFieldName.get();
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java
index e0661432..ef2a1877 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java
@@ -73,9 +73,9 @@ public TypeContext(AnnotationConfiguration annotationConfig) {
*/
public TypeContext(AnnotationConfiguration annotationConfig, SchemaGeneratorConfig generatorConfig) {
this(annotationConfig, generatorConfig.shouldDeriveFieldsFromArgumentFreeMethods());
- if (annotationConfig instanceof AnnotationConfiguration.StdConfiguration) {
+ if (annotationConfig instanceof AnnotationConfiguration.StdConfiguration stdConfiguration) {
generatorConfig.getAnnotationInclusionOverrides()
- .forEach(((AnnotationConfiguration.StdConfiguration) annotationConfig)::setInclusion);
+ .forEach(stdConfiguration::setInclusion);
}
}
@@ -327,8 +327,8 @@ public A getTypeParameterAnnotation(Class annotationCl
* @since 4.30.0
*/
public Stream getTypeParameterAnnotations(AnnotatedType annotatedContainerType, Integer containerItemIndex) {
- if (annotatedContainerType instanceof AnnotatedParameterizedType) {
- AnnotatedType[] typeArguments = ((AnnotatedParameterizedType) annotatedContainerType).getAnnotatedActualTypeArguments();
+ if (annotatedContainerType instanceof AnnotatedParameterizedType parameterizedType) {
+ AnnotatedType[] typeArguments = parameterizedType.getAnnotatedActualTypeArguments();
int itemIndex = containerItemIndex == null ? 0 : containerItemIndex;
if (typeArguments.length > itemIndex) {
return Stream.of(typeArguments[itemIndex].getAnnotations());
@@ -478,10 +478,10 @@ public String getMethodPropertyArgumentTypeDescription(ResolvedType type) {
public R performActionOnMember(MemberScope, ?> member, Function fieldAction,
Function methodAction) {
R result;
- if (member instanceof FieldScope) {
- result = fieldAction.apply((FieldScope) member);
- } else if (member instanceof MethodScope) {
- result = methodAction.apply((MethodScope) member);
+ if (member instanceof FieldScope field) {
+ result = fieldAction.apply(field);
+ } else if (member instanceof MethodScope method) {
+ result = methodAction.apply(method);
} else {
throw new IllegalStateException("Unsupported member scope of type: " + member.getClass());
}
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
index c0853e6c..7246a49e 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
@@ -376,47 +376,47 @@ public AttributeCollector setEnum(ObjectNode node, Collection> enumValues, Sch
private void addRawPropertyValue(ObjectNode node, String propertyName, Object value) {
// need to specifically add simple/primitive values by type
- if (value instanceof String) {
+ if (value instanceof String stringValue) {
// explicit inclusion as string results in wrapping quote symbols
- node.put(propertyName, (String) value);
- } else if (value instanceof BigDecimal) {
- node.put(propertyName, (BigDecimal) value);
- } else if (value instanceof BigInteger) {
- node.put(propertyName, (BigInteger) value);
- } else if (value instanceof Boolean) {
- node.put(propertyName, (Boolean) value);
- } else if (value instanceof Double) {
- node.put(propertyName, (Double) value);
- } else if (value instanceof Float) {
- node.put(propertyName, (Float) value);
- } else if (value instanceof Integer) {
- node.put(propertyName, (Integer) value);
+ node.put(propertyName, stringValue);
+ } else if (value instanceof BigDecimal decimalValue) {
+ node.put(propertyName, decimalValue);
+ } else if (value instanceof BigInteger intValue) {
+ node.put(propertyName, intValue);
+ } else if (value instanceof Boolean boolValue) {
+ node.put(propertyName, boolValue);
+ } else if (value instanceof Double doubleValue) {
+ node.put(propertyName, doubleValue);
+ } else if (value instanceof Float floatValue) {
+ node.put(propertyName, floatValue);
+ } else if (value instanceof Integer intValue) {
+ node.put(propertyName, intValue);
} else {
// everything else is simply forwarded as-is to the JSON Schema, it's up to the configurator to ensure the value's correctness
node.putPOJO(propertyName, value);
}
}
- private void addRawArrayItem(ArrayNode node, Object value) {
+ private void addRawArrayItem(ArrayNode node, Object item) {
// need to specifically add simple/primitive values by type
- if (value instanceof String) {
+ if (item instanceof String stringItem) {
// explicit inclusion as string results in wrapping quote symbols
- node.add((String) value);
- } else if (value instanceof BigDecimal) {
- node.add((BigDecimal) value);
- } else if (value instanceof BigInteger) {
- node.add((BigInteger) value);
- } else if (value instanceof Boolean) {
- node.add((Boolean) value);
- } else if (value instanceof Double) {
- node.add((Double) value);
- } else if (value instanceof Float) {
- node.add((Float) value);
- } else if (value instanceof Integer) {
- node.add((Integer) value);
+ node.add(stringItem);
+ } else if (item instanceof BigDecimal decimalItem) {
+ node.add(decimalItem);
+ } else if (item instanceof BigInteger intItem) {
+ node.add(intItem);
+ } else if (item instanceof Boolean boolItem) {
+ node.add(boolItem);
+ } else if (item instanceof Double doubleItem) {
+ node.add(doubleItem);
+ } else if (item instanceof Float floatItem) {
+ node.add(floatItem);
+ } else if (item instanceof Integer intItem) {
+ node.add(intItem);
} else {
// everything else is simply forwarded as-is to the JSON Schema, it's up to the configurator to ensure the value's correctness
- node.addPOJO(value);
+ node.addPOJO(item);
}
}
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtils.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtils.java
index d06a4864..35abff90 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtils.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtils.java
@@ -188,8 +188,8 @@ private Set getTagNamesSupporting(SchemaKeyword.TagContent contentType)
private void finaliseSchemaParts(List schemaNodes, Consumer performCleanUpOnSingleSchemaNode) {
List nextNodesToCheck = new ArrayList<>(schemaNodes);
Consumer addNodeToCheck = node -> {
- if (node instanceof ObjectNode) {
- nextNodesToCheck.add((ObjectNode) node);
+ if (node instanceof ObjectNode objectNode) {
+ nextNodesToCheck.add(objectNode);
}
};
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
index d521f732..f5c98789 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
@@ -435,11 +435,11 @@ private void generateArrayDefinition(GenericTypeDetails typeDetails, ObjectNode
}
private JsonNode populateItemMemberSchema(TypeScope targetScope) {
- if (targetScope instanceof FieldScope && !((FieldScope) targetScope).isFakeContainerItemScope()) {
- return this.populateFieldSchema(((FieldScope) targetScope).asFakeContainerItemScope());
+ if (targetScope instanceof FieldScope field && !field.isFakeContainerItemScope()) {
+ return this.populateFieldSchema(field.asFakeContainerItemScope());
}
- if (targetScope instanceof MethodScope && !((MethodScope) targetScope).isFakeContainerItemScope()) {
- return this.populateMethodSchema(((MethodScope) targetScope).asFakeContainerItemScope());
+ if (targetScope instanceof MethodScope method && !method.isFakeContainerItemScope()) {
+ return this.populateMethodSchema(method.asFakeContainerItemScope());
}
ObjectNode arrayItemDefinition = this.generatorConfig.createObjectNode();
this.traverseGenericType(targetScope.getContainerItemType(), arrayItemDefinition);
@@ -710,9 +710,8 @@ private static boolean canExtendTypeDeclarationToIncludeNull(ObjectNode node, Sc
private static void extendTypeDeclarationToIncludeNull(ObjectNode node, SchemaGeneratorConfig config) {
JsonNode fixedJsonSchemaType = node.get(config.getKeyword(SchemaKeyword.TAG_TYPE));
final String nullTypeName = config.getKeyword(SchemaKeyword.TAG_TYPE_NULL);
- if (fixedJsonSchemaType instanceof ArrayNode) {
+ if (fixedJsonSchemaType instanceof ArrayNode arrayOfTypes) {
// there are already multiple "type" values
- ArrayNode arrayOfTypes = (ArrayNode) fixedJsonSchemaType;
// one of the existing "type" values could be null
for (JsonNode arrayEntry : arrayOfTypes) {
if (nullTypeName.equals(arrayEntry.stringValue())) {
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
index 99ded587..0c4935a4 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
@@ -238,11 +238,11 @@ public SchemaDefinitionNamingStrategy getDefinitionNamingStrategy() {
public > CustomPropertyDefinition getCustomDefinition(M scope, SchemaGenerationContext context,
CustomPropertyDefinitionProvider ignoredDefinitionProvider) {
CustomPropertyDefinition result;
- if (scope instanceof FieldScope) {
- result = this.getCustomDefinition(this.fieldConfigPart, (FieldScope) scope, context,
+ if (scope instanceof FieldScope fieldScope) {
+ result = this.getCustomDefinition(this.fieldConfigPart, fieldScope, context,
(CustomPropertyDefinitionProvider) ignoredDefinitionProvider);
- } else if (scope instanceof MethodScope) {
- result = this.getCustomDefinition(this.methodConfigPart, (MethodScope) scope, context,
+ } else if (scope instanceof MethodScope methodScope) {
+ result = this.getCustomDefinition(this.methodConfigPart, methodScope, context,
(CustomPropertyDefinitionProvider) ignoredDefinitionProvider);
} else {
throw new IllegalArgumentException("Unexpected member scope: " + (scope == null ? null : scope.getClass().getName()));
diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorAllOfCleanUpTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorAllOfCleanUpTest.java
index 5804d3f8..03059dd9 100644
--- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorAllOfCleanUpTest.java
+++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorAllOfCleanUpTest.java
@@ -36,10 +36,14 @@ public class SchemaGeneratorAllOfCleanUpTest {
static Stream parametersForTestAllOfCleanUp() {
String differentValueInMainSchema = "{ \"type\":\"object\", \"title\":\"main schema\", \"allOf\":[{ \"title\":\"different title\" }, {}] }";
String differentValueInAllOfPart = "{ \"type\":\"object\", \"allOf\":[{ \"title\":\"title X\" }, { \"title\":\"title Y\" }] }";
- String equalIfTagInMainSchema = "{ \"type\":\"object\", \"if\":{ \"const\": 1 }, \"then\":{}, "
- + "\"allOf\":[{ \"if\":{ \"const\": 1 }, \"then\":{}, \"else\": { \"title\": \"otherwise...\" } }, {}] }";
- String equalIfTagInAllOfPart = "{ \"type\":\"object\", \"allOf\":[{ \"if\":{ \"const\": 1 }, \"then\":{} }, "
- + "{ \"if\":{ \"const\": 1 }, \"then\":{}, \"else\": { \"title\": \"otherwise...\" } }] }";
+ String equalIfTagInMainSchema = """
+ { "type":"object", "if":{ "const": 1 }, "then":{}, \
+ "allOf":[{ "if":{ "const": 1 }, "then":{}, "else": { "title": "otherwise..." } }, {}] }\
+ """;
+ String equalIfTagInAllOfPart = """
+ { "type":"object", "allOf":[{ "if":{ "const": 1 }, "then":{} }, \
+ { "if":{ "const": 1 }, "then":{}, "else": { "title": "otherwise..." } }] }\
+ """;
List testCases = EnumSet.allOf(SchemaVersion.class).stream()
.flatMap(schemaVersion -> Stream.of(
Arguments.of(schemaVersion, differentValueInMainSchema, differentValueInMainSchema),
@@ -47,8 +51,10 @@ static Stream parametersForTestAllOfCleanUp() {
Arguments.of(schemaVersion, equalIfTagInMainSchema, equalIfTagInMainSchema),
Arguments.of(schemaVersion, equalIfTagInAllOfPart, equalIfTagInAllOfPart),
Arguments.of(schemaVersion,
- "{ \"type\": \"object\", \"title\":\"same in all three\", "
- + "\"allOf\": [{ \"title\":\"same in all three\" }, { \"title\":\"same in all three\" }] }",
+ """
+ { "type": "object", "title":"same in all three", \
+ "allOf": [{ "title":"same in all three" }, { "title":"same in all three" }] }\
+ """,
"{ \"type\": \"object\", \"title\":\"same in all three\" }"),
Arguments.of(schemaVersion,
"{ \"type\": \"object\", \"allOf\": [{ \"title\":\"from allOf[0]\" }, { \"description\":\"from allOf[1]\" }] }",
diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImplTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImplTest.java
index 0fb8e7e9..3542e6b0 100644
--- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImplTest.java
+++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImplTest.java
@@ -287,11 +287,13 @@ public void testCreateStandardDefinitionReferenceForField_withCustomPropertyDefi
public void testCreateStandardDefinition() {
ResolvedType type = this.contextImpl.getTypeContext().resolve(TestClass.class);
ObjectNode result = this.contextImpl.createStandardDefinition(type, null);
- Assertions.assertEquals("{\"type\":\"object\",\"properties\":{"
- + "\"booleanField\":{\"allOf\":[{},{\"title\":\"Field Title\"}]},"
- + "\"isBooleanField()\":{\"allOf\":[{},{\"title\":\"Method Title\"}]}},"
- + "\"dependentRequired\":{\"booleanField\":[\"isBooleanField()\"],\"isBooleanField()\":[\"booleanField\"]}," +
- "\"description\":\"Type Description\"}",
+ Assertions.assertEquals("""
+ {"type":"object","properties":{\
+ "booleanField":{"allOf":[{},{"title":"Field Title"}]},\
+ "isBooleanField()":{"allOf":[{},{"title":"Method Title"}]}},\
+ "dependentRequired":{"booleanField":["isBooleanField()"],"isBooleanField()":["booleanField"]},\
+ "description":"Type Description"}\
+ """,
result.toString());
}
diff --git a/jsonschema-maven-plugin/src/main/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojo.java b/jsonschema-maven-plugin/src/main/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojo.java
index 076dd8dd..e5318b64 100644
--- a/jsonschema-maven-plugin/src/main/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojo.java
+++ b/jsonschema-maven-plugin/src/main/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojo.java
@@ -523,8 +523,10 @@ private void addStandardModule(GeneratorModule module, SchemaGeneratorConfigBuil
configBuilder.with(new Swagger2Module());
break;
default:
- throw new MojoExecutionException("Error: Module does not have a name in "
- + "['Jackson', 'JakartaValidation', 'JavaxValidation', 'Swagger15', 'Swagger2'] or does not have a custom classname.");
+ throw new MojoExecutionException("""
+ Error: Module does not have a name in \
+ ['Jackson', 'JakartaValidation', 'JavaxValidation', 'Swagger15', 'Swagger2'] or does not have a custom classname.\
+ """);
}
}
diff --git a/jsonschema-maven-plugin/src/test/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojoTest.java b/jsonschema-maven-plugin/src/test/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojoTest.java
index 010ea79c..3664b5ad 100644
--- a/jsonschema-maven-plugin/src/test/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojoTest.java
+++ b/jsonschema-maven-plugin/src/test/java/com/github/victools/jsonschema/plugin/maven/SchemaGeneratorMojoTest.java
@@ -203,8 +203,10 @@ public void testPackageName(String scenario) throws Exception {
@Test
public void testFileNamePattern() throws Exception {
File testCaseLocation = new File("src/test/resources/reference-test-cases");
- File generationLocation = new File("target/generated-test-sources/SchemaFileName/schemas/"+
- "com/github/victools/jsonschema/plugin/maven/testpackage");
+ File generationLocation = new File("""
+ target/generated-test-sources/SchemaFileName/schemas/\
+ com/github/victools/jsonschema/plugin/maven/testpackage\
+ """);
// Execute the pom
executePom(new File("src/test/resources/reference-test-cases/SchemaFileName-pom.xml"));
diff --git a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonPropertySorter.java b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonPropertySorter.java
index 42d38b03..8a129b32 100644
--- a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonPropertySorter.java
+++ b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonPropertySorter.java
@@ -75,8 +75,8 @@ protected int getPropertyIndex(MemberScope, ?> property) {
List sortedProperties = this.propertyOrderPerDeclaringType
.computeIfAbsent(topMostHierarchyType.getErasedType(), this::getAnnotatedPropertyOrder);
String fieldName;
- if (property instanceof MethodScope) {
- fieldName = Optional.ofNullable(((MethodScope) property).findGetterField())
+ if (property instanceof MethodScope method) {
+ fieldName = Optional.>ofNullable(method.findGetterField())
// since 4.33.1: fall-back on method's property name if no getter can be found
.orElse(property)
.getSchemaPropertyName();
diff --git a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolver.java b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolver.java
index 8cbd3f87..7caf6e4c 100644
--- a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolver.java
+++ b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolver.java
@@ -395,10 +395,10 @@ private ObjectNode createNestedSubtypeSchema(ResolvedType javaType, SchemaGenera
private ObjectNode getAttributesToInclude(TypeScope scope, SchemaGenerationContext context) {
ObjectNode attributesToInclude;
- if (scope instanceof FieldScope) {
- attributesToInclude = AttributeCollector.collectFieldAttributes((FieldScope) scope, context);
- } else if (scope instanceof MethodScope) {
- attributesToInclude = AttributeCollector.collectMethodAttributes((MethodScope) scope, context);
+ if (scope instanceof FieldScope fieldScope) {
+ attributesToInclude = AttributeCollector.collectFieldAttributes(fieldScope, context);
+ } else if (scope instanceof MethodScope methodScope) {
+ attributesToInclude = AttributeCollector.collectMethodAttributes(methodScope, context);
} else {
attributesToInclude = null;
}
diff --git a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonUnwrappedDefinitionProvider.java b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonUnwrappedDefinitionProvider.java
index 4556f58b..1b8d2dfb 100644
--- a/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonUnwrappedDefinitionProvider.java
+++ b/jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonUnwrappedDefinitionProvider.java
@@ -109,11 +109,11 @@ private Optional createUnwrappedMemberSchema(ResolvedMember> membe
*/
private void applyPrefixAndSuffixToPropertyNames(JsonNode definition, String prefix, String suffix, SchemaGenerationContext context) {
JsonNode properties = definition.get(context.getKeyword(SchemaKeyword.TAG_PROPERTIES));
- if (properties instanceof ObjectNode && !properties.isEmpty()) {
- List fieldNames = new ArrayList<>(properties.propertyNames());
+ if (properties instanceof ObjectNode propertiesNode && !propertiesNode.isEmpty()) {
+ List fieldNames = new ArrayList<>(propertiesNode.propertyNames());
for (String fieldName : fieldNames) {
- JsonNode propertySchema = ((ObjectNode) properties).remove(fieldName);
- ((ObjectNode) properties).set(prefix + fieldName + suffix, propertySchema);
+ JsonNode propertySchema = propertiesNode.remove(fieldName);
+ propertiesNode.set(prefix + fieldName + suffix, propertySchema);
}
}
JsonNode allOf = definition.get(context.getKeyword(SchemaKeyword.TAG_ALLOF));
diff --git a/jsonschema-module-jackson/src/test/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolverCustomDefinitionsTest.java b/jsonschema-module-jackson/src/test/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolverCustomDefinitionsTest.java
index 215c28c6..079498c8 100644
--- a/jsonschema-module-jackson/src/test/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolverCustomDefinitionsTest.java
+++ b/jsonschema-module-jackson/src/test/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolverCustomDefinitionsTest.java
@@ -77,8 +77,10 @@ static Stream parametersForTestProvideCustomSchemaDefinition() {
return Stream.of(
Arguments.of(TestClassWithSuperTypeReferences.class, null),
Arguments.of(TestSuperClassWithNameProperty.class, null),
- Arguments.of(TestSubClass1.class, "{\"allOf\":[{},"
- + "{\"type\":\"object\",\"properties\":{\"@type\":{\"const\":\"SUB_CLASS_1\"}},\"required\":[\"@type\"]}]}")
+ Arguments.of(TestSubClass1.class, """
+ {"allOf":[{},\
+ {"type":"object","properties":{"@type":{"const":"SUB_CLASS_1"}},"required":["@type"]}]}\
+ """)
);
}
@@ -97,36 +99,50 @@ static Stream parametersForTestProvideCustomPropertySchemaDefinitionF
Arguments.of("superTypeNoAnnotation", TestSubClass2.class, null),
Arguments.of("superTypeWithAnnotationOnField", null, null),
Arguments.of("superTypeWithAnnotationOnField", TestSubClass1.class,
- "{\"allOf\":[{},{\"title\":\"property attribute\",\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1\"}},"
- + "\"required\":[\"fullClass\"]}]}"),
+ """
+ {"allOf":[{},{"title":"property attribute","type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1"}},\
+ "required":["fullClass"]}]}\
+ """),
Arguments.of("superTypeWithAnnotationOnField", TestSubClass2.class,
- "{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2\"}},"
- + "\"required\":[\"fullClass\"]}]}"),
+ """
+ {"allOf":[{},{"type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2"}},\
+ "required":["fullClass"]}]}\
+ """),
Arguments.of("superTypeWithAnnotationOnGetter", null, null),
Arguments.of("superTypeWithAnnotationOnGetter", TestSubClass1.class,
- "{\"allOf\":[{},{\"title\":\"property attribute\",\"type\":\"object\","
- + "\"properties\":{\"@type\":{\"const\":\"SUB_CLASS_1\"}},\"required\":[\"@type\"]}]}"),
+ """
+ {"allOf":[{},{"title":"property attribute","type":"object",\
+ "properties":{"@type":{"const":"SUB_CLASS_1"}},"required":["@type"]}]}\
+ """),
Arguments.of("superTypeWithAnnotationOnGetter", TestSubClass2.class,
"{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"@type\":{\"const\":\"SUB_CLASS_2\"}},\"required\":[\"@type\"]}]}"),
Arguments.of("superTypeWithAnnotationOnFieldAndGetter", null, null),
Arguments.of("superTypeWithAnnotationOnFieldAndGetter", TestSubClass1.class,
- "{\"type\":\"array\",\"prefixItems\":[{\"type\":\"string\",\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1\"},"
- + "{\"allOf\":[{},{\"title\":\"property attribute\"}]}]}"),
+ """
+ {"type":"array","prefixItems":[{"type":"string","const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1"},\
+ {"allOf":[{},{"title":"property attribute"}]}]}\
+ """),
Arguments.of("superTypeWithAnnotationOnFieldAndGetter", TestSubClass2.class,
- "{\"type\":\"array\",\"prefixItems\":[{\"type\":\"string\",\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2\"},{}]}"),
+ """
+ {"type":"array","prefixItems":[{"type":"string","const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2"},{}]}\
+ """),
Arguments.of("superInterfaceWithAnnotationOnField", null, null),
Arguments.of("superInterfaceWithAnnotationOnField", TestSubClass3.class,
- "{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass3\"}},"
- + "\"required\":[\"fullClass\"]}]}"),
+ """
+ {"allOf":[{},{"type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass3"}},\
+ "required":["fullClass"]}]}\
+ """),
Arguments.of("superInterfaceWithAnnotationOnField", TestSubClass4.class,
- "{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass4\"}},"
- + "\"required\":[\"fullClass\"]}]}")
+ """
+ {"allOf":[{},{"type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass4"}},\
+ "required":["fullClass"]}]}\
+ """)
);
}
@@ -149,23 +165,31 @@ static Stream parametersForTestProvideCustomPropertySchemaDefinitionF
Arguments.of("getSuperTypeNoAnnotation", TestSubClass2.class, null),
Arguments.of("getSuperTypeWithAnnotationOnField", null, null),
Arguments.of("getSuperTypeWithAnnotationOnField", TestSubClass1.class,
- "{\"allOf\":[{},{\"title\":\"property attribute\",\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1\"}},"
- + "\"required\":[\"fullClass\"]}]}"),
+ """
+ {"allOf":[{},{"title":"property attribute","type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass1"}},\
+ "required":["fullClass"]}]}\
+ """),
Arguments.of("getSuperTypeWithAnnotationOnField", TestSubClass2.class,
- "{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"fullClass\":{\"const\":"
- + "\"com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2\"}},"
- + "\"required\":[\"fullClass\"]}]}"),
+ """
+ {"allOf":[{},{"type":"object","properties":{"fullClass":{"const":\
+ "com.github.victools.jsonschema.module.jackson.JsonSubTypesResolverCustomDefinitionsTest$TestSubClass2"}},\
+ "required":["fullClass"]}]}\
+ """),
Arguments.of("getSuperTypeWithAnnotationOnGetter", null, null),
Arguments.of("getSuperTypeWithAnnotationOnGetter", TestSubClass1.class,
- "{\"allOf\":[{},{\"title\":\"property attribute\",\"type\":\"object\","
- + "\"properties\":{\"@type\":{\"const\":\"SUB_CLASS_1\"}},\"required\":[\"@type\"]}]}"),
+ """
+ {"allOf":[{},{"title":"property attribute","type":"object",\
+ "properties":{"@type":{"const":"SUB_CLASS_1"}},"required":["@type"]}]}\
+ """),
Arguments.of("getSuperTypeWithAnnotationOnGetter", TestSubClass2.class,
"{\"allOf\":[{},{\"type\":\"object\",\"properties\":{\"@type\":{\"const\":\"SUB_CLASS_2\"}},\"required\":[\"@type\"]}]}"),
Arguments.of("getSuperTypeWithAnnotationOnFieldAndGetter", null, null),
Arguments.of("getSuperTypeWithAnnotationOnFieldAndGetter", TestSubClass1.class,
- "{\"type\":\"object\",\"properties\":{\"SUB_CLASS_1\":{\"allOf\":[{},{\"title\":\"property attribute\"}]}},"
- + "\"required\":[\"SUB_CLASS_1\"]}"),
+ """
+ {"type":"object","properties":{"SUB_CLASS_1":{"allOf":[{},{"title":"property attribute"}]}},\
+ "required":["SUB_CLASS_1"]}\
+ """),
Arguments.of("getSuperTypeWithAnnotationOnFieldAndGetter", TestSubClass2.class,
"{\"type\":\"object\",\"properties\":{\"SUB_CLASS_2\":{}},\"required\":[\"SUB_CLASS_2\"]}")
);
diff --git a/jsonschema-module-swagger-2/src/main/java/com/github/victools/jsonschema/module/swagger2/Swagger2Module.java b/jsonschema-module-swagger-2/src/main/java/com/github/victools/jsonschema/module/swagger2/Swagger2Module.java
index 11038742..97c3dce3 100644
--- a/jsonschema-module-swagger-2/src/main/java/com/github/victools/jsonschema/module/swagger2/Swagger2Module.java
+++ b/jsonschema-module-swagger-2/src/main/java/com/github/victools/jsonschema/module/swagger2/Swagger2Module.java
@@ -419,7 +419,7 @@ protected Boolean resolveArrayUniqueItems(MemberScope, ?> member) {
*/
protected CustomPropertyDefinition provideCustomSchemaDefinition(MemberScope, ?> scope, SchemaGenerationContext context) {
Optional externalReference = this.getSchemaAnnotationValue(scope, Schema::ref, ref -> !ref.isEmpty());
- if (!externalReference.isPresent()) {
+ if (externalReference.isEmpty()) {
return null;
}
// in Draft 6 and Draft 7, no other keywords are allowed besides a "$ref"