Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swagger api docs #35

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/api-docs/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getApiDocs } from "@/lib/swagger";
import ReactSwagger from "./react-swagger";
import "@/styles/swagger.css";

export default async function IndexPage() {
const spec = await getApiDocs();
return (
<section className="container">
<ReactSwagger spec={spec} />
</section>
);
}
14 changes: 14 additions & 0 deletions app/api-docs/react-swagger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import SwaggerUI from "swagger-ui-react";
import "swagger-ui-react/swagger-ui.css";

type Props = {
spec: Record<string, any>;
};

function ReactSwagger({ spec }: Props) {
return <SwaggerUI spec={spec} />;
}

export default ReactSwagger;
48 changes: 48 additions & 0 deletions app/api/create-space/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,54 @@ import { WorkflowType } from "@/lib/workflow-type";
import { NextRequest, NextResponse } from "next/server";
import invariant from "ts-invariant";

/**
* @swagger
* /api/create-space:
* post:
* tags: [/api/]
* summary: Create a new space
* description: Creates a new space for the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* workflowType:
* type: string
* description: The type of workflow for the space.
* spaceName:
* type: string
* description: The name of the space.
* responses:
* 201:
* description: Successfully created the space.
* content:
* application/json:
* schema:
* type: object
* properties:
* spaceId:
* type: string
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
* 500:
* description: Error creating the space.
*/

export const POST = async (request: NextRequest, context: { params: any }) => {
return authenticatedRoute(request, context, async (request, context) => {
let json = await request.json();
Expand Down
126 changes: 126 additions & 0 deletions app/api/custom-field/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,106 @@ import { authenticatedRoute } from "@/lib/api-helpers";
import { CustomFieldService } from "@/lib/services/custom-field";
import { NextRequest, NextResponse } from "next/server";

/**
* @swagger
* /api/custom-field:
* post:
* tags: [/api/]
* summary: Create a new custom field
* description: Creates a new custom field for the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* name:
* type: string
* description: The name of the custom field.
* type:
* type: string
* description: The type of the custom field.
* required:
* type: boolean
* description: Whether the custom field is required.
* dateFormat:
* type: string
* description: The date format for the custom field.
* decimals:
* type: number
* description: The number of decimals for the custom field.
* enumOptions:
* type: array
* description: The enum options for the custom field.
* responses:
* 201:
* description: Successfully created the custom field.
* content:
* application/json:
* schema:
* type: object
* properties:
* customField:
* type: object
* properties:
* id:
* type: string
* userId:
* type: string
* name:
* type: string
* type:
* type: string
* required:
* type: boolean
* dateFormat:
* type: string
* decimals:
* type: number
* enumOptions:
* type: array
* items:
* type: string
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
* 500:
* description: Error creating the custom field.
*
* delete:
* summary: Delete custom field
* description: Deletes the custom field for the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* responses:
* 201:
* description: Successfully deleted the custom field.
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
*/

export const POST = async (request: NextRequest, context: { params: any }) => {
return authenticatedRoute(request, context, async (rq, cxt) => {
const json = await request.json();
Expand All @@ -23,6 +123,32 @@ export const POST = async (request: NextRequest, context: { params: any }) => {
});
};

/**
* @swagger
* /api/custom-field:
* delete:
* tags: [/api/]
* summary: Delete custom field
* description: Deletes the custom field for the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* responses:
* 201:
* description: Successfully deleted the custom field.
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
*/

export const DELETE = async (
request: NextRequest,
context: { params: any }
Expand Down
49 changes: 49 additions & 0 deletions app/api/filefeed-events/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,55 @@ import { serializeFilefeedEvents } from "@/lib/serializers/filefeed-event";
import { ActionService } from "@/lib/services/action";
import { NextRequest, NextResponse } from "next/server";

/**
* @swagger
* /api/filefeed-events:
* get:
* tags: [/api/]
* summary: Retrieve all filefeed events for the logged-in user
* description: Returns a list of filefeed events associated with the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* - in: header
* name: x-space-id
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Successfully retrieved the filefeed events.
* content:
* application/json:
* schema:
* type: object
* properties:
* actions:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* actionType:
* type: string
* createdAt:
* type: string
* data:
* type: object
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
*/

export const GET = async (request: NextRequest, context: { params: any }) => {
return authenticatedRoute(request, context, async (rq, cxt) => {
const actions = await ActionService.getFilefeedEvents({
Expand Down
26 changes: 26 additions & 0 deletions app/api/reset-account/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ import { authenticatedRoute } from "@/lib/api-helpers";
import { ResetAccountService } from "@/lib/services/reset-account";
import { NextRequest, NextResponse } from "next/server";

/**
* @swagger
* /api/reset-account:
* post:
* tags: [/api/]
* summary: Reset the account
* description: Resets the account for the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* responses:
* 201:
* description: Successfully reset the account.
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
*/

export const POST = async (request: NextRequest, context: { params: any }) => {
return authenticatedRoute(request, context, async (rq, cxt) => {
const userId = cxt.user.id;
Expand Down
49 changes: 49 additions & 0 deletions app/api/v1/attributes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@ import { apiAuthenticatedRoute } from "@/lib/api-helpers";
import { AttributeService } from "@/lib/services/attribute";
import { NextRequest, NextResponse } from "next/server";

/**
* @swagger
* /api/v1/attributes:
* get:
* tags: [/api/v1/]
* summary: Retrieve all attributes for the logged-in user
* description: Returns a list of attributes associated with the logged-in user.
* parameters:
* - in: header
* name: Authorization
* required: true
* schema:
* type: string
* description: Bearer token for authentication.
* - in: header
* name: x-listener-auth
* required: true
* schema:
* type: string
* - in: header
* name: x-space-id
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Successfully retrieved the attributes.
* content:
* application/json:
* schema:
* type: object
* properties:
* attributes:
* type: array
* items:
* type: object
* properties:
* name:
* type: string
* value:
* type: string
* unit:
* type: string
* externalId:
* type: string
* 401:
* description: Unauthorized, if the user is not logged in or token is invalid.
*/

export const GET = (
req: NextRequest,
context: { params: { userId: string } }
Expand Down
Loading
Loading