Skip to content

Commit

Permalink
fix: support for react 19
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Dec 14, 2024
1 parent 12f4206 commit 082e6d3
Show file tree
Hide file tree
Showing 22 changed files with 1,815 additions and 2,362 deletions.
6 changes: 3 additions & 3 deletions packages/plugin-client/src/clients/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Subset of AxiosRequestConfig
* Subset of FetchRequestConfig
*/
export type RequestConfig<TData = unknown> = {
baseURL?: string
Expand All @@ -12,7 +12,7 @@ export type RequestConfig<TData = unknown> = {
headers?: [string, string][] | Record<string, string>
}
/**
* Subset of AxiosResponse
* Subset of FetchResponse
*/
export type ResponseConfig<TData = unknown> = {
data: TData
Expand All @@ -22,7 +22,7 @@ export type ResponseConfig<TData = unknown> = {
}

export const fetchClient = async <TData, TError = unknown, TVariables = unknown>(config: RequestConfig<TVariables>): Promise<ResponseConfig<TData>> => {
const response = await fetch('https://example.org/post', {
const response = await fetch(`${config.baseURL}${config.url}`, {
method: config.method.toUpperCase(),
body: JSON.stringify(config.data),
signal: config.signal,
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-client/src/components/Client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type Operation, isOptional } from '@kubb/oas'
import type { OperationSchemas } from '@kubb/plugin-oas'
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
import { File, Function, FunctionParams } from '@kubb/react'
import type { KubbNode } from '@kubb/react/types'
import type { PluginClient } from '../types.ts'

type Props = {
Expand Down Expand Up @@ -113,7 +112,7 @@ export function Client({
paramsCasing,
pathParamsType,
operation,
}: Props): KubbNode {
}: Props) {
const path = new URLPath(operation.path, { casing: paramsCasing })
const contentType = operation.getContentType()
const isFormData = contentType === 'multipart/form-data'
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-faker/src/components/Faker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Props = {
canOverride: boolean
}

export function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props): KubbNode {
export function Faker({ tree, description, name, typeName, seed, regexGenerator, canOverride, mapper, dateParser }: Props) {
const fakerText = parserFaker.joinItems(
tree
.map((schema, _index, siblings) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-msw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-oas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-oas/src/components/Oas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OasContextProps = {

const OasContext = createContext<OasContextProps>({})

export function Oas({ oas, children, operations, generator }: Props): KubbNode {
export function Oas({ oas, children, operations, generator }: Props) {
return <OasContext.Provider value={{ oas, generator, operations }}>{children}</OasContext.Provider>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-oas/src/components/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OperationContextProps = {

const OperationContext = createContext<OperationContextProps>({})

export function Operation({ operation, children }: Props): KubbNode {
export function Operation({ operation, children }: Props) {
return <OperationContext.Provider value={{ operation }}>{children}</OperationContext.Provider>
}

Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-oas/src/components/Schema.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from '@kubb/react'

import type { SchemaObject } from '@kubb/oas'
import type { KubbNode } from '@kubb/react/types'
import type { Key, KubbNode } from '@kubb/react/types'
import type { Schema as SchemaType } from '../SchemaMapper.ts'

export type SchemaContextProps = {
Expand All @@ -11,6 +11,7 @@ export type SchemaContextProps = {
}

type Props = {
key?: Key
name: string
value?: SchemaObject
tree?: Array<SchemaType>
Expand All @@ -22,7 +23,7 @@ const SchemaContext = createContext<SchemaContextProps>({
tree: [],
})

export function Schema({ name, value, tree = [], children }: Props): KubbNode {
export function Schema({ name, value, tree = [], children }: Props) {
return <SchemaContext.Provider value={{ name, schema: value, tree }}>{children}</SchemaContext.Provider>
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-redoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@
"@kubb/plugin-oas": "workspace:*",
"handlebars": "^4.7.8",
"mobx": "^6.13.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "catalog:",
"react-dom": "catalog:",
"redoc": "^2.2.0",
"styled-components": "^6.1.13"
},
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"@types/react-dom": "^18.3.5",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-redoc/src/redoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import fs from 'node:fs'
import path from 'node:path'
import type { OasTypes } from '@kubb/oas'
import pkg from 'handlebars'
import React from 'react'
import { renderToString } from 'react-dom/server'
import { ServerStyleSheet } from 'styled-components'
import redoc from 'redoc'
import { ServerStyleSheet } from 'styled-components'

type BuildDocsOptions = {
title?: string
Expand Down Expand Up @@ -40,7 +41,9 @@ export async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoo
error(...args)
}

const html = renderToString(sheet.collectStyles(<Redoc store={store} />))
const App = Redoc as any

const html = renderToString(sheet.collectStyles(<App store={store} />))
const state = await store.toJS()
const css = sheet.getStyleTags()

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-solid-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-svelte-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ts/src/components/OasType.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { File, Type } from '@kubb/react'

import type { OasTypes } from '@kubb/oas'
import type { ReactNode } from 'react'
import type { KubbNode } from '@kubb/react/types'

type Props = {
/**
Expand All @@ -12,7 +12,7 @@ type Props = {
api: OasTypes.OASDocument
}

export function OasType({ name, typeName, api }: Props): ReactNode {
export function OasType({ name, typeName, api }: Props) {
return (
<>
<File.Source name={name} isExportable isIndexable>
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ts/src/components/Type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export function Type({ name, typedName, tree, keysToOmit, optionalType, syntaxTy
return (
<Fragment>
{enums.map(({ name, nameNode, typeName, typeNode }, index) => (
<Fragment key={[name, nameNode].join('-')}>
// biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
<Fragment>
{nameNode && (
<File.Source name={name} isExportable isIndexable>
{print([nameNode])}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vue-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"devDependencies": {
"@kubb/config-ts": "workspace:*",
"@kubb/config-tsup": "workspace:*",
"@types/react": "^18.3.16",
"react": "^18.3.1",
"@types/react": "catalog:",
"react": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-zod/src/components/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
operations: Array<{ operation: Operation; data: SchemaNames }>
}

export function Operations({ name, operations }: Props): KubbNode {
export function Operations({ name, operations }: Props) {
const operationsJSON = operations.reduce(
(prev, acc) => {
prev[`"${acc.operation.getOperationId()}"`] = acc.data
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-zod/src/components/Zod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Props = {
keysToOmit?: string[]
}

export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props): KubbNode {
export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props) {
const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple))

const output = parserZod
Expand Down
Loading

0 comments on commit 082e6d3

Please sign in to comment.