mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 09:03:53 +00:00
feat: specify the api's auth type (#2715)
This commit is contained in:
@@ -29,10 +29,16 @@ type OpenAPIResponse = {
|
||||
};
|
||||
};
|
||||
|
||||
type OpenAPISecurity = {
|
||||
apiKey?: string[];
|
||||
token?: string[];
|
||||
};
|
||||
|
||||
type PathType = {
|
||||
[method: string]: {
|
||||
description: string;
|
||||
parameters: OpenAPIParameter[];
|
||||
security?: OpenAPISecurity[];
|
||||
responses: OpenAPIResponse;
|
||||
};
|
||||
};
|
||||
@@ -52,6 +58,22 @@ type OpenApiType = {
|
||||
servers?: {
|
||||
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 {
|
||||
@@ -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 = (() => {
|
||||
if (api.response) {
|
||||
if (Array.isArray(api.response)) {
|
||||
@@ -159,6 +192,7 @@ export function convertPath(api: ApiType): PathType {
|
||||
return {
|
||||
[method]: {
|
||||
description: api.description ?? '',
|
||||
security,
|
||||
parameters,
|
||||
responses
|
||||
}
|
||||
|
Reference in New Issue
Block a user