@Override
            public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
                Class<?> erasedType = javaType.getErasedType();
                if (this.mainType == null) {
                    this.mainType = erasedType;
                } else if (!this.isMainType(javaType)
                        && erasedType.getPackage() != null
                        && erasedType.getPackage().getName().startsWith(this.packageForExternalRefs)) {
                    ObjectNode schema = context.getGeneratorConfig().createObjectNode()
                            .put(context.getKeyword(SchemaKeyword.TAG_REF), this.getExternalRef(javaType));
                    return new CustomDefinition(schema, CustomDefinition.INLINE_DEFINITION, CustomDefinition.INCLUDING_ATTRIBUTES);
                }
                return null;
            }
Wrapped as module with zero-parameter constructor for use via the Maven plugin.
jsonschema-examples/src/main/java/com/github/victools/jsonschema/examples/ExternalRefPackageExample.java