Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
1ebc95a2
authored
Sep 15, 2024
by
Finley Ge
Committed by
GitHub
Sep 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: specify the api's auth type (#2715)
parent
d0e8f720
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
1 deletions
+55
-1
projects/app/public/openapi/index.html
+0
-0
scripts/openapi/index.ts
+17
-1
scripts/openapi/openapi.ts
+34
-0
scripts/openapi/type.d.ts
+1
-0
scripts/openapi/utils.ts
+3
-0
No files found.
projects/app/public/openapi/index.html
View file @
1ebc95a2
This source diff could not be displayed because it is too large. You can
view the blob
instead.
scripts/openapi/index.ts
View file @
1ebc95a2
...
@@ -4,7 +4,7 @@ import * as path from 'path';
...
@@ -4,7 +4,7 @@ import * as path from 'path';
import
{
convertOpenApi
}
from
'./openapi'
;
import
{
convertOpenApi
}
from
'./openapi'
;
const
rootPath
=
'projects/app/src/pages/api'
;
const
rootPath
=
'projects/app/src/pages/api'
;
const
exclude
=
[
'/admin'
,
'/proApi'
];
const
exclude
=
[
'/admin'
,
'/proApi'
,
'test.ts'
];
function
getAllFiles
(
dir
:
string
)
{
function
getAllFiles
(
dir
:
string
)
{
let
files
:
string
[]
=
[];
let
files
:
string
[]
=
[];
...
@@ -39,6 +39,22 @@ const openapi = convertOpenApi({
...
@@ -39,6 +39,22 @@ const openapi = convertOpenApi({
version
:
'1.0.0'
,
version
:
'1.0.0'
,
author
:
'FastGPT'
author
:
'FastGPT'
},
},
components
:
{
securitySchemes
:
{
apiKey
:
{
type
:
'apiKey'
,
name
:
'Authorization'
,
in
:
'header'
,
scheme
:
'bearer'
},
token
:
{
type
:
'apiKey'
,
in
:
'token'
,
name
:
'token'
,
scheme
:
'basic'
}
}
},
servers
:
[
servers
:
[
{
{
url
:
'http://localhost:4000'
url
:
'http://localhost:4000'
...
...
scripts/openapi/openapi.ts
View file @
1ebc95a2
...
@@ -29,10 +29,16 @@ type OpenAPIResponse = {
...
@@ -29,10 +29,16 @@ type OpenAPIResponse = {
};
};
};
};
type
OpenAPISecurity
=
{
apiKey
?:
string
[];
token
?:
string
[];
};
type
PathType
=
{
type
PathType
=
{
[
method
:
string
]:
{
[
method
:
string
]:
{
description
:
string
;
description
:
string
;
parameters
:
OpenAPIParameter
[];
parameters
:
OpenAPIParameter
[];
security
?:
OpenAPISecurity
[];
responses
:
OpenAPIResponse
;
responses
:
OpenAPIResponse
;
};
};
};
};
...
@@ -52,6 +58,22 @@ type OpenApiType = {
...
@@ -52,6 +58,22 @@ type OpenApiType = {
servers
?:
{
servers
?:
{
url
:
string
;
url
:
string
;
}[];
}[];
components
:
{
securitySchemes
:
{
apiKey
:
{
type
:
'apiKey'
;
name
:
'Authorization'
;
in
:
'header'
;
scheme
:
'bearer'
;
};
token
:
{
type
:
'apiKey'
;
in
:
'token'
;
name
:
'token'
;
scheme
:
'basic'
;
};
};
};
};
};
export
function
convertPath
(
api
:
ApiType
):
PathType
{
export
function
convertPath
(
api
:
ApiType
):
PathType
{
...
@@ -97,6 +119,17 @@ export function convertPath(api: ApiType): PathType {
...
@@ -97,6 +119,17 @@ export function convertPath(api: ApiType): PathType {
}
}
}
}
const
security
:
OpenAPISecurity
[]
=
[];
if
(
api
.
authorization
===
'apikey'
)
{
security
.
push
({
apiKey
:
[]
});
}
else
if
(
api
.
authorization
===
'token'
)
{
security
.
push
({
token
:
[]
});
}
const
responses
:
OpenAPIResponse
=
(()
=>
{
const
responses
:
OpenAPIResponse
=
(()
=>
{
if
(
api
.
response
)
{
if
(
api
.
response
)
{
if
(
Array
.
isArray
(
api
.
response
))
{
if
(
Array
.
isArray
(
api
.
response
))
{
...
@@ -159,6 +192,7 @@ export function convertPath(api: ApiType): PathType {
...
@@ -159,6 +192,7 @@ export function convertPath(api: ApiType): PathType {
return
{
return
{
[
method
]:
{
[
method
]:
{
description
:
api
.
description
??
''
,
description
:
api
.
description
??
''
,
security
,
parameters
,
parameters
,
responses
responses
}
}
...
...
scripts/openapi/type.d.ts
View file @
1ebc95a2
...
@@ -6,6 +6,7 @@ export type ApiMetaData = {
...
@@ -6,6 +6,7 @@ export type ApiMetaData = {
export
type
ApiType
=
{
export
type
ApiType
=
{
description
?:
string
;
description
?:
string
;
authorization
?:
'apikey'
|
'token'
;
path
:
string
;
path
:
string
;
url
:
string
;
url
:
string
;
query
?:
itemType
|
itemType
[];
query
?:
itemType
|
itemType
[];
...
...
scripts/openapi/utils.ts
View file @
1ebc95a2
...
@@ -213,7 +213,10 @@ function getMethod(api: ApiType): 'GET' | 'POST' {
...
@@ -213,7 +213,10 @@ function getMethod(api: ApiType): 'GET' | 'POST' {
export
function
parseAPI
({
path
,
rootPath
}:
{
path
:
string
;
rootPath
:
string
}):
ApiType
{
export
function
parseAPI
({
path
,
rootPath
}:
{
path
:
string
;
rootPath
:
string
}):
ApiType
{
const
code
=
fs
.
readFileSync
(
path
,
'utf-8'
);
const
code
=
fs
.
readFileSync
(
path
,
'utf-8'
);
const
authApiKey
=
code
.
includes
(
'authApiKey: true'
);
const
authToken
=
code
.
includes
(
'authToken: true'
);
const
api
=
parseCode
(
code
);
const
api
=
parseCode
(
code
);
api
.
authorization
=
authApiKey
?
'apikey'
:
authToken
?
'token'
:
undefined
;
api
.
url
=
path
.
replace
(
'.ts'
,
''
).
replace
(
rootPath
,
''
);
api
.
url
=
path
.
replace
(
'.ts'
,
''
).
replace
(
rootPath
,
''
);
api
.
path
=
path
;
api
.
path
=
path
;
if
(
api
.
method
===
undefined
)
{
if
(
api
.
method
===
undefined
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment