Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_yMP-pNQgQByUg37CiB6VA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"packages/vite-plugin/package.json":"Patch","packages/rsbuild-plugin/package.json":"Patch","packages/webpack-plugin/package.json":"Patch","packages/fetch/package.json":"Patch","packages/generator/package.json":"Patch","packages/core/package.json":"Patch","packages/utils/package.json":"Patch","packages/next-plugin/package.json":"Patch"},"note":"Support multi api","date":"2025-12-01T08:57:43.782132200Z"}
4 changes: 4 additions & 0 deletions examples/next/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { Box, Text } from '@devup-ui/react'
import { useEffect } from 'react'

const api = createApi('https://api.example.com')
const api2 = createApi('https://api.example2.com', undefined, 'openapi2.json')

export default function Home() {
useEffect(() => {
api2.get('getUsers2', {}).then((res) => {
console.log(res)
})
api.get('getUsers', {}).then((res) => {
console.log(res)
})
Expand Down
11 changes: 8 additions & 3 deletions examples/next/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import devupApi from '@devup-api/next-plugin'
import { DevupUI } from '@devup-ui/next-plugin'

const config = devupApi({
reactStrictMode: true,
})
const config = devupApi(
{
reactStrictMode: true,
},
{
openapiFiles: ['./openapi.json', './openapi2.json'],
},
)

export default DevupUI(config)
122 changes: 122 additions & 0 deletions examples/next/openapi2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"openapi": "3.0.0",
"info": {
"title": "Example API",
"version": "1.0.0",
"description": "Example OpenAPI specification for testing devup-api"
},
"paths": {
"/users": {
"get": {
"summary": "Get all users",
"operationId": "getUsers2",
"responses": {
"200": {
"description": "List of users",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
},
"post": {
"summary": "Create a new user",
"operationId": "createUser2",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateUserRequest"
}
}
}
},
"responses": {
"201": {
"description": "User created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
},
"/users/{id}": {
"get": {
"summary": "Get user by ID",
"operationId": "getUserById2",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
}
],
"responses": {
"200": {
"description": "User details",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"createdAt": {
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name", "email"]
},
"CreateUserRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
}
},
"required": ["name", "email"]
}
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/additional.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Additional<
T extends string,
Target extends object,
> = T extends keyof Target ? Target[T] : object
> = T extends keyof Target ? Target[T] & object : object

export type RequiredOptions<T extends object> = keyof T extends undefined
? never
Expand Down
31 changes: 23 additions & 8 deletions packages/core/src/api-struct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Conditional } from './utils'
import type { ConditionalKeys, ConditionalScope } from './utils'

// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupApiServers {}

// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupGetApiStruct {}
Expand Down Expand Up @@ -27,10 +30,22 @@ export type DevupApiStruct = DevupGetApiStruct &
DevupDeleteApiStruct &
DevupPatchApiStruct

export type DevupGetApiStructKey = Conditional<DevupGetApiStruct>
export type DevupPostApiStructKey = Conditional<DevupPostApiStruct>
export type DevupPutApiStructKey = Conditional<DevupPutApiStruct>
export type DevupDeleteApiStructKey = Conditional<DevupDeleteApiStruct>
export type DevupPatchApiStructKey = Conditional<DevupPatchApiStruct>

export type DevupApiStructKey = Conditional<DevupApiStruct>
export type DevupGetApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupGetApiStruct, O>
>
export type DevupPostApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupPostApiStruct, O>
>
export type DevupPutApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupPutApiStruct, O>
>
export type DevupDeleteApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupDeleteApiStruct, O>
>
export type DevupPatchApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupPatchApiStruct, O>
>

export type DevupApiStructKey<O extends string> = ConditionalKeys<
ConditionalScope<DevupApiStruct, O>
>
2 changes: 1 addition & 1 deletion packages/core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export interface DevupApiOptions extends DevupApiTypeGeneratorOptions {
* OpenAPI file path
* @default {'openapi.json'}
*/
openapiFile?: string
openapiFiles?: string[] | string
}
7 changes: 6 additions & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export type Conditional<T> = keyof T extends undefined ? string : keyof T
export type ConditionalKeys<T, F = string> = keyof T extends undefined
? F
: keyof T & string
export type ConditionalScope<T, K extends string> = K extends keyof T
? T[K]
: object
Loading