private void collectReferenceKeysFromGroup(Map<DefinitionKey, String> referenceKeys, Map.Entry<String, List<DefinitionKey>> group,
            DefinitionKey mainSchemaKey, Predicate<DefinitionKey> shouldProduceDefinition) {
        String baseDefinitionName = group.getKey();
        List<DefinitionKey> definitionKeys = group.getValue().stream()
                .peek(key -> referenceKeys.put(key, ""))
                .filter(shouldProduceDefinition)
                .collect(Collectors.toList());
        if (this.areDefinitionKeysDistinct(mainSchemaKey, definitionKeys)) {
            definitionKeys.forEach(key -> referenceKeys.put(key, baseDefinitionName));
        } else {
            Map<DefinitionKey, String> referenceKeyGroup = definitionKeys.stream()
                    .collect(Collectors.toMap(key -> key, _key -> baseDefinitionName, (val1, _val2) -> val1, LinkedHashMap::new));
            this.definitionNamingStrategy.adjustDuplicateNames(referenceKeyGroup, this.generationContext);
            if (definitionKeys.size() != referenceKeyGroup.size()) {
                throw new IllegalStateException(SchemaDefinitionNamingStrategy.class.getSimpleName()
                        + " of type " + this.definitionNamingStrategy.getClass().getSimpleName()
                        + " altered list of subschemas with duplicate names.");
            }
            referenceKeys.putAll(referenceKeyGroup);
        }
    }
Derive the applicable keys for the collected entries for the {@link SchemaKeyword#TAG_DEFINITIONS} in the given context.

@param mainSchemaKey special definition key for the main schema
@param shouldProduceDefinition filter to indicate whether a given key should be considered when determining definition names
@return encountered types with their corresponding reference keys
jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java