Skip to content

Generated client code cannot convert UUIDs to string when used as path parameters. #943

@optimality

Description

@optimality

I have an API that defines a path parameter as such:

id:
      type: string
      format: uuid

The generated server code takes a uuid.UUID as a parameter, correctly. The generated client code also accepts a uuid.UUID as a parameter as well, again correctly.

But when I actually call the generated client function and pass a UUID in, I get unsupported type uuid.UUID. I believe this is because StyleParamWithLocation has no casing for uuid.UUID, it just forwards it to stylePrimitive, which forwards to primitiveToString, which also has no case for uuid.UUID.

The offending code is:

switch kind {
	case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
		output = strconv.FormatInt(v.Int(), 10)
	case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
		output = strconv.FormatUint(v.Uint(), 10)
	case reflect.Float64:
		output = strconv.FormatFloat(v.Float(), 'f', -1, 64)
	case reflect.Float32:
		output = strconv.FormatFloat(v.Float(), 'f', -1, 32)
	case reflect.Bool:
		if v.Bool() {
			output = "true"
		} else {
			output = "false"
		}
	case reflect.String:
		output = v.String()
	default:
		return "", fmt.Errorf("unsupported type %s", reflect.TypeOf(value).String())
	}

It would be trivial to add

case uuid.UUID:
    output = v.String()

but I'm not sure you want to introduce a dependency on uuid.UUID at this point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions