Array of query parameters
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
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)
}),
};
it should be noted that tuples also need to be taken into account AFAIR there is separate ast for tuples
@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?
Should be solved by the new QuerySchema module.