Skip to content

Commit

Permalink
fix: npe for custom void definition (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenWickner authored Sep 12, 2024
1 parent b116d48 commit cdf5aff
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### `jsonschema-generator`
#### Fixed
- avoid exception when trying to collect supported enum values from raw `Enum` type (i.e., missing type parameter)
- avoid exception when trying to find type with annotation when given type is `null`

### `jsonschema-module-jackson`
#### Fixed
- avoid exception in subtype resolution, when targeting void method

## [4.36.0] - 2024-07-20
### `jsonschema-generator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public ResolvedType getTypeWithAnnotation(ResolvedType targetType, Class<? exten
*/
public ResolvedType getTypeConsideringHierarchyMatching(ResolvedType targetType, Predicate<ResolvedType> check) {
ResolvedType targetSuperType = targetType;
do {
while (targetSuperType != null) {
if (check.test(targetSuperType)) {
return targetSuperType;
}
Expand All @@ -403,7 +403,7 @@ public ResolvedType getTypeConsideringHierarchyMatching(ResolvedType targetType,
return interfaceWithAnnotation.get();
}
targetSuperType = targetSuperType.getParentClass();
} while (targetSuperType != null);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public CustomEnumDefinitionProvider(boolean checkForJsonValueAnnotatedMethod, bo

@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
if (javaType == null) {
// since 4.37.0: not for void methods
return null;
}
Object[] enumConstants = javaType.getErasedType().getEnumConstants();
if (enumConstants == null || enumConstants.length == 0) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class JsonIdentityReferenceDefinitionProvider implements CustomDefinition

@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
if (javaType == null) {
// since 4.37.0: not for void methods
return null;
}
return this.getIdentityReferenceType(javaType, context.getTypeContext())
.map(context::createDefinitionReference)
.map(CustomDefinition::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ private ResolvedType resolveSubtype(ResolvedType declaredType, JsonSubTypes.Type
*/
@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
if (javaType == null) {
// since 4.37.0: not for void methods
return null;
}
ResolvedType typeWithTypeInfo = context.getTypeContext().getTypeWithAnnotation(javaType, JsonTypeInfo.class);
if (typeWithTypeInfo == null || javaType.getErasedType().getAnnotation(JsonSubTypes.class) != null
|| this.skipSubtypeResolution(javaType, context.getTypeContext())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class JsonUnwrappedDefinitionProvider implements CustomDefinitionProvider

@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
if (javaType == null) {
// since 4.37.0: not for void methods
return null;
}
ResolvedTypeWithMembers typeWithMembers = context.getTypeContext().resolveWithMembers(javaType);

if (Arrays.stream(typeWithMembers.getMemberFields()).noneMatch(this::hasJsonUnwrappedAnnotation)
Expand Down

0 comments on commit cdf5aff

Please sign in to comment.