@Override
        public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
            Class<?> erasedType = javaType.getErasedType();
            if (this.mainType == null) {
                this.mainType = erasedType;
            }
            if (this.mainType == erasedType) {
                // avoid external ref to the "main" schema being generated
                return null;
            }
            // look-up external reference from @Schema(ref = "...")
            return Optional.ofNullable(erasedType.getAnnotation(Schema.class))
                    .map(Schema::ref)
                    .filter(ref -> !ref.isEmpty())
                    .map(ref -> context.getGeneratorConfig().createObjectNode()
                            .put(context.getKeyword(SchemaKeyword.TAG_REF), ref))
                    .map(schema -> new CustomDefinition(schema,
                            CustomDefinition.INLINE_DEFINITION,
                            CustomDefinition.INCLUDING_ATTRIBUTES))
                    .orElse(null);
        }
Example created in response to <a href="https://github.com/victools/jsonschema-generator/issues/319">#319</a>.
<br/>
Based on Swagger2 {@code @Schema} annotations, allowing to reference "external" files.
jsonschema-examples/src/main/java/com/github/victools/jsonschema/examples/ExternalRefAnnotationExample.java