Skip to content

Commit d5f4a0b

Browse files
authored
Merge branch 'reduxjs:master' into task/remove-all-settled
2 parents 7b68805 + cf24419 commit d5f4a0b

File tree

10 files changed

+95
-13
lines changed

10 files changed

+95
-13
lines changed

docs/api/createSlice.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ Result's function `getInitialState` provides access to the initial state value g
233233
## Examples
234234

235235
```ts
236-
import { createSlice, createAction } from '@reduxjs/toolkit'
236+
import { createSlice, createAction, configureStore } from '@reduxjs/toolkit'
237237
import type { PayloadAction } from '@reduxjs/toolkit'
238-
import { createStore, combineReducers } from 'redux'
238+
import { combineReducers } from 'redux'
239239
240240
const incrementBy = createAction<number>('incrementBy')
241241
const decrementBy = createAction<number>('decrementBy')
@@ -282,13 +282,13 @@ const user = createSlice({
282282
},
283283
})
284284
285-
const reducer = combineReducers({
286-
counter: counter.reducer,
287-
user: user.reducer,
285+
const store = configureStore({
286+
reducer: {
287+
counter: counter.reducer,
288+
user: user.reducer,
289+
},
288290
})
289291
290-
const store = createStore(reducer)
291-
292292
store.dispatch(counter.actions.increment())
293293
// -> { counter: 1, user: {name : '', age: 21} }
294294
store.dispatch(counter.actions.increment())

docs/rtk-query/overview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ RTK Query is **an optional addon included in the Redux Toolkit package**, and it
2626

2727
To learn how to use RTK Query, see the full ["Redux Essentials" tutorial](https://redux.js.org/tutorials/essentials/part-7-rtk-query-basics) on the Redux core docs site.
2828

29+
If you prefer a video course, you can [watch this RTK Query video course by Lenz Weber-Tronic, the creator of RTK Query, for free at Egghead](https://egghead.io/courses/rtk-query-basics-query-endpoints-data-flow-and-typescript-57ea3c43?af=7pnhj6) or take a look at the first lesson right here:
30+
31+
<div style={{position:"relative",paddingTop:"56.25%"}}>
32+
<iframe
33+
src="https://app.egghead.io/lessons/redux-course-introduction-and-application-walk-through-for-rtk-query-basics/embed?af=7pnhj6"
34+
title="RTK Query Video course at Egghead: Course Introduction and Application Walk through for RTK Query Basics"
35+
frameborder="0"
36+
allowfullscreen
37+
style={{position:"absolute",top:0,left:0,width:"100%",height:"100%"}}
38+
></iframe>
39+
</div>
40+
2941
:::
3042

3143
## Motivation
@@ -160,7 +172,7 @@ export default function App() {
160172
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur')
161173
// Individual hooks are also accessible under the generated endpoints:
162174
// const { data, error, isLoading } = pokemonApi.endpoints.getPokemonByName.useQuery('bulbasaur')
163-
175+
164176
// render UI based on data and loading state
165177
}
166178
```

docs/tutorials/overview.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ The RTK [**Usage Guide** docs page](../usage/usage-guide.md) explains the standa
6262

