Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested structs in query params fail to encode #52

Open
WarningImHack3r opened this issue Oct 9, 2024 · 0 comments
Open

Nested structs in query params fail to encode #52

WarningImHack3r opened this issue Oct 9, 2024 · 0 comments

Comments

@WarningImHack3r
Copy link

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: myOpId
      parameters:
        - name: param_id
          in: query
          style: form
          schema:
            $ref: "#/components/schemas/ParentStruct"
...

with ParentStruct being generated like:

type ParentStruct struct {
   Header Header `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 code
client.MyEndpointWithResponse
  // generated code
  c.MyEndpoint(ctx, params, reqEditors...)
    NewMyEndpointRequest(c.Server, params)
      // starting from here we're inside `styleparam.go` from this repo
      runtime.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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant