Skip to content

Commit de3f7eb

Browse files
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

24 files changed

+2039
-506
lines changed

integration-tests-definitions/todo-lists.yaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ paths:
1010
schema:
1111
type: string
1212
format: date-time
13-
- name: status
13+
- name: statuses
1414
in: query
1515
schema:
16-
type: string
17-
enum:
18-
- incomplete
19-
- complete
16+
$ref: '#/components/schemas/Statuses'
17+
- name: tags
18+
in: query
19+
schema:
20+
type: array
21+
items:
22+
type:
23+
string
2024
get:
2125
operationId: getTodoLists
2226
responses:
@@ -174,7 +178,13 @@ components:
174178
updated:
175179
type: string
176180
format: date-time
177-
181+
Statuses:
182+
type: array
183+
items:
184+
type: string
185+
enum:
186+
- incomplete
187+
- complete
178188
parameters:
179189
listId:
180190
name: listId

integration-tests/typescript-angular/src/generated/todo-lists.yaml/client.service.ts

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-angular/src/generated/todo-lists.yaml/models.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-axios/src/generated/todo-lists.yaml/client.ts

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-axios/src/generated/todo-lists.yaml/models.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-fetch/src/generated/todo-lists.yaml/client.ts

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-fetch/src/generated/todo-lists.yaml/models.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-koa/src/generated/api.github.com.yaml/generated.ts

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-koa/src/generated/azure-core-data-plane-service.tsp/generated.ts

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/typescript-koa/src/generated/petstore-expanded.yaml/generated.ts

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

Comments
 (0)