mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
945 B
TypeScript
39 lines
945 B
TypeScript
import _ from 'lodash';
|
|
import type { TcService } from 'tailchat-server-sdk';
|
|
import type { PathsObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
|
|
export function generateOpenapiPath(service: TcService): PathsObject {
|
|
const serviceName = service.serviceName;
|
|
const actions = service.getActionList();
|
|
|
|
const paths: PathsObject = {};
|
|
|
|
for (const action of actions) {
|
|
const pathName = '/' + serviceName + '/' + action.name;
|
|
paths[pathName] = {
|
|
post: {
|
|
requestBody: {
|
|
content: {
|
|
'application/json': {
|
|
schema: {
|
|
type: 'object',
|
|
properties: generateRequestBodyProperties(action.params),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
return paths;
|
|
}
|
|
|
|
function generateRequestBodyProperties(params: {
|
|
[x: string]: any;
|
|
}): Record<string, SchemaObject> {
|
|
return _.mapValues(params, (type) => {
|
|
return type;
|
|
});
|
|
}
|