Skip to content

Commit 0db8995

Browse files
committed
make default backend optional
1 parent 062aec6 commit 0db8995

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# React OpenApi Hook
2+
Please find here an example of use: https://github.com/StefanoMarzo/react-openapi-generator-hook-demo

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-openapi-generator-hook",
3-
"version": "0.0.15",
3+
"version": "0.0.16",
44
"main": "dist/react-openapi-hook.umd.js",
55
"module": "dist/react-openapi-hook.es.js",
66
"types": "dist/index.d.ts",

src/hook/useApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Configuration } from '../../generated/configuration'
55

66
export function useApi<
77
ApiInstance,
8-
MethodName extends keyof ApiInstance &(string | number | symbol)
8+
MethodName extends keyof ApiInstance & (string | number | symbol)
99
>(
1010
apiParams: {
1111
apiFactory: (
@@ -44,7 +44,8 @@ export function useApi<
4444

4545
const { openApiConfigurationMap, defaultConfigurationId } = useOpenApiGenerator()
4646
const { axiosInstance, configuration, baseUrl } = openApiConfigurationMap[
47-
options?.configurationId ?? defaultConfigurationId]
47+
options?.configurationId ?? defaultConfigurationId ?? Object.keys(openApiConfigurationMap)[0]
48+
]
4849

4950
const apiInstance = useMemo(
5051
() => apiFactory(configuration, baseUrl, axiosInstance),

src/type/openApiConfigurationTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export interface OpenApiConfigurationType {
1111
export interface OpenApiProviderProps {
1212
readonly children: ReactNode
1313
readonly openApiConfigurationMap: Record<string, OpenApiConfigurationType>
14-
readonly defaultConfigurationId: string
14+
readonly defaultConfigurationId?: string
1515
}
1616

1717
export interface OpenApiProviderState {
1818
readonly openApiConfigurationMap: Record<string, OpenApiConfigurationType>
19-
readonly defaultConfigurationId: string
19+
readonly defaultConfigurationId?: string
2020
}

0 commit comments

Comments
 (0)