Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npe for custom void definition #474

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Comment on lines +62 to +65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
provideCustomSchemaDefinition has a cyclomatic complexity of 9, threshold = 9

Suppress

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
Loading