diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 00000000..4f11a03d --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/next-swagger-doc.json b/next-swagger-doc.json new file mode 100644 index 00000000..02c3e2a7 --- /dev/null +++ b/next-swagger-doc.json @@ -0,0 +1,13 @@ +{ + "apiFolder": "pages/api", + "schemaFolders": [ + "models" + ], + "definition": { + "openapi": "3.0.0", + "info": { + "title": "Next Swagger API Example", + "version": "1.0" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 8a7c144b..e1037b2d 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "next-auth": "4.19.2", "next-connect": "^0.12.2", "next-redux-wrapper": "^7.0.5", + "next-swagger-doc": "^0.3.6", "next-translate": "^1.2.0", "nodemailer": "^6.9.1", "nookies": "^2.5.2", @@ -63,6 +64,7 @@ "redux-thunk": "^2.4.2", "sass": "1.32", "sass-loader": "13.2.0", + "swagger-ui-react": "^4.17.0", "typescript": "^4.9.5", "uuid": "9.0.0", "webpack": "^5.66.0", diff --git a/pages/api-doc.tsx b/pages/api-doc.tsx new file mode 100644 index 00000000..5981cd6d --- /dev/null +++ b/pages/api-doc.tsx @@ -0,0 +1,34 @@ +import { GetStaticProps, InferGetStaticPropsType } from 'next'; +import { createSwaggerSpec } from 'next-swagger-doc'; +import dynamic from 'next/dynamic'; +import 'swagger-ui-react/swagger-ui.css'; + +const SwaggerUI = dynamic<{ + spec: any; +}>(import('swagger-ui-react'), { ssr: false }); + +function ApiDoc({ spec }: InferGetStaticPropsType) { + return ; +} + +export const getStaticProps: GetStaticProps = async () => { + const spec: Record = createSwaggerSpec({ + + definition: { + openapi: '3.0.0', + info: { + title: 'PEDW API', + description: "something here", + version: '1.0', + }, + }, + }); + + return { + props: { + spec, + }, + }; +}; + +export default ApiDoc; \ No newline at end of file diff --git a/pages/api/doc.ts b/pages/api/doc.ts new file mode 100644 index 00000000..06781292 --- /dev/null +++ b/pages/api/doc.ts @@ -0,0 +1,13 @@ +import { withSwagger } from 'next-swagger-doc'; + +const swaggerHandler = withSwagger({ + definition: { + openapi: '3.0.0', + info: { + title: 'NextJS Swagger', + version: '0.1.0', + }, + }, + apiFolder: 'pages/api', +}); +export default swaggerHandler(); \ No newline at end of file diff --git a/pages/api/documents/download/[id].js b/pages/api/documents/download/[id].js index 7dbf66f9..f0a0a2ea 100644 --- a/pages/api/documents/download/[id].js +++ b/pages/api/documents/download/[id].js @@ -1,3 +1,26 @@ +/** + * @swagger + * /api/documents/download/{id}: + * get: + * tags: + * - Documents + * description: Get document + * parameters: + * - name: id + * in: path + * description: iShare ID + * type: string + * required: true + * default: A21852159 + * - name: hash + * in: query + * description: Hashe stirng + * default: 25d7ae78acb551d9e051b98fc425ebee9b201ba203afe4fc9d330e2b7895e072 + * responses: + * 200: + * description: Success + */ + import axios from "axios"; import CryptoJS from "crypto-js"; import { getToken, consoleLogger } from "../../../../actions"; diff --git a/pages/api/email/notify.js b/pages/api/email/notify.js index 65235bc0..0fb1d41b 100644 --- a/pages/api/email/notify.js +++ b/pages/api/email/notify.js @@ -1,3 +1,15 @@ +/** + * @swagger + * /api/email/notify: + * get: + * tags: + * - Email + * description: Send email via gov notify + * responses: + * 200: + * description: Success + */ + import { consoleLogger } from "../../../actions"; export default async function ApiProxy(req, res) { diff --git a/pages/api/endpoint/getappealtypes_api.js b/pages/api/endpoint/getappealtypes_api.js index 5c5aa7d3..3718ff3c 100644 --- a/pages/api/endpoint/getappealtypes_api.js +++ b/pages/api/endpoint/getappealtypes_api.js @@ -6,16 +6,6 @@ import { azureHeaders, consoleLogger, } from "../../../actions"; -/** - * @swagger - * /api/endpoint/getappealtypes_api: - * get: - * description: Returns appeal types - * responses: - * 200: - * description: - * - */ const WORDKEY = process.env.HASHKEY; diff --git a/pages/api/endpoint/getlogin_api.js b/pages/api/endpoint/getlogin_api.js index ca856d23..f73bca5c 100644 --- a/pages/api/endpoint/getlogin_api.js +++ b/pages/api/endpoint/getlogin_api.js @@ -1,3 +1,14 @@ +/** + * @swagger + * /api/endpoint/getlogin_api: + * get: + * tags: [Login] + * description: Returns the hello world + * responses: + * 200: + * description: hello world + */ + import axios from "axios"; import CryptoJS from "crypto-js"; import _ from "lodash"; diff --git a/pages/api/endpoint/getlpa_api.js b/pages/api/endpoint/getlpa_api.js index 9ef309f7..e831a211 100644 --- a/pages/api/endpoint/getlpa_api.js +++ b/pages/api/endpoint/getlpa_api.js @@ -1,3 +1,14 @@ +/** + * @swagger + * /api/endpoint/getlpa_api: + * get: + * tags: [Search] + * description: Get list of LPA's + * responses: + * 200: + * description: Success + */ + import axios from "axios"; import CryptoJS from "crypto-js"; import { diff --git a/public/swagger.json b/public/swagger.json new file mode 100644 index 00000000..ce4b7051 --- /dev/null +++ b/public/swagger.json @@ -0,0 +1,32 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Next Swagger API Example", + "version": "1.0" + }, + "paths": { + "/api/endpoint/getlogin_api": { + "tags": "Hello", + "get": { + "description": "Returns the hello world", + "responses": { + "200": { + "description": "hello world" + } + } + } + }, + "/api/endpoint/getlpa_api": { + "get": { + "description": "Returns the hello world", + "responses": { + "200": { + "description": "hello world" + } + } + } + } + }, + "components": {}, + "tags": [] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..6db37c02 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] +}