public Map<String, TypeReference> getDiscriminatorTypes(TypeDefinition type) {
        // Get the parent type (Which contains the typeSwitch field)
        SwitchField switchField = null;
        Function<String, TypeReference> typeRefRetriever = null;
        if (type.isDiscriminatedComplexTypeDefinition()) {
            DiscriminatedComplexTypeDefinition discriminatedComplexTypeDefinition = type.asDiscriminatedComplexTypeDefinition().orElseThrow();
            switchField = discriminatedComplexTypeDefinition.getSwitchField().orElse(null);
            typeRefRetriever = propertyName -> discriminatedComplexTypeDefinition.getTypeReferenceForProperty(propertyName).orElse(null);
            // Please forgive us, we didn't know what we were doing.
            if(switchField == null) {
                ComplexTypeDefinition parentType = type.asDiscriminatedComplexTypeDefinition().orElseThrow().getParentType().orElseThrow();
                switchField = parentType.getSwitchField().orElse(null);
                typeRefRetriever = propertyName -> parentType.getTypeReferenceForProperty(propertyName).orElse(null);
            }
        } else if (type.isDataIoTypeDefinition()) {
            final DefaultDataIoTypeDefinition dataIoTypeDefinition = (DefaultDataIoTypeDefinition) type;
            switchField = dataIoTypeDefinition.getSwitchField().orElseThrow();
            typeRefRetriever = propertyName -> type.getParserArguments()
                .orElse(Collections.emptyList())
                .stream()
                .filter(argument -> argument.getName().equals(propertyName))
                .findFirst()
                .map(Argument::getType)
                .orElse(null);
        } else if (type.isComplexTypeDefinition()) {
            switchField = ((ComplexTypeDefinition) type).getSwitchField().orElse(null);
            typeRefRetriever = propertyName -> ((ComplexTypeDefinition) type).getTypeReferenceForProperty(propertyName).orElse(null);
        }
        // Get the typeSwitch field from that.
        if (switchField == null) {
            return Collections.emptyMap();
        }
        Map<String, TypeReference> discriminatorTypes = new TreeMap<>();
        for (VariableLiteral variableLiteral : switchField.getDiscriminatorExpressions()) {
            // Get some symbolic name we can use.
            String discriminatorName = variableLiteral.getDiscriminatorName();
            final TypeReference typeReference = typeRefRetriever.apply(variableLiteral.getName());
            Optional<TypeReference> discriminatorType = typeReference.getDiscriminatorType(variableLiteral);
            if (discriminatorType.isEmpty()) {
                throw new RuntimeException("no type for " + discriminatorName);
            }
            discriminatorTypes.put(discriminatorName, discriminatorType.orElse(null));
        }
        return discriminatorTypes;
    }
Get a list of the types for every discriminator name.

@return Map mapping discriminator names to types.
code-generation/language-base-freemarker/src/main/java/org/apache/plc4x/plugins/codegenerator/protocol/freemarker/BaseFreemarkerLanguageTemplateHelper.java