npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger-schemagen

v1.0.5

Published

swagger-ui schema auto generation perameter type for mssql

Downloads

7

Readme

swagger-schema

swagger-ui schema auto generation and base on swagger-autogen.

NPM Version NPM Downloads

Installation

This is a Node.js module available through the npm.

$ npm install --save swagger-schemagen

It is loaded using the require() function:

const swaggerSchema = require('swagger-schemagen')

Update

If you already have the module installed and want to update to the latest version, use the command:

$ npm install --save swagger-schemagen@last

Usage

Example express api

Usage

Function signature:

const swaggerSchema: (outputFile: <string>, schemaFolder: <Array of string>) => Promise <any>

outputFile: (Required*). Output file. It will be the file generated by the module containing the documentation in the format identified by Swagger.

schemaFolder: (Required*). This Folder is saving all of schema json file, and the parameter's type for mssql will update in Swagger file.

The code below must be inserted in a separate file, for example: swagger.js. For example:

File: swagger.js

const doc = {
    info: {
        title: "Example API Document",
        description: "Description"
    },
    host: null,
    schemes: ['http'],
    tags: alltags
}

const outputFile = './src/swagger/swagger-output.json'
const endpointsFiles = ['./index.js']

const swaggerschema = require('./src/lib/swaggerschema')
const schematest = require('swagger-schemagen')

const asyncfun = async (outputFile, endpointsFiles, doc, schemaFolder) => {
    await swaggerAutogen(outputFile, endpointsFiles, doc)
    await schematest(outputFile, schemaFolder)
}

const schemaFolder = './src/schema/'
asyncfun(outputFile, endpointsFiles, doc, schemaFolder)

Example Document

Json file in schema folder

Note.json:

[
    { "attr": "vid", "type": "Int" },
    { "attr": "currenttime", "type": "Float" },
    { "attr": "nid", "type": "Int" },
    { "attr": "title", "type": "NVarChar" },
    { "attr": "content", "type": "NVarChar" }
]

Notice

Swagger schema json file and swagger tag should be give in same name!!!

Like your router's swagger tag is 'Note', and your schema name should be 'Note.json'.

Compare Use

Before Using swagger-schema

controller -> Note.js:

router.delete('/note', async (req, res, next) => {
    // #swagger.tags = ['Note']
    // #swagger.summary = '刪除單個筆記'
    const { nid } = req.body // declare parameter's in body
    sqlcode = "update Note set bDel = 1 where NID = @nid and OwnerMID = @mid";
    let response = await runSQL(sqlcode, req, schema);
    res.json(response ? { message: "success" } : { message: "failed" });
});

router.put('/note/title', async (req, res, next) => {
    // #swagger.tags = ['Note']
    // #swagger.summary = '編輯筆記標題'
    const { nid, title } = req.body // declare parameter's in body
    sqlcode = "update Note set Title = @title, LastModifiedDT = getdate() where NID = @nid and OwnerMID = @mid";
    let response = await runSQL(sqlcode, req, schema);
    res.json(response ? { message: "success" } : { message: "failed" });
});

image

After Using swagger-schema

schema file: image

image