private String updateReferences(List<ObjectNode> references, DefinitionCollectionDetails definitionCollectionDetails,
            Map.Entry<DefinitionKey, String> baseReferenceKey) {
        if (definitionCollectionDetails.shouldProduceDefinition(baseReferenceKey.getKey())) {
            final String referenceKey;
            if (definitionCollectionDetails.isMainSchemaKey(baseReferenceKey.getKey()) && !this.config.shouldCreateDefinitionForMainSchema()) {
                // no need to add the main schema into the definitions, unless explicitly configured to do so
                referenceKey = this.config.getKeyword(SchemaKeyword.TAG_REF_MAIN);
            } else {
                // add it to the definitions
                definitionCollectionDetails.getDefinitionsNode()
                        .set(baseReferenceKey.getValue(), this.generationContext.getDefinition(baseReferenceKey.getKey()));
                referenceKey = definitionCollectionDetails.getReferenceKey(baseReferenceKey.getValue());
            }
            references.forEach(node -> node.put(this.config.getKeyword(SchemaKeyword.TAG_REF), referenceKey));
            return referenceKey;
        }
        // in-line the sub-schema everywhere (assuming there is no complex hierarchy inside (especially no circular reference)
        ObjectNode definition = this.generationContext.getDefinition(baseReferenceKey.getKey());
        references.forEach(node -> AttributeCollector.mergeMissingAttributes(node, definition));
        return null;
    }
Finalisation Step: collect the entries for the generated schema's "definitions" and ensure that all references are either pointing to the
appropriate definition or contain the respective (sub) schema directly inline.

@param referenceKeyPrefix designated prefix to the entries in the returned definitions node (i.e., on {@link SchemaKeyword#TAG_REF} values)
@param mainSchemaKey definition key identifying the main type for which createSchemaReference() was invoked
@return node representing the main schema's "definitions" (may be empty)
jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java