Skip to content

Commit

Permalink
fix(fetch/axios): correctly merge headers from opts (#231)
Browse files Browse the repository at this point in the history
- Previously if you passed any request headers using the `opts`
parameter, this would overwrite the headers set from parameters,
defaults, etc
- Now these will be consistently merged following: `defaults` ->
`params` -> `opts`
- `undefined` header values will be ignored, `null` header values will
delete headers set previously

This wound up being a lot more complex than I'd expected, and there may
still be some edges that I've missed. However I'm confident that this
makes things better than before based on the new e2e tests at least.
  • Loading branch information
mnahkies authored Aug 17, 2024
1 parent 41c48cb commit 5efc36e
Show file tree
Hide file tree
Showing 38 changed files with 19,283 additions and 13,674 deletions.
40 changes: 40 additions & 0 deletions e2e/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,32 @@ info:
title: E2E Tests for @nahkies/openapi-code-generator
version: "0.0.1"
tags:
- name: headers
- name: validation
paths:
/headers/undeclared:
get:
tags:
- headers
responses:
200:
$ref: '#/components/responses/GetHeaders'
/headers/request:
get:
tags:
- headers
parameters:
- name: route-level-header
in: header
schema:
type: string
- name: Authorization
in: header
schema:
type: string
responses:
200:
$ref: '#/components/responses/GetHeaders'
/validation/numbers/random-number:
get:
tags:
Expand Down Expand Up @@ -38,6 +62,22 @@ paths:
$ref: '#/components/schemas/RandomNumber'

components:
responses:
GetHeaders:
description: success
content:
application/json:
schema:
type: object
properties:
headers:
additionalProperties:
anyOf:
- type: string
- type: array
items:
type: string

schemas:
RandomNumber:
type: object
Expand Down
12 changes: 9 additions & 3 deletions e2e/scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ yarn openapi-code-generator \

yarn openapi-code-generator \
--input ./openapi.yaml \
--output ./src/generated/client \
--output ./src/generated/client/fetch \
--template typescript-fetch \
--schema-builder zod \
--extract-inline-schemas \
--grouping-strategy first-tag \
--extract-inline-schemas

yarn openapi-code-generator \
--input ./openapi.yaml \
--output ./src/generated/client/axios \
--template typescript-axios \
--schema-builder zod \
--extract-inline-schemas
88 changes: 88 additions & 0 deletions e2e/src/generated/client/axios/client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions e2e/src/generated/client/axios/models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 0 additions & 38 deletions e2e/src/generated/client/client.ts

This file was deleted.

79 changes: 79 additions & 0 deletions e2e/src/generated/client/fetch/client.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions e2e/src/generated/client/fetch/models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions e2e/src/generated/client/models.ts

This file was deleted.

16 changes: 16 additions & 0 deletions e2e/src/generated/models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5efc36e

Please sign in to comment.