Skip to content

openapi-fetch improvements #1169

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

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-ligers-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": patch
---

Clone response internally
5 changes: 5 additions & 0 deletions .changeset/khaki-bobcats-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": minor
---

Expose createFinalURL() logic for testing
5 changes: 5 additions & 0 deletions .changeset/khaki-cycles-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": minor
---

Automatically remove `undefined` and `null` query params without requiring querySerializer
5 changes: 5 additions & 0 deletions .changeset/long-llamas-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": patch
---

Strip trailing slashes from baseUrl
5 changes: 5 additions & 0 deletions .changeset/mighty-dots-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": patch
---

Fix querySerializer typing
5 changes: 5 additions & 0 deletions .changeset/rude-bikes-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": minor
---

Allow overriding of JSON body parsing
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
"@typescript-eslint/consistent-indexed-object-style": "off", // sometimes naming keys is more user-friendly
"@typescript-eslint/no-dynamic-delete": "off", // delete is OK
"@typescript-eslint/no-unnecessary-condition": "off", // this gives bad advice
"no-console": "error",
"no-unused-vars": "off",
},
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"@astrojs/sitemap": "^1.3.1",
"@types/node": "^20.2.3",
"html-escaper": "^3.0.3",
"typescript": "^5.0.4"
"typescript": "^5.1.3"
}
}
17 changes: 9 additions & 8 deletions docs/src/content/docs/openapi-fetch/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ const { get, put, post, del, options, head, patch, trace } = createClient<paths>
const { data, error, response } = await get("/my-url", options);
```

| Name | Type | Description |
| :---------------- | :-----------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `params` | ParamsObject | Provide `path` and `query` params from the OpenAPI schema |
| `params.path` | `{ [name]: value }` | Provide all `path` params (params that are part of the URL) |
| `params.query` | `{ [name]: value }` | Provide all `query params (params that are part of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams" target="_blank" rel="noopener noreferrer">searchParams</a> |
| `body` | `{ [name]:value }` | The <a href="https://spec.openapis.org/oas/latest.html#request-body-object" target="_blank" rel="noopener noreferrer">requestBody</a> data, if needed (PUT/POST/PATCH/DEL only) |
| `querySerializer` | QuerySerializer | (optional) Override default param serialization (see [Parameter Serialization](#parameter-serialization)) |
| (Fetch options) | | Any valid fetch option (`headers`, `mode`, `cache`, `signal` …) (<a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch#options" target="_blank" rel="noopener noreferrer">docs</a>) |
| Name | Type | Description |
| :---------------- | :---------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `params` | ParamsObject | Provide `path` and `query` params from the OpenAPI schema |
| `params.path` | `{ [name]: value }` | Provide all `path` params (params that are part of the URL) |
| `params.query` | `{ [name]: value }` | Provide all `query params (params that are part of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams" target="_blank" rel="noopener noreferrer">searchParams</a> |
| `body` | `{ [name]:value }` | The <a href="https://spec.openapis.org/oas/latest.html#request-body-object" target="_blank" rel="noopener noreferrer">requestBody</a> data, if needed (PUT/POST/PATCH/DEL only) |
| `querySerializer` | QuerySerializer | (optional) Override default param serialization (see [Parameter Serialization](#parameter-serialization)) |
| `parseAs` | `"json"` \| `"text"` \| `"arrayBuffer"` \| `"blob"` \| `"stream"` | Decide how to parse the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/body" target="_blank" rel="noopener noreferrer">response body</a>, with `"stream"` skipping processing altogether (default: `"json"`) |
| (Fetch options) | | Any valid fetch option (`headers`, `mode`, `cache`, `signal` …) (<a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch#options" target="_blank" rel="noopener noreferrer">docs</a>) |

### Parameter Serialization

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"del-cli": "^5.0.0",
"eslint": "^8.41.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"typescript": "^5.0.4"
"typescript": "^5.1.3"
}
}
8 changes: 4 additions & 4 deletions packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
},
"devDependencies": {
"del-cli": "^5.0.0",
"esbuild": "^0.17.19",
"esbuild": "^0.18.3",
"nanostores": "^0.8.1",
"openapi-typescript": "^6.2.4",
"openapi-typescript": "^6.2.7",
"prettier": "^2.8.8",
"typescript": "^5.0.4",
"vitest": "^0.31.1",
"typescript": "^5.1.3",
"vitest": "^0.32.0",
"vitest-fetch-mock": "^0.2.2"
}
}
Loading