Skip to content

Commit

Permalink
Merge branch 'master' into fix/form-data-array
Browse files Browse the repository at this point in the history
  • Loading branch information
BijanRegmi committed Jun 26, 2024
2 parents 3cfb3d0 + e038704 commit 21060a1
Show file tree
Hide file tree
Showing 363 changed files with 52,669 additions and 89,075 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Enable corepack
run: corepack enable
- name: install
run: yarn
- name: build
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.yarn
.yarnrc.yml

# Runtime data
pids
Expand Down
5 changes: 1 addition & 4 deletions .husky/commit-msg
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
3 changes: 0 additions & 3 deletions .husky/pre-commit
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
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ node_modules

# Build
.next
**/dist
**/dist
.husky
mockServiceWorker.js
yarn.lock
.svelte-kit
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodeLinker: node-modules
packageExtensions:
'@vue/test-utils@*':
peerDependencies:
vue: '*'
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ You can find below some samples:
- [svelte query](https://github.com/anymaniax/orval/tree/master/samples/svelte-query)
- [vue query](https://github.com/anymaniax/orval/tree/master/samples/vue-query)
- [react app with swr](https://github.com/anymaniax/orval/tree/master/samples/react-app-with-swr)
- [nx fastify react](https://github.com/anymaniax/orval/tree/master/samples/nx-fastify-react)
- [angular app](https://github.com/anymaniax/orval/tree/master/samples/angular-app)
- [hono](https://github.com/anymaniax/orval/tree/master/samples/hono)

Expand Down
5 changes: 5 additions & 0 deletions docs/src/manifests/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"path": "/guides/basics",
"editUrl": "/guides/basics.md"
},
{
"title": "Fetch API",
"path": "/guides/fetch",
"editUrl": "/guides/fetch.md"
},
{
"title": "React query",
"path": "/guides/react-query",
Expand Down
114 changes: 114 additions & 0 deletions docs/src/pages/guides/fetch.md
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',
});
};
```
6 changes: 3 additions & 3 deletions docs/src/pages/guides/msw.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ A function that returns a mock object will be generated as shown below:
```typescript
import { faker } from '@faker-js/faker';

export const getShowPetByIdMock = (overrideResponse?: any) => ({
export const getShowPetByIdMock = (overrideResponse?: Partial<Type>): Type => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
Expand All @@ -50,9 +50,9 @@ If you want to overwrite part of the object, you can write the mock value by spe
```typescript
import { getShowPetByIdMock } from 'pets.msw';

const pet = getShowPetByIdMock({ name: 'orverride' });
const pet = getShowPetByIdMock({ name: 'override' });
console.log(pet);
// => { id: 7272122785202176, ​name: "orverride", tag: undefined }
// => { id: 7272122785202176, ​name: "override", tag: undefined }
```

#### A function that returns the value of binding the mock object to the http request handler of `MSW`
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/guides/zod.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ The `zod` object generated automatically can be utilized in the usual manner.

```ts
import type { z } from 'zod';
import { createPetsBody } from './src/gen/zod/swaggerPetstore.ts';
import { createPetsBodyItem } from './src/gen/zod/swaggerPetstore.ts';

const pet = { id: 1, name: 'pet name', tag: 'tag' };

// parsing
const parsedPet = createPetsBodyItem.parse();
const parsedPet = createPetsBodyItem.parse(pet);
console.log(parsedPet);
// => Object { id: 1, name: "pet name", tag: "tag" }

Expand Down
8 changes: 8 additions & 0 deletions docs/src/pages/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ The `--tslint`, can be used to specify `tslint` ([TSLint is deprecated in favour
$ orval --tslint
```
### biome
The `--biome`, can be used to [`Biome`](https://biomejs.dev/) generated files. You need to have `Biome` in your global dependencies.
```bash
$ orval --biome
```
### tsconfig
The `--tsconfig`, can be used to specify the path to your `tsconfig`.
Expand Down
31 changes: 29 additions & 2 deletions docs/src/pages/reference/configuration/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,44 @@ Example of transformer <a href="https://github.com/anymaniax/orval/blob/master/s

Type: `Object`.

Default Value: `{}`.

If specified, Orval only generates the endpoints after applying the filter.

#### tags

Type: Array of `string` or `RegExp`.

Default Value: `[]`.

It is possible to filter on `tags`.
For instance the example below only generates the endpoints that contain the tag `pets` or matches the regular expression `/health/`.

```js
module.exports = {
petstore: {
input: {
filters: {
tags: ['pets', /health/],
},
},
},
};
```

#### schemas

Type: Array of `string` or `RegExp`.

For instance the example below only generates the endpoints that contain the tag `pets`.
Only schemas names match the specified `string` or `RegExp` will be automatically generated.
For instance the example below only generates the `schema` object that matches string `Error` or regular expression `/Cat/`.

```js
module.exports = {
petstore: {
input: {
filters: {
tags: ['pets'],
schemas: ['Error', /Cat/],
},
},
},
Expand Down
Loading

0 comments on commit 21060a1

Please sign in to comment.