6363
The [Redux Essentials tutorial](https://redux.js.org/tutorials/essentials/part-1-overview-concepts) also shows how to use each of the APIs while building an application.
6464

65+
## RTK Query Video Course
66+
67+
If you prefer a video course, you can [watch this RTK Query video course by Lenz Weber-Tronic, the creator of RTK Query, for free at Egghead](https://egghead.io/courses/rtk-query-basics-query-endpoints-data-flow-and-typescript-57ea3c43?af=7pnhj6) or take a look at the first lesson right here:
68+
69+
<div style={{position:"relative",paddingTop:"56.25%"}}>
70+
<iframe
71+
src="https://app.egghead.io/lessons/redux-course-introduction-and-application-walk-through-for-rtk-query-basics/embed?af=7pnhj6"
72+
title="RTK Query Video course at Egghead: Course Introduction and Application Walk through for RTK Query Basics"
73+
frameborder="0"
74+
allowfullscreen
75+
style={{position:"absolute",top:0,left:0,width:"100%",height:"100%"}}
76+
></iframe>
77+
</div>
78+
6579
## Migrating Vanilla Redux to Redux Toolkit
6680

6781
If you already know Redux and just want to know how to migrate an existing application to use Redux Toolkit, the [**"Modern Redux with Redux Toolkit" page in the Redux Fundamentals tutorial**](https://redux.js.org/tutorials/fundamentals/part-8-modern-redux) shows how RTK's APIs simplify Redux usage patterns and how to handle that migration.

packages/rtk-query-codegen-openapi/ChangeLog.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ All notable changes to the `RTK Query - Code Generator` for `Open API` project w
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## 1.1.3 - 10-11-2023
7+
## 1.2.0 - 2023-11-09
8+
9+
This version adds a new `mergeReadWriteOnly` configuration option (default to `false`) that, when set to `true` will not generate separate types for read-only and write-only properties.
10+
11+
## 1.1.3 - 2023-10-11
812

913
### Added
1014
- Adds a temporary workaround for [4.9.0 and 4.10.0 generate circular types oazapfts/oazapfts#491](https://github.com/oazapfts/oazapfts/issues/491)
1115

12-
## 1.1.2 - 10-11-2023
16+
## 1.1.2 - 2023-10-11
1317

1418
### Added
1519
- Support for Read Only Properties in the Open API spec. Previously, this property was ignored.
1620
- Now if the readOnly property is present and set to `true` in a schema, it will split the type into two types: one with the read only property suffixed as 'Read' and the other without the read only properties, using the same type name as before.
1721
- This may cause issues if you had your OpenAPI spec properly typed/configured, as it will remove the read onyl types from your existing type. You will need to switch to the new type suffixed as 'Read' to avoid missing property names.
1822

19-
## 1.1.1 - 10-11-2023
23+
## 1.1.1 - 2023-10-11
2024

2125
### Changed
2226
- Codegen: better handling of duplicate param names ([Codegen: better handling of duplicate param names #3780](https://github.com/reduxjs/redux-toolkit/pull/3780))
2327
- If a parameter name is both used in a query and a parameter, it will be prefixed with `query`/`param` now to avoid conflicts
2428

25-
## 1.1.0 - 10-11-2023
29+
## 1.1.0 - 2023-10-11
2630

2731
### Added
2832
- Option of generating real TS enums instead of string unions [Adds the option of generating real TS enums instead of string unions #2854](https://github.com/reduxjs/redux-toolkit/pull/2854)

packages/rtk-query-codegen-openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rtk-query/codegen-openapi",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"main": "lib/index.js",
55
"types": "lib/index.d.ts",
66
"author": "Lenz Weber",

packages/rtk-query-codegen-openapi/src/generate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ export async function generateApi(
9494
unionUndefined,
9595
flattenArg = false,
9696
useEnumType = false,
97+
mergeReadWriteOnly = false,
9798
}: GenerationOptions
9899
) {
99100
const v3Doc = await getV3Doc(spec);
100101

101102
const apiGen = new ApiGenerator(v3Doc, {
102103
unionUndefined,
103104
useEnumType,
105+
mergeReadWriteOnly,
104106
});
105107

106108
// temporary workaround for https://github.com/oazapfts/oazapfts/issues/491

packages/rtk-query-codegen-openapi/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export interface CommonOptions {
6767
* `true` will "flatten" the arg so that you can do things like `useGetEntityById(1)` instead of `useGetEntityById({ entityId: 1 })`
6868
*/
6969
flattenArg?: boolean;
70+
/**
71+
* default to false
72+
* `true` will not generate separate types for read-only and write-only properties.
73+
*/
74+
mergeReadWriteOnly?: boolean;
7075
}
7176

7277
export type TextMatcher = string | RegExp | (string | RegExp)[];

packages/rtk-query-codegen-openapi/test/__snapshots__/generateEndpoints.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,38 @@ export const { useAddPetMutation, useGetPetByIdQuery } = injectedRtkApi;
491491

492492
`;
493493

494+
exports[`openapi spec readOnly / writeOnly are merged 1`] = `
495+
import { api } from './fixtures/emptyApi';
496+
const injectedRtkApi = api.injectEndpoints({
497+
endpoints: (build) => ({
498+
getExample: build.query<GetExampleApiResponse, GetExampleApiArg>({
499+
query: () => ({ url: \`/example\` }),
500+
}),
501+
setExample: build.mutation<SetExampleApiResponse, SetExampleApiArg>({
502+
query: (queryArg) => ({
503+
url: \`/example\`,
504+
method: 'POST',
505+
body: queryArg.exampleSchema,
506+
}),
507+
}),
508+
}),
509+
overrideExisting: false,
510+
});
511+
export { injectedRtkApi as enhancedApi };
512+
export type GetExampleApiResponse = /** status 200 OK */ ExampleSchema;
513+
export type GetExampleApiArg = void;
514+
export type SetExampleApiResponse = /** status 200 OK */ ExampleSchema;
515+
export type SetExampleApiArg = {
516+
exampleSchema: ExampleSchema;
517+
};
518+
export type ExampleSchema = {
519+
always_present: string;
520+
read_only_prop: string;
521+
write_only_prop: string;
522+
};
523+
524+
`;
525+
494526
exports[`openapi spec readOnly / writeOnly are respected 1`] = `
495527
import { api } from './fixtures/emptyApi';
496528
const injectedRtkApi = api.injectEndpoints({

packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,15 @@ describe('openapi spec', () => {
372372
expect(api).toMatchSnapshot();
373373
});
374374
});
375+
376+
describe('openapi spec', () => {
377+
it('readOnly / writeOnly are merged', async () => {
378+
const api = await generateEndpoints({
379+
unionUndefined: true,
380+
schemaFile: './fixtures/readOnlyWriteOnly.yaml',
381+
apiFile: './fixtures/emptyApi.ts',
382+
mergeReadWriteOnly: true
383+
});
384+
expect(api).toMatchSnapshot();
385+
});
386+
});

packages/toolkit/src/query/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type {
1616
export type {
1717
EndpointDefinitions,
1818
EndpointDefinition,
19+
EndpointBuilder,
1920
QueryDefinition,
2021
MutationDefinition,
2122
TagDescription,

0 commit comments

Comments
 (0)