Skip to content

Illegal substituion of UUID, better handling of arrays #2024

Closed

Description

@espenvis

Problem & Background

Kiota will produce code using java.util.UUID if you specify uuid as the format of a string in your OpenAPI specification.

For query parameters, the java.util.UUID type is handled appropriately with the use of getSanitizedValues in order to transform the UUID into its string representation.

That is, until you attempt to pass an array of UUIDs as a query parameter.

The issue is that there is no strategy in getSanitizedValues to handle arrays of any types besides ValuedEnum. To me, this smells like an oversight, where ValuedEnum was reported to not function properly when passed as part of an array, and a fix was made for it, but not for any other types.

Solution

I propose we shoot for one solution for all types handled in getSanitizedValues, and all future types that may be added:

    private static Object getSanitizedValues(Object value) {
        if (value == null) {
            return null;
        }
        if (value.getClass().isArray()) {
            if (((Object[]) value).length > 0 && ((Object[]) value)[0].getClass().isArray()) {
                // Perhaps handle this, as I do not know if arrays of arrays is something you'd
                //  fancy passed as a query parameter (or path parameter for that matter)
            }
            final ArrayList<Object> result = new ArrayList<>();
            for (final Object item : (Object[]) value) {
                // Reuse the implementation of getSanitizedValues
                //  to cover all future additions to sanitization.
                result.add(getSanitizedValues(item));
            }
            return result;
        }

        if (value instanceof ValuedEnum) {
            return ((ValuedEnum) value).getValue();
        } else if (value instanceof UUID) {
            return value.toString();
        } else if (value instanceof OffsetDateTime) {
            return ((OffsetDateTime) value).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
        } else if (value instanceof LocalDate) {
            return ((LocalDate) value).format(DateTimeFormatter.ISO_LOCAL_DATE);
        } else if (value instanceof LocalTime) {
            return ((LocalTime) value).format(DateTimeFormatter.ISO_LOCAL_TIME);
        } else if (value instanceof PeriodAndDuration) {
            return ((PeriodAndDuration) value).toString();
        } else {
            return value;
        }
    }
}

So that we don't need to duplicate logic and individually support array instances of each supported type.

Let me know if there is anything else to consider, or if this behavior is intended (in which case, Kiota should not respect the uuid format in OpenAPI schemas for array types).

Activity

  1. moved this to Needs Triage 🔍 in Kiotaon Sep 4, 2025
  2. espenvis commented on Nov 18, 2025

    @espenvis
    ContributorAuthor

    This is a bug that requires some hacky workarounds. If need be I can take care of the implementation as soon as we agree on the solution.

    EDIT: because the change is simple I went ahead and created a PR

  3. moved this from Needs Triage 🔍 to Done ✔️ in Kiotaon Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✔️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions