private Predicate<DefinitionKey> getShouldProduceDefinitionCheck(DefinitionKey mainSchemaKey, AtomicBoolean considerOnlyDirectReferences) {
        final boolean createDefinitionsForAll = this.config.shouldCreateDefinitionsForAllObjects();
        final boolean inlineAllSchemas = this.config.shouldInlineAllSchemas();
        return definitionKey -> {
            if (this.generationContext.shouldNeverInlineDefinition(definitionKey)) {
                // e.g. custom definition explicitly marked to always produce a definition
                return true;
            }
            if (inlineAllSchemas) {
                // global setting: always inline schemas by default
                return false;
            }
            if (createDefinitionsForAll || definitionKey.equals(mainSchemaKey)) {
                return true;
            }
            List<ObjectNode> references = this.generationContext.getReferences(definitionKey);
            if (considerOnlyDirectReferences.get() && references.isEmpty()) {
                return false;
            }
            return references.size() > 1
                    || (references.size() + this.generationContext.getNullableReferences(definitionKey).size()) > 1;
        };
    }
Produce reusable predicate for checking whether a given type should produce an entry in the {@link SchemaKeyword#TAG_DEFINITIONS} or not.

@param mainSchemaKey main type to consider
@param considerOnlyDirectReferences whether to ignore nullable references when determining about definition vs. inlining
@return reusable predicate
jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java