Commit de3f7eb
authored
fix: support array of 1 for query parameter arrays (round 2) (#225)
#220 got a bit off-track with scope creep.
this PR takes a similar approach, but for internal use only
- detects query parameters with array type schemas
- adds an internal annotation to indicate these need preprocessing
- applies a `z.preprocess` to coerce an individual value to an array of
1 element, before parsing with the array schema
- for `joi` we resort to a pretty hacky wrapping of the schema with a
object that does the preprocessing, as the `joi` extension API didn't
work as I'd expected it to.
will continue experimenting with making this a more generally useful
feature for handling things like parsing `date-time` strings to be a
`Date`, etc, separately.
fixes #217
**Testing Notes**
Need to improve automated test coverage still, but manually tested on a
running server:
- No query params
- 1 element
- 2 elements
- 2 elements, 1 element
and it seems to be working correctly.
```
listening on http://127.0.0.1:3000
query { query: {} }
query { query: { statuses: [ 'complete' ] } }
query { query: { statuses: [ 'complete', 'incomplete' ] } }
query { query: { statuses: [ 'complete', 'incomplete' ] } }
query { query: { statuses: [ 'complete', 'incomplete' ], tags: [ '123' ] } }
```1 parent ea0d044 commit de3f7eb
File tree
24 files changed
+2039
-506
lines changed- integration-tests-definitions
- integration-tests
- typescript-angular/src/generated/todo-lists.yaml
- typescript-axios/src/generated/todo-lists.yaml
- typescript-fetch/src/generated/todo-lists.yaml
- typescript-koa/src
- generated
- api.github.com.yaml
- azure-core-data-plane-service.tsp
- petstore-expanded.yaml
- stripe.yaml
- todo-lists.yaml
- packages/openapi-code-generator/src
- core
- typescript
- common/schema-builders
- typescript-koa
24 files changed
+2039
-506
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
174 | 178 | | |
175 | 179 | | |
176 | 180 | | |
177 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
178 | 188 | | |
179 | 189 | | |
180 | 190 | | |
| |||
Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments