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

Array of query parameters #441

Closed
KhraksMamtsov opened this issue Feb 10, 2024 · 4 comments
Closed

Array of query parameters #441

KhraksMamtsov opened this issue Feb 10, 2024 · 4 comments

Comments

@KhraksMamtsov
Copy link
Contributor

Single query parameter must be treated as single element array for appropriate schema.

export const GetManyUsersRequest = {
  query: Schema.struct({
    id: Schema.array(IdUserSchema)
  }),
};

Return 400 for GET /users?id=123
But 200 for GET /users?id=123&id=456

I have tried Schema<string[], string> for 123 -> [123] but it breaks swagger UI - it renders string input instead of several inputs for array of strings

@sukovanej
Copy link
Owner

I see. Yeah, the problem is the query parameters are first parsed onto a javascript object (by the @effect/platform) and only then they are passed to the schema decoder.

The solution that comes to my mind is to adjust the internal request parser in effect-http and convert any Schema.array(X) schema into a Schema.union(X + transformation onto a single item array, Schema.array(X)) schema. I'll try to think it through and prepare a PR.

For now, you can probably use the union in your code. Unfortunately, it will not solve the wrong visualisation in the swagger UI.

export const GetManyUsersRequest = {
  query: Schema.struct({
    id: Schema.union(Schema.array(IdUserSchema), IdUserSchema)
  }),
};

@KhraksMamtsov
Copy link
Contributor Author

KhraksMamtsov commented Feb 11, 2024

it should be noted that tuples also need to be taken into account
AFAIR there is separate ast for tuples

@KhraksMamtsov
Copy link
Contributor Author

@sukovanej I think better not to wrap user's schema, but wrap query-element into single array if users schema implies this.

otherwise in case of error user will get unexpected parse error - he enters one schema but errors from wrapper one
What do you think?

@sukovanej
Copy link
Owner

Should be solved by the new QuerySchema module.

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

2 participants