Skip to content

Commit 2204900

Browse files
authored
Merge pull request #2529 from hey-api/chore/pinia-colada-polish
chore: polish Pinia Colada plugin
2 parents 9038263 + ee11cca commit 2204900

File tree

240 files changed

+32271
-2062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+32271
-2062
lines changed

docs/openapi-ts/plugins/pinia-colada.md

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Queries are generated from [query operations](/openapi-ts/configuration/parser#h
5959
::: code-group
6060

6161
```ts [example]
62-
const { data, error } = useQuery({
62+
const query = useQuery({
6363
...getPetByIdQuery({
6464
path: {
6565
petId: 1,
@@ -86,19 +86,22 @@ export default {
8686

8787
You can customize the naming and casing pattern for `queryOptions` functions using the `.name` and `.case` options.
8888

89-
### Meta
89+
## Query Keys
9090

91-
You can use the `meta` field to attach arbitrary information to a query. To generate metadata for `queryOptions`, provide a function to the `.meta` option.
91+
Query keys contain normalized SDK function parameters and additional metadata.
9292

9393
::: code-group
9494

9595
```ts [example]
96-
queryOptions({
97-
// ...other fields
98-
meta: {
99-
id: 'getPetById',
96+
const queryKey = [
97+
{
98+
_id: 'getPetById',
99+
baseUrl: 'https://app.heyapi.dev',
100+
path: {
101+
petId: 1,
102+
},
100103
},
101-
});
104+
];
102105
```
103106

104107
```js [config]
@@ -109,30 +112,29 @@ export default {
109112
// ...other plugins
110113
{
111114
name: '@pinia/colada',
112-
queryOptions: {
113-
meta: (operation) => ({ id: operation.id }), // [!code ++]
114-
},
115+
queryKeys: true, // [!code ++]
115116
},
116117
],
117118
};
118119
```
119120

120121
:::
121122

122-
## Query Keys
123+
### Tags
123124

124-
Query keys contain normalized SDK function parameters and additional metadata.
125+
You can include operation tags in your query keys by setting `tags` to `true`. This will make query keys larger but provides better cache invalidation capabilities.
125126

126127
::: code-group
127128

128129
```ts [example]
129-
const queryKey = [
130+
const key = [
130131
{
131132
_id: 'getPetById',
132133
baseUrl: 'https://app.heyapi.dev',
133134
path: {
134135
petId: 1,
135136
},
137+
tags: ['pets', 'one', 'get'], // [!code ++]
136138
},
137139
];
138140
```
@@ -145,7 +147,9 @@ export default {
145147
// ...other plugins
146148
{
147149
name: '@pinia/colada',
148-
queryKeys: true, // [!code ++]
150+
queryKeys: {
151+
tags: true, // [!code ++]
152+
},
149153
},
150154
],
151155
};
@@ -155,12 +159,12 @@ export default {
155159

156160
### Accessing Query Keys
157161

158-
If you have access to the result of query options function, you can get the query key from the `queryKey` field.
162+
If you have access to the result of query options function, you can get the query key from the `key` field.
159163

160164
::: code-group
161165

162166
```ts [example]
163-
const { queryKey } = getPetByIdOptions({
167+
const { key } = getPetByIdQuery({
164168
path: {
165169
petId: 1,
166170
},
@@ -188,7 +192,7 @@ Alternatively, you can access the same query key by calling query key functions.
188192
::: code-group
189193

190194
```ts [example]
191-
const queryKey = getPetByIdQueryKey({
195+
const key = getPetByIdQueryKey({
192196
path: {
193197
petId: 1,
194198
},
@@ -213,6 +217,45 @@ export default {
213217

214218
You can customize the naming and casing pattern for `queryKeys` functions using the `.name` and `.case` options.
215219

220+
## Mutations
221+
222+
Mutations are generated from [mutation operations](/openapi-ts/configuration/parser#hooks-mutation-operations). The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`.
223+
224+
::: code-group
225+
226+
```ts [example]
227+
const addPet = useMutation({
228+
...addPetMutation(),
229+
onError: (error) => {
230+
console.log(error);
231+
},
232+
});
233+
234+
addPet.mutate({
235+
body: {
236+
name: 'Kitty',
237+
},
238+
});
239+
```
240+
241+
```js [config]
242+
export default {
243+
input: 'hey-api/backend', // sign up at app.heyapi.dev
244+
output: 'src/client',
245+
plugins: [
246+
// ...other plugins
247+
{
248+
name: '@pinia/colada',
249+
mutationOptions: true, // [!code ++]
250+
},
251+
],
252+
};
253+
```
254+
255+
:::
256+
257+
You can customize the naming and casing pattern for `mutationOptions` functions using the `.name` and `.case` options.
258+
216259
## API
217260

218261
You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@pinia/colada/types.d.ts) interface.

docs/openapi-ts/plugins/tanstack-query.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Queries are generated from [query operations](/openapi-ts/configuration/parser#h
109109
::: code-group
110110

111111
```ts [example]
112-
const { data, error } = useQuery({
112+
const query = useQuery({
113113
...getPetByIdOptions({
114114
path: {
115115
petId: 1,
@@ -307,7 +307,7 @@ Infinite queries are generated from [query operations](/openapi-ts/configuration
307307
::: code-group
308308

309309
```ts [example]
310-
const { data, error } = useInfiniteQuery({
310+
const query = useInfiniteQuery({
311311
...getFooInfiniteOptions({
312312
path: {
313313
fooId: 1,

docs/openapi-ts/plugins/valibot.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The Valibot plugin for Hey API generates schemas from your OpenAPI spec, fully c
2424
- Valibot v1 support
2525
- seamless integration with `@hey-api/openapi-ts` ecosystem
2626
- Valibot schemas for requests, responses, and reusable definitions
27+
- minimal learning curve thanks to extending the underlying technology
2728

2829
## Installation
2930

docs/openapi-ts/plugins/zod.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The Zod plugin for Hey API generates schemas from your OpenAPI spec, fully compa
2424
- Zod v4 support
2525
- seamless integration with `@hey-api/openapi-ts` ecosystem
2626
- Zod schemas for requests, responses, and reusable definitions
27+
- minimal learning curve thanks to extending the underlying technology
2728

2829
## Installation
2930

docs/openapi-ts/plugins/zod/mini.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The Zod plugin for Hey API generates schemas from your OpenAPI spec, fully compa
2424
- Zod Mini support
2525
- seamless integration with `@hey-api/openapi-ts` ecosystem
2626
- Zod schemas for requests, responses, and reusable definitions
27+
- minimal learning curve thanks to extending the underlying technology
2728

2829
## Installation
2930

docs/openapi-ts/plugins/zod/v3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The Zod plugin for Hey API generates schemas from your OpenAPI spec, fully compa
2424
- Zod v3 support
2525
- seamless integration with `@hey-api/openapi-ts` ecosystem
2626
- Zod schemas for requests, responses, and reusable definitions
27+
- minimal learning curve thanks to extending the underlying technology
2728

2829
## Installation
2930

packages/openapi-ts-tests/main/test/3.1.x.test.ts

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -822,151 +822,6 @@ describe(`OpenAPI ${version}`, () => {
822822
description:
823823
'generates validator schemas for all integer format combinations (number/integer/string types with int8, int16, int32, int64, uint8, uint16, uint32, uint64 formats)',
824824
},
825-
// TODO: add Pinia Colada snapshots
826-
// {
827-
// config: createConfig({
828-
// input: 'petstore.yaml',
829-
// output: 'plugins/@pinia/colada/default',
830-
// plugins: ['@pinia/colada'],
831-
// }),
832-
// description: 'generates Pinia Colada plugin code with default settings',
833-
// },
834-
// {
835-
// config: createConfig({
836-
// input: 'petstore.yaml',
837-
// output: 'plugins/@pinia/colada/operationOverrides',
838-
// plugins: [
839-
// {
840-
// name: '@pinia/colada',
841-
// operationTypes: {
842-
// addPet: 'query',
843-
// getPetById: 'both',
844-
// },
845-
// },
846-
// ],
847-
// }),
848-
// description:
849-
// 'generates Pinia Colada plugin code with operation type overrides',
850-
// },
851-
// {
852-
// config: createConfig({
853-
// input: 'petstore.yaml',
854-
// output: 'plugins/@pinia/colada/groupByTag',
855-
// plugins: [
856-
// {
857-
// groupByTag: true,
858-
// name: '@pinia/colada',
859-
// },
860-
// ],
861-
// }),
862-
// description: 'generates Pinia Colada plugin code grouped by OpenAPI tags',
863-
// },
864-
// {
865-
// config: createConfig({
866-
// input: 'petstore.yaml',
867-
// output: 'plugins/@pinia/colada/groupByTagWithIndex',
868-
// plugins: [
869-
// {
870-
// exportFromIndex: true,
871-
// groupByTag: true,
872-
// name: '@pinia/colada',
873-
// },
874-
// ],
875-
// }),
876-
// description:
877-
// 'generates Pinia Colada plugin code grouped by tags with index file',
878-
// },
879-
// {
880-
// config: createConfig({
881-
// input: 'petstore.yaml',
882-
// output: 'plugins/@pinia/colada/customNaming',
883-
// plugins: [
884-
// {
885-
// mutationOptions: {
886-
// name: '{{name}}MutationOptions',
887-
// },
888-
// name: '@pinia/colada',
889-
// queryOptions: {
890-
// name: '{{name}}QueryOptions',
891-
// },
892-
// },
893-
// ],
894-
// }),
895-
// description:
896-
// 'generates Pinia Colada plugin code with custom naming patterns',
897-
// },
898-
// {
899-
// config: createConfig({
900-
// input: 'petstore.yaml',
901-
// output: 'plugins/@pinia/colada/caseSettings',
902-
// plugins: [
903-
// {
904-
// case: 'PascalCase',
905-
// mutationOptions: {
906-
// case: 'snake_case',
907-
// },
908-
// name: '@pinia/colada',
909-
// queryOptions: {
910-
// case: 'camelCase',
911-
// },
912-
// },
913-
// ],
914-
// }),
915-
// description:
916-
// 'generates Pinia Colada plugin code with different case settings',
917-
// },
918-
// {
919-
// config: createConfig({
920-
// input: 'petstore.yaml',
921-
// output: 'plugins/@pinia/colada/disabledOptions',
922-
// plugins: [
923-
// {
924-
// mutationOptions: {
925-
// enabled: true,
926-
// },
927-
// name: '@pinia/colada',
928-
// queryOptions: false,
929-
// },
930-
// ],
931-
// }),
932-
// description: 'generates Pinia Colada plugin code with queries disabled',
933-
// },
934-
// {
935-
// config: createConfig({
936-
// input: 'petstore.yaml',
937-
// output: 'plugins/@pinia/colada/complexConfiguration',
938-
// plugins: [
939-
// {
940-
// exportFromIndex: true,
941-
// groupByTag: true,
942-
// mutationOptions: {
943-
// case: 'camelCase',
944-
// meta: (operation) => ({
945-
// method: operation.method,
946-
// operationId: operation.id,
947-
// }),
948-
// name: 'use{{name}}Mutation',
949-
// },
950-
// name: '@pinia/colada',
951-
// operationTypes: {
952-
// addPet: 'query',
953-
// getPetById: 'both',
954-
// updatePet: 'mutation',
955-
// },
956-
// queryOptions: {
957-
// case: 'camelCase',
958-
// meta: (operation) => ({
959-
// operationId: operation.id,
960-
// tags: operation.tags,
961-
// }),
962-
// name: 'use{{name}}Query',
963-
// },
964-
// },
965-
// ],
966-
// }),
967-
// description:
968-
// 'generates Pinia Colada plugin code with complex configuration combining all features',
969-
// },
970825
{
971826
config: createConfig({
972827
input: 'opencode.yaml',

0 commit comments

Comments
 (0)