Skip to content

Commit

Permalink
feat(app): add openapi documentation capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Feb 11, 2024
1 parent ca0b9e3 commit 77fdde8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "8.56.0",
"@types/pg": "^8.10.9",
"@types/swagger-jsdoc": "^6.0.4",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"autoprefixer": "^10.4.16",
Expand Down Expand Up @@ -80,6 +81,7 @@
"svelte-highlight": "^7.4.7",
"svelte-sonner": "^0.3.11",
"sveltekit-superforms": "^1.13.1",
"swagger-jsdoc": "^6.2.8",
"tailwind-merge": "^2.2.0",
"tailwind-variants": "^0.1.19",
"tsx": "^4.7.0",
Expand Down
15 changes: 15 additions & 0 deletions src/routes/api/log/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import { z } from 'zod';
import { PUBLIC_APP_URL } from '$env/static/public';
import { formatDate } from '$lib/format/date';

/**
* @openapi
* /api/log:
* post:
* description: Logs an event and sends the webhooks.
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* responses:
* 200:
* description: Returns the newly created event object.
*/
export const POST: RequestHandler = async ({ request, locals }) => {
const parser = new UAParser(request.headers.get('user-agent'));
if (!locals.apiUser) return error(403);
Expand Down
18 changes: 18 additions & 0 deletions src/routes/api/openapi/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { RequestHandler } from './$types';
import swaggerJsdoc from 'swagger-jsdoc';

const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Supso',
version: '1.0.0'
}
},
apis: ['src/routes/api/**/+server.ts']
};

export const GET: RequestHandler = async () => {
const openapiSpecification = swaggerJsdoc(options);
return Response.json(openapiSpecification);
};
4 changes: 2 additions & 2 deletions src/routes/api/projects/[projectId]/rss/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { usersToProjects } from '$lib/db/schema';
import { Feed } from 'feed';
import { PUBLIC_APP_URL } from '$env/static/public';

export const GET: RequestHandler = async ({ locals, request }) => {
const projectId = request.params;
export const GET: RequestHandler = async ({ locals, params }) => {
const { projectId } = params;
const user = locals.apiUser;
if (!user) return error(400, 'Unauthorized');
const memberships = await db.query.usersToProjects.findMany({
Expand Down

0 comments on commit 77fdde8

Please sign in to comment.