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

Object encoding in query parameters #606

Open
m1212e opened this issue Apr 11, 2024 · 1 comment
Open

Object encoding in query parameters #606

m1212e opened this issue Apr 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@m1212e
Copy link
Contributor

m1212e commented Apr 11, 2024

Calling the API via the treaty encodes objects passed as query params as literally "[object Object]" instead of URL encoding it.

      this.iam.auth.domain.user.get({
        query: {
          role: [{ id: orga.adminRoleId }, { id: orga.memberRoleId }],
        },
      })

and on the receiving end:

      query: t.Optional(
        t.Object({
          role: t.Optional(
            t.Array(t.Partial(t.Pick(Role, ["id", "name", "authProviderId"]))),
          ),
        }),
      ),

results in

   "type": "validation",
   "on": "query",
   "property": "/role",
   "message": "Expected array",
   "expected": {},
   "found": {
     "role": "[object Object],[object Object]"
   },
   "errors": [
     {
       "type": 6,
       "schema": {
         "type": "array",
         "items": {
           "description": "Composition of RolePlain, RoleRelations",
           "additionalProperties": false,
           "type": "object",
           "properties": {
             "id": {
               "type": "string"
             },
             "name": {
               "type": "string"
             },
             "authProviderId": {
               "type": "string"
             }
           }
         }
       },
       "path": "/role",
       "value": "[object Object],[object Object]",
       "message": "Expected array"
     }
   ]
 }. Thrown at Error: {
   "type": "validation",
   "on": "query",
   "property": "/role",
   "message": "Expected array",
   "expected": {},
   "found": {
     "role": "[object Object],[object Object]"
   },

Is this as it should work and we are just expected to only send primitive values via query parameters?
Thanks!

@m1212e m1212e added the bug Something isn't working label Apr 11, 2024
@m1212e
Copy link
Contributor Author

m1212e commented Apr 15, 2024

Just realized that it may not be the intended usage for query parameters to be anything beyond strings: https://elysiajs.com/validation/schema-type#query

If thats the case, maybe it would make sense to only every allow strings or optional strings to be passed as query schema to the handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant