generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use of
useOperationHelpers
to abstract operation logic
- Loading branch information
1 parent
607ccbc
commit fb25317
Showing
22 changed files
with
130 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kubb/swagger-zod": patch | ||
--- | ||
|
||
use of `useOperationHelpers` to abstract operation logic |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { useOas } from './useOas.ts' | ||
export { useOperation, useOperationFile, useOperationName } from './useOperation.ts' | ||
export { useOperationHelpers } from './useOperationHelpers.ts' | ||
export { useOperations } from './useOperations.ts' | ||
export { useGetSchemas, useSchemas } from './useSchemas.ts' | ||
export { useSchemas } from './useSchemas.ts' |
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,50 @@ | ||
import { usePluginManager } from '@kubb/react' | ||
|
||
import type { KubbFile, Plugin, ResolveNameParams } from '@kubb/core' | ||
import type { Operation as OperationType } from '../oas/index.ts' | ||
|
||
type FileMeta = KubbFile.FileMetaBase & { | ||
pluginKey: Plugin['key'] | ||
name: string | ||
tag?: string | ||
} | ||
|
||
type UseOperationHelpersProps = { | ||
operation: OperationType | ||
} | ||
|
||
type UseOperationHelpersResult = { | ||
getOperationName: (params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string | ||
getOperationFile: (params: { pluginKey: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta> | ||
} | ||
|
||
export function useOperationHelpers({ operation }: UseOperationHelpersProps): UseOperationHelpersResult { | ||
const pluginManager = usePluginManager() | ||
|
||
const getOperationName: UseOperationHelpersResult['getOperationName'] = ({ pluginKey, type }) => { | ||
return pluginManager.resolveName({ name: operation.getOperationId(), pluginKey, type }) | ||
} | ||
|
||
const getOperationFile: UseOperationHelpersResult['getOperationFile'] = ({ pluginKey, extName = '.ts' }) => { | ||
// needed for the `output.group` | ||
const tag = operation?.getTags().at(0)?.name | ||
const name = getOperationName({ type: 'file', pluginKey }) | ||
|
||
const file = pluginManager.getFile({ name, extName, pluginKey, options: { type: 'file', pluginKey, tag } }) | ||
|
||
return { | ||
...file, | ||
meta: { | ||
...file.meta, | ||
name, | ||
pluginKey, | ||
tag, | ||
}, | ||
} | ||
} | ||
|
||
return { | ||
getOperationName, | ||
getOperationFile, | ||
} | ||
} |
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