
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
swagger-generator-json
Advanced tools
Library generate json use for swagger-ui-express
// example.js file
const { DType, Response, Operation, API } = require('swagger-generator-json')
// By default will be get method
const documentsSearchUser = new API({
path: '/public/users/search',
operation: [
new Operation({
method: DType.get,
parameters: [
{
name: 'username',
type: DType.string,
place: DType.query,
description: "Username must be required"
}
],
responses: [
new Response({
schema: [{
id: DType.number,
name: DType.string,
isAdmin: DType.boolean
}]
}),
new Response({
code: 302,
schema: [{
id: DType.number,
name: DType.string,
isAdmin: DType.boolean
}]
})
],
tags: 'public/user'
})
]
})
// example.js file
const { DType, Response, Operation, API } = require('swagger-generator-json')
// GET method
const operationGet = new Operation({
method: DType.get,
parameters: [
{
name: 'token',
type: DType.string,
place: DType.body,
description: "Token need to authenticate"
},
{
name: 'userid',
type: DType.string,
place: DType.path,
description: "Only number"
}
],
responses: [
new Response({
schema: [{
id: DType.number,
name: DType.string,
isAdmin: DType.boolean
}]
})
],
summary: "API GET USER",
tags: 'public/user'
})
// POST method
const operationPost = new Operation({
method: DType.post,
parameters: [
{
name: 'token',
type: DType.string,
place: DType.header,
description: "Token need to authenticate"
}
],
responses: [
new Response({
schema: {
id: DType.number,
name: DType.string,
isAdmin: DType.boolean
},
})
],
tags: 'public/user',
summary: "API CREATE USER"
})
const documentsPublicUser = new API({
path: '/public/users',
operation: [operationGet, operationPost]
})
module.exports = [documentsPublicUser, documentsSearchUser]
// document.js file
const paths = require('./example')
const { Document } = require('swagger-generator-json')
module.exports = new Document({
description: `This is the Devteam's documents of project`,
version: "1.0.0",
title: "App Name",
paths
})
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./document');
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
// Data response
const data = {
status: true,
message: "Success",
list: [
{
username: "devteam",
isAdmin: "true",
age: 25
}
]
}
// Convert to schema
new Response({
schema: {
status: DType.boolean,
message: DType.string,
list: [
{
username: DType.string,
isAdmin: DType.boolean,
age: DType.number
}
]
}
})
const param = [
{
name: 'list',
type: {
userid: DType.number,
list: [{
productId: DType.number,
price: DType.number
}]
},
place: DType.body,
description: "User's orders"
}
]
FAQs
Generate JSON document for swagger-ui-express
The npm package swagger-generator-json receives a total of 12 weekly downloads. As such, swagger-generator-json popularity was classified as not popular.
We found that swagger-generator-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.