mirror of
https://github.com/Floriansylvain/SnippetsManager.git
synced 2026-08-19 11:43:15 +02:00
Started to add Swagger doc
This commit is contained in:
+6
-1
@@ -1,8 +1,12 @@
|
||||
import express, { RequestHandler } from "express"
|
||||
import * as dotenv from "dotenv"
|
||||
import express, { RequestHandler } from "express"
|
||||
import jwt from "jsonwebtoken"
|
||||
import cors from "cors"
|
||||
import cookieParser from "cookie-parser"
|
||||
|
||||
import swaggerUi from "swagger-ui-express"
|
||||
import swaggerSpec from "./assets/swaggerSpec.js"
|
||||
|
||||
import { getJwtSecret } from "./utils/jwt.js"
|
||||
|
||||
import userRouter from "./routers/user.js"
|
||||
@@ -64,6 +68,7 @@ export function initServer(): express.Express {
|
||||
appRouter.use("/snippet/", authMiddleware, snippetRouter)
|
||||
|
||||
app.use("/v1/", appRouter)
|
||||
app.use("/doc", swaggerUi.serve, swaggerUi.setup(swaggerSpec))
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
export default {
|
||||
openapi: "3.0.0",
|
||||
info: {
|
||||
title: "Snippets Manager",
|
||||
version: "1.0.0",
|
||||
description: "API de gestion de Snippets.",
|
||||
},
|
||||
paths: {
|
||||
"/v1/category": {
|
||||
get: {
|
||||
summary: "Get all categories",
|
||||
description: "Get all the categories available for the user, with pagination.",
|
||||
responses: {
|
||||
"200": {
|
||||
description: "The list of categories with pagination and links.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
categories: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "number",
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
},
|
||||
user_id: {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pagination: {
|
||||
type: "object",
|
||||
properties: {
|
||||
take: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
skip: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
links: {
|
||||
type: "object",
|
||||
},
|
||||
total: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"400": {
|
||||
description: "List of issues that led to the bad request.",
|
||||
},
|
||||
},
|
||||
},
|
||||
post: {
|
||||
summary: "Create a category",
|
||||
description: "Create a category for the user.",
|
||||
requestBody: {
|
||||
description: "The category to create.",
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string",
|
||||
required: true,
|
||||
description: "The category name.",
|
||||
example: "My category",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
"200": {
|
||||
description: "The category has been successfully created.",
|
||||
},
|
||||
"400": {
|
||||
description: "List of issues that led to the bad request.",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"/v1/category/{id}": {
|
||||
get: {
|
||||
summary: "Get a category",
|
||||
description: "Get a category available for the user by its id.",
|
||||
parameters: [
|
||||
{
|
||||
in: "path",
|
||||
name: "id",
|
||||
description: "The category id.",
|
||||
required: true,
|
||||
schema: {
|
||||
type: "integer",
|
||||
},
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
"200": {
|
||||
description: "The category.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
category: {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer",
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
},
|
||||
user_id: {
|
||||
type: "integer",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user