UNPKG

@furystack/rest-service

Version:

Repository implementation for FuryStack

55 lines 1.95 kB
export const defaultSchema = { definitions: { default: { type: 'object', properties: { headers: { type: 'object', additionalProperties: true, }, query: { type: 'object', additionalProperties: true, }, body: { type: 'object', additionalProperties: true, }, url: { type: 'object', additionalProperties: true, }, }, required: [], description: 'Default schema for API endpoints', additionalProperties: true, }, }, }; const defaultSchemaName = 'default'; const getDefinitionFromAction = (method, path, action) => { return { method, path, schema: 'schema' in action && typeof action.schema === 'object' ? action.schema : defaultSchema, schemaName: 'schemaName' in action && typeof action.schemaName === 'string' ? action.schemaName : defaultSchemaName, isAuthenticated: 'isAuthenticated' in action && typeof action.isAuthenticated === 'boolean' ? action.isAuthenticated : false, }; }; export const getSchemaFromApi = ({ api, name = 'FuryStack API', description = 'API documentation generated from FuryStack API schema', version = '1.0.0', }) => { const endpoints = {}; Object.entries(api).forEach(([method, endpointList]) => { Object.entries(endpointList).forEach(([url, requestAction]) => { if (method && url && requestAction) { endpoints[url] = getDefinitionFromAction(method, url, requestAction); } }); }); return { name, description, version, endpoints, }; }; //# sourceMappingURL=get-schema-from-api.js.map