-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/form-data-array
- Loading branch information
Showing
363 changed files
with
52,669 additions
and
89,075 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
.yarn | ||
.yarnrc.yml | ||
|
||
# Runtime data | ||
pids | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn commitlint --edit | ||
yarn commitlint --edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint | ||
yarn test:ci | ||
yarn format:staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,8 @@ node_modules | |
|
||
# Build | ||
.next | ||
**/dist | ||
**/dist | ||
.husky | ||
mockServiceWorker.js | ||
yarn.lock | ||
.svelte-kit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
nodeLinker: node-modules | ||
packageExtensions: | ||
'@vue/test-utils@*': | ||
peerDependencies: | ||
vue: '*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
id: fetch | ||
title: Fetch | ||
--- | ||
|
||
<a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch" target="_blank">The `fetch` API</a> has the advantage of reducing the bundle size of the application compared to using `Axios`. It can also act as an `http client` in server-side frameworks and edge computing runtimes such as `Cloudflare`, `Vercel Edge` and `Deno`. | ||
|
||
You should have an `OpenAPI` specification and an `Orval` config where you define the mode as `fetch`. | ||
|
||
#### Example with fetch | ||
|
||
```ts | ||
import { defineConfig } from 'orval'; | ||
|
||
export default defineConfig({ | ||
petstore: { | ||
output: { | ||
mode: 'tags-split', | ||
target: 'app/gen/petstore.ts', | ||
schemas: 'app/gen/models', | ||
client: 'fetch', | ||
baseUrl: 'http://localhost:3000', | ||
mock: true, | ||
}, | ||
input: { | ||
target: './petstore.yaml', | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
Checkout the [orval config](../reference/configuration/full-example) reference to see all available options. | ||
Like the following example from this <a href="https://github.com/anymaniax/orval/blob/master/samples/next-app-with-fetch/petstore.yaml" target="_blank">`OpenAPI` Specification</a>: | ||
|
||
```ts | ||
/** | ||
* @summary List all pets | ||
*/ | ||
export type listPetsResponse = { | ||
data: Pets; | ||
status: number; | ||
}; | ||
|
||
export const getListPetsUrl = (params?: ListPetsParams) => { | ||
const normalizedParams = new URLSearchParams(); | ||
|
||
Object.entries(params || {}).forEach(([key, value]) => { | ||
if (value === null) { | ||
normalizedParams.append(key, 'null'); | ||
} else if (value !== undefined) { | ||
normalizedParams.append(key, value.toString()); | ||
} | ||
}); | ||
|
||
return `http://localhost:3000/pets?${normalizedParams.toString()}`; | ||
}; | ||
|
||
export const listPets = async ( | ||
params?: ListPetsParams, | ||
options?: RequestInit, | ||
): Promise<listPetsResponse> => { | ||
const res = await fetch(getListPetsUrl(params), { | ||
...options, | ||
method: 'GET', | ||
}); | ||
const data = await res.json(); | ||
|
||
return { status: res.status, data }; | ||
}; | ||
``` | ||
|
||
The `fetch` client will generate an implementation file with following per path in your `OpenAPI` Specification. | ||
|
||
1. A response type for the `fetch` function | ||
2. A Function to generate request URL including query parameters and path parameters | ||
3. A function that call `fetch` API. | ||
|
||
Checkout <a href="https://github.com/anymaniax/orval/blob/master/samples/next-app-with-fetch" target="_blank">here</a> the full example | ||
|
||
#### Custom instance | ||
|
||
You can add a custom `fetch` function to your config. | ||
|
||
```ts | ||
module.exports = { | ||
petstore: { | ||
output: { | ||
... | ||
override: { | ||
mutator: { | ||
path: './custom-fetch.ts', | ||
name: 'customFetch', | ||
}, | ||
}, | ||
} | ||
... | ||
}, | ||
}; | ||
``` | ||
|
||
And, you prepare like the <a href="https://github.com/anymaniax/orval/blob/master/samples/next-app-with-fetch/custom-fetch.ts" target="_blank">sample implementation</a> | ||
Then, you can generate a `fetch` client that calls the `customFetch` function like bellow: | ||
|
||
```ts | ||
export const listPets = async ( | ||
params?: ListPetsParams, | ||
options?: RequestInit, | ||
): Promise<listPetsResponse> => { | ||
return customFetch<Promise<listPetsResponse>>(getListPetsUrl(params), { | ||
...options, | ||
method: 'GET', | ||
}); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.