@Override
    public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
        if (javaType == null) {
            // since 4.37.0: not for void methods
            return null;
        }
        final TypeContext typeContext = context.getTypeContext();
        ResolvedType typeWithTypeInfo = typeContext.getTypeWithAnnotation(javaType, JsonTypeInfo.class, JacksonModule.NESTED_ANNOTATION_CHECK);
        if (typeWithTypeInfo == null
                || AnnotationHelper.resolveAnnotation(javaType.getErasedType(), JsonSubTypes.class, JacksonModule.NESTED_ANNOTATION_CHECK).isPresent()
                || this.skipSubtypeResolution(javaType, typeContext)) {
            // no @JsonTypeInfo annotation found or the given javaType is the super type, that should be replaced
            return null;
        }
        Class<?> erasedTypeWithTypeInfo = typeWithTypeInfo.getErasedType();
        final List<Annotation> annotationsList = Arrays.asList(erasedTypeWithTypeInfo.getAnnotations());
        JsonTypeInfo typeInfoAnnotation = typeContext.getAnnotationFromList(JsonTypeInfo.class, annotationsList,
                JacksonModule.NESTED_ANNOTATION_CHECK);
        JsonSubTypes subTypesAnnotation = typeContext.getAnnotationFromList(JsonSubTypes.class, annotationsList,
                JacksonModule.NESTED_ANNOTATION_CHECK);
        TypeScope scope = typeContext.createTypeScope(javaType);
        ObjectNode definition = this.createSubtypeDefinition(scope, typeInfoAnnotation, subTypesAnnotation, context);
        if (definition == null) {
            return null;
        }
        return new CustomDefinition(definition, this.wrappingSubtypeDefinitionType, CustomDefinition.AttributeInclusion.NO);
    }
Safe way of resolving an erased subtype from its supertype. If the subtype introduces generic parameters not present on the supertype, the
subtype will be resolved without any type parameters - for simplicity's sake not even the ones declared alongside the supertype then.

@param declaredType supertype encountered while generating a schema
@param annotatedSubtype single subtype declared via {@link JsonSubTypes} on the super class
@param context type context for proper type resolution
@return resolved annotated subtype
jsonschema-module-jackson/src/main/java/com/github/victools/jsonschema/module/jackson/JsonSubTypesResolver.java