From 05a5bc428eaf671af3964db4bb54735e9cbbe359 Mon Sep 17 00:00:00 2001 From: sinedied Date: Fri, 15 Sep 2023 15:27:25 +0200 Subject: [PATCH] feat(indexer): add openapi schema and ui (#35) --- packages/indexer/src/plugins/multipart.ts | 2 +- packages/indexer/src/plugins/schemas.ts | 60 -------------------- packages/indexer/src/routes/indexes/index.ts | 15 ++++- 3 files changed, 13 insertions(+), 64 deletions(-) delete mode 100644 packages/indexer/src/plugins/schemas.ts diff --git a/packages/indexer/src/plugins/multipart.ts b/packages/indexer/src/plugins/multipart.ts index b69402ce..e93093de 100644 --- a/packages/indexer/src/plugins/multipart.ts +++ b/packages/indexer/src/plugins/multipart.ts @@ -6,7 +6,7 @@ const FILE_UPLOAD_LIMIT = 20 * 1024 * 1024; // 20 MB export default fp(async (fastify) => { fastify.register(multipart, { attachFieldsToBody: true, - sharedSchemaId: '#multipartField', + sharedSchemaId: 'multipartField', limits: { fileSize: FILE_UPLOAD_LIMIT, files: 1, diff --git a/packages/indexer/src/plugins/schemas.ts b/packages/indexer/src/plugins/schemas.ts deleted file mode 100644 index 85f21952..00000000 --- a/packages/indexer/src/plugins/schemas.ts +++ /dev/null @@ -1,60 +0,0 @@ -import fp from 'fastify-plugin'; - -// export const chatRequestSchema = { -// $id: 'chatRequest', -// type: 'object', -// properties: { -// approach: { type: 'string' }, -// history: { -// type: 'array', -// items: { -// type: 'object', -// properties: { -// bot: { type: 'string' }, -// user: { type: 'string' }, -// }, -// }, -// }, -// overrides: { -// type: 'object', -// additionalProperties: { type: 'string' }, -// }, -// }, -// required: ['approach', 'history'], -// } as const; - -// export const askRequestSchema = { -// $id: 'askRequest', -// type: 'object', -// properties: { -// approach: { type: 'string' }, -// question: { type: 'string' }, -// overrides: { -// type: 'object', -// additionalProperties: { type: 'string' }, -// }, -// }, -// required: ['approach', 'question'], -// } as const; - -// export const approachResponseSchema = { -// $id: 'approachResponse', -// data_points: { -// type: 'array', -// items: { type: 'string' }, -// }, -// answer: { type: 'string' }, -// thoughts: { type: 'string' }, -// required: ['data_points', 'answer', 'thoughts'], -// additionalProperties: false, -// } as const; - -export const schemas = []; - -// export type SchemaTypes = [typeof chatRequestSchema, typeof askRequestSchema, typeof approachResponseSchema]; - -export default fp(async (fastify, _options): Promise => { - for (const schema of schemas) { - fastify.addSchema(schema); - } -}); diff --git a/packages/indexer/src/routes/indexes/index.ts b/packages/indexer/src/routes/indexes/index.ts index 9471ea3b..ef444d1c 100644 --- a/packages/indexer/src/routes/indexes/index.ts +++ b/packages/indexer/src/routes/indexes/index.ts @@ -10,6 +10,8 @@ export interface IndexFileOptionsField { const root: FastifyPluginAsyncJsonSchemaToTs = async (fastify, _options): Promise => { fastify.post('/', { schema: { + description: 'Create a new search index', + tags: ['indexes'], body: { type: 'object', properties: { @@ -43,6 +45,8 @@ const root: FastifyPluginAsyncJsonSchemaToTs = async (fastify, _options): Promis fastify.delete('/:name', { schema: { + description: 'Delete a search index', + tags: ['indexes'], params: { type: 'object', properties: { @@ -75,7 +79,9 @@ const root: FastifyPluginAsyncJsonSchemaToTs = async (fastify, _options): Promis fastify.post('/:name/files', { schema: { - // consumes: ['multipart/form-data'], + description: 'Upload a file for indexing', + tags: ['indexes'], + consumes: ['multipart/form-data'], params: { type: 'object', properties: { @@ -88,8 +94,9 @@ const root: FastifyPluginAsyncJsonSchemaToTs = async (fastify, _options): Promis body: { type: 'object', properties: { - options: { $ref: '#multipartField' }, - file: { $ref: '#multipartField' }, + options: { $ref: 'multipartField' }, + // TODO: missing proper file type from ajv plugin + file: { $ref: 'multipartField' }, }, required: ['file'], }, @@ -150,6 +157,8 @@ const root: FastifyPluginAsyncJsonSchemaToTs = async (fastify, _options): Promis fastify.delete('/:name/files/:filename', { schema: { + description: 'Delete a file from the index', + tags: ['indexes'], params: { type: 'object', properties: {