Skip to content

Commit 04f8c7c

Browse files
authored
Merge pull request #8 from dev-five-git/multi-openapi
Support multi openapi
2 parents cc1bbea + 97b5c13 commit 04f8c7c

File tree

29 files changed

+2194
-1228
lines changed

29 files changed

+2194
-1228
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}

examples/next/app/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import { Box, Text } from '@devup-ui/react'
55
import { useEffect } from 'react'
66

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

910
export default function Home() {
1011
useEffect(() => {
12+
api2.get('getUsers2', {}).then((res) => {
13+
console.log(res)
14+
})
1115
api.get('getUsers', {}).then((res) => {
1216
console.log(res)
1317
})

examples/next/next.config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import devupApi from '@devup-api/next-plugin'
22
import { DevupUI } from '@devup-ui/next-plugin'
33

4-
const config = devupApi({
5-
reactStrictMode: true,
6-
})
4+
const config = devupApi(
5+
{
6+
reactStrictMode: true,
7+
},
8+
{
9+
openapiFiles: ['./openapi.json', './openapi2.json'],
10+
},
11+
)
712

813
export default DevupUI(config)

examples/next/openapi2.json

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Example API",
5+
"version": "1.0.0",
6+
"description": "Example OpenAPI specification for testing devup-api"
7+
},
8+
"paths": {
9+
"/users": {
10+
"get": {
11+
"summary": "Get all users",
12+
"operationId": "getUsers2",
13+
"responses": {
14+
"200": {
15+
"description": "List of users",
16+
"content": {
17+
"application/json": {
18+
"schema": {
19+
"type": "array",
20+
"items": {
21+
"$ref": "#/components/schemas/User"
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"post": {
30+
"summary": "Create a new user",
31+
"operationId": "createUser2",
32+
"requestBody": {
33+
"required": true,
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"$ref": "#/components/schemas/CreateUserRequest"
38+
}
39+
}
40+
}
41+
},
42+
"responses": {
43+
"201": {
44+
"description": "User created",
45+
"content": {
46+
"application/json": {
47+
"schema": {
48+
"$ref": "#/components/schemas/User"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
},
56+
"/users/{id}": {
57+
"get": {
58+
"summary": "Get user by ID",
59+
"operationId": "getUserById2",
60+
"parameters": [
61+
{
62+
"name": "id",
63+
"in": "path",
64+
"required": true,
65+
"schema": {
66+
"type": "integer"
67+
}
68+
}
69+
],
70+
"responses": {
71+
"200": {
72+
"description": "User details",
73+
"content": {
74+
"application/json": {
75+
"schema": {
76+
"$ref": "#/components/schemas/User"
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
84+
},
85+
"components": {
86+
"schemas": {
87+
"User": {
88+
"type": "object",
89+
"properties": {
90+
"id": {
91+
"type": "integer"
92+
},
93+
"name": {
94+
"type": "string"
95+
},
96+
"email": {
97+
"type": "string",
98+
"format": "email"
99+
},
100+
"createdAt": {
101+
"type": "string",
102+
"format": "date-time"
103+
}
104+
},
105+
"required": ["id", "name", "email"]
106+
},
107+
"CreateUserRequest": {
108+
"type": "object",
109+
"properties": {
110+
"name": {
111+
"type": "string"
112+
},
113+
"email": {
114+
"type": "string",
115+
"format": "email"
116+
}
117+
},
118+
"required": ["name", "email"]
119+
}
120+
}
121+
}
122+
}

packages/core/src/additional.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type Additional<
22
T extends string,
33
Target extends object,
4-
> = T extends keyof Target ? Target[T] : object
4+
> = T extends keyof Target ? Target[T] & object : object
55

66
export type RequiredOptions<T extends object> = keyof T extends undefined
77
? never

packages/core/src/api-struct.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { Conditional } from './utils'
1+
import type { ConditionalKeys, ConditionalScope } from './utils'
2+
3+
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
4+
export interface DevupApiServers {}
25

36
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
47
export interface DevupGetApiStruct {}
@@ -27,10 +30,22 @@ export type DevupApiStruct = DevupGetApiStruct &
2730
DevupDeleteApiStruct &
2831
DevupPatchApiStruct
2932

30-
export type DevupGetApiStructKey = Conditional<DevupGetApiStruct>
31-
export type DevupPostApiStructKey = Conditional<DevupPostApiStruct>
32-
export type DevupPutApiStructKey = Conditional<DevupPutApiStruct>
33-
export type DevupDeleteApiStructKey = Conditional<DevupDeleteApiStruct>
34-
export type DevupPatchApiStructKey = Conditional<DevupPatchApiStruct>
35-
36-
export type DevupApiStructKey = Conditional<DevupApiStruct>
33+
export type DevupGetApiStructKey<O extends string> = ConditionalKeys<
34+
ConditionalScope<DevupGetApiStruct, O>
35+
>
36+
export type DevupPostApiStructKey<O extends string> = ConditionalKeys<
37+
ConditionalScope<DevupPostApiStruct, O>
38+
>
39+
export type DevupPutApiStructKey<O extends string> = ConditionalKeys<
40+
ConditionalScope<DevupPutApiStruct, O>
41+
>
42+
export type DevupDeleteApiStructKey<O extends string> = ConditionalKeys<
43+
ConditionalScope<DevupDeleteApiStruct, O>
44+
>
45+
export type DevupPatchApiStructKey<O extends string> = ConditionalKeys<
46+
ConditionalScope<DevupPatchApiStruct, O>
47+
>
48+
49+
export type DevupApiStructKey<O extends string> = ConditionalKeys<
50+
ConditionalScope<DevupApiStruct, O>
51+
>

packages/core/src/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export interface DevupApiOptions extends DevupApiTypeGeneratorOptions {
2727
* OpenAPI file path
2828
* @default {'openapi.json'}
2929
*/
30-
openapiFile?: string
30+
openapiFiles?: string[] | string
3131
}

packages/core/src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export type Conditional<T> = keyof T extends undefined ? string : keyof T
1+
export type ConditionalKeys<T, F = string> = keyof T extends undefined
2+
? F
3+
: keyof T & string
4+
export type ConditionalScope<T, K extends string> = K extends keyof T
5+
? T[K]
6+
: object

0 commit comments

Comments
 (0)