Skip to content

Nested structs in query params fail to encode #52

Description

@WarningImHack3r

Such a YAML endpoint fails to encode on client request invocation, leading to a error formatting 'param_id': unsupported type Header error with a nested struct:

...
paths:
/my/endpoint:
post:
security: []operationId: myOpIdparameters:
- name: param_idin: querystyle: formschema:
$ref: "#/components/schemas/ParentStruct"
...

with ParentStruct being generated like:

typeParentStructstruct {
HeaderHeader`json:"header"`// a simple struct with a few fields
}

(I don't own and can't modify the YAML, I know such a use case is very unconventional)

Call stack:

// my codeclient.MyEndpointWithResponse// generated codec.MyEndpoint(ctx, params, reqEditors...)
NewMyEndpointRequest(c.Server, params)
// starting from here we're inside `styleparam.go` from this reporuntime.StyleParamWithLocation("form", true, "param_id", runtime.ParamLocationQuery, *params.ParamId)
styleStruct(style, explode, paramName, paramLocation, value)
primitiveToString(value) // <-- value is my Header here// inside this function, it correctly passes into the `case reflect.Struct`, but fails because it doesn't conform to `uuid.UUID` nor to `json.Marshaler` (for some reason)// as a result, it `fallthrough`s in `default:` and also fails the conformity check to `fmt.Stringer`, leading to the error.

I didn't inspect the code that much, but I fail to understand why the serialization process uses the custom reflection logic instead of simply using json.Encode which would 100% do the job.

Thank you in advance!

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