Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Mar 9, 2024
1 parent 412325a commit 607ccbc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/swagger/src/components/Oas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import type { KubbNode } from '@kubb/react'
import type { Oas as OasType, Operation as OperationType } from '../oas/index.ts'
import type { OperationSchemas } from '../types.ts'

export type GetSchemas = (operation: OperationType, statusCode?: string | number) => OperationSchemas

type Props = {
oas: OasType
operations: OperationType[]
getSchemas: (operation: OperationType, statusCode?: string | number) => OperationSchemas
getSchemas: GetSchemas
children?: KubbNode
}

type OasContextProps = {
oas?: OasType
operations?: OperationType[]
getSchemas?: (operation: OperationType, statusCode?: string | number) => OperationSchemas
getSchemas?: GetSchemas
}

const OasContext = createContext<OasContextProps>({})
Expand Down
2 changes: 1 addition & 1 deletion packages/swagger/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { useOas } from './useOas.ts'
export { useOperation, useOperationFile, useOperationName } from './useOperation.ts'
export { useOperations } from './useOperations.ts'
export { useSchemas } from './useSchemas.ts'
export { useGetSchemas, useSchemas } from './useSchemas.ts'
12 changes: 11 additions & 1 deletion packages/swagger/src/hooks/useSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from '@kubb/react'

import { Oas } from '../components/Oas.tsx'
import { Oas, type GetSchemas } from '../components/Oas.tsx'
import { Operation } from '../components/Operation.tsx'

import type { OperationSchemas } from '../types.ts'
Expand All @@ -22,3 +22,13 @@ export function useSchemas(): OperationSchemas {

return schemas
}

Check warning on line 24 in packages/swagger/src/hooks/useSchemas.ts

View check run for this annotation

Codecov / codecov/patch

packages/swagger/src/hooks/useSchemas.ts#L18-L24

Added lines #L18 - L24 were not covered by tests

export function useGetSchemas(): GetSchemas {
const { getSchemas } = useContext(Oas.Context)

if (!getSchemas) {
throw new Error(`getSchemas is not defined`)
}

Check warning on line 31 in packages/swagger/src/hooks/useSchemas.ts

View check run for this annotation

Codecov / codecov/patch

packages/swagger/src/hooks/useSchemas.ts#L27-L31

Added lines #L27 - L31 were not covered by tests

return getSchemas

Check warning on line 33 in packages/swagger/src/hooks/useSchemas.ts

View check run for this annotation

Codecov / codecov/patch

packages/swagger/src/hooks/useSchemas.ts#L33

Added line #L33 was not covered by tests
}

0 comments on commit 607ccbc

Please sign in to comment.