private OperationShape getPreferredExampleOperation()

in codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java [127:176]


    private OperationShape getPreferredExampleOperation(Collection<OperationShape> operations, Model model) {
        // Heuristic score used to rank the candidate operations.
        long candidateOperationScore = Long.MIN_VALUE;
        OperationShape candidateOperation = null;

        for (OperationShape operation : operations) {
            long heuristicScore = 0;

            String name = operation.getId().getName().toLowerCase();

            heuristicScore -= name.length() / 6;

            if (name.startsWith("list")) {
                heuristicScore += 20;
            } else if (
                name.startsWith("get")
                || name.startsWith("describe")
                || name.startsWith("retrieve")
                || name.startsWith("fetch")
            ) {
                heuristicScore += 10;
            } else if (
                name.startsWith("delete")
                || name.startsWith("remove")
                || name.startsWith("stop")
                || name.startsWith("abort")
                || name.startsWith("terminate")
                || name.startsWith("deactivate")
                || name.startsWith("toggle")
            ) {
                heuristicScore -= 20;
            }

            Optional<Shape> input = model.getShape(operation.getInputShape());
            if (input.isPresent()) {
                long inputFields = input.get().getAllMembers().values().stream()
                    .filter(member -> member.isRequired())
                    .count();

                heuristicScore -= inputFields;
            }

            if (heuristicScore > candidateOperationScore) {
                candidateOperation = operation;
                candidateOperationScore = heuristicScore;
            }
        }

        return candidateOperation;
    }