Skip to content

Commit

Permalink
Add command to package.json for auto generating
Browse files Browse the repository at this point in the history
swagger.
  • Loading branch information
abdulla-ashurov committed Jul 10, 2023
1 parent 7948af3 commit 293273c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"scripts": {
"prebuild": "swagger-jsdoc -d src/swagger.cjs -o src/static/swagger.json ./src/controllers/*.ts",
"build": "tsc",
"start": "node dist/index.js",
"format": "prettier --write '*.{json,js}' 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
Expand Down
33 changes: 6 additions & 27 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,15 @@ import { Connection } from './database/connection/connection.js'
import { RevocationController } from './controllers/revocation.js'
import { CORS_ERROR_MSG } from './types/constants.js'

import swaggerJSONDoc from './static/swagger.json' assert { type: "json" }

import * as dotenv from 'dotenv'
dotenv.config()

import path from 'path'
import { LogToWebHook } from './middleware/hook.js'
import { Middleware } from './middleware/middleware.js'

import swaggerJsdoc from 'swagger-jsdoc';

const options = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'Credential Service for cheqd network',
version: '2.0.0',
description: 'API service to create and manage DIDs and credentials on cheqd network.'
},
tags: [
{
name: 'Credential',
externalDocs: {
url: 'https://github.com/cheqd/credential-service#readme'
}
}
],
components: {}
},
apis: ['./src/controllers/*.ts'],
};

const openApiSpecification = swaggerJsdoc(options);

let swagger_options = {}
if (process.env.ENABLE_AUTHENTICATION === 'true') {
swagger_options = {
Expand Down Expand Up @@ -96,8 +73,10 @@ class App {

this.express.use(
'/swagger',
swaggerUi.serve,
swaggerUi.setup(openApiSpecification, swagger_options)
swaggerUi.serve,
async (_req: express.Request, res: express.Response) => {
return res.send(swaggerUi.generateHTML(swaggerJSONDoc, swagger_options))
}
)
this.express.use(auth.handleError)
this.express.use(async (req, res, next) => await auth.accessControl(req, res, next))
Expand Down

0 comments on commit 293273c

Please sign in to comment.