New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

openapi_js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi_js

under the hood it used https://openapi-generator.tech/ without previous installation.

Source
npmnpm
Version
1.5.2
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
Source

HOW IT WORK

under the hood it used https://openapi-generator.tech/ without previous installation.

Installation and usage

npm install openapi_js

In my case, I created the interfaces folder in the root of the project and added a file with interface.js there with one of the options below.

Without Auth

const {generatorInterfaces} = require("openapi_js");

/**
 * @example {https://{{SITE_NAME}}/swagger.json}
 */
const linkToSwagger = "{{LINK_TO_YOUR_SWAGGER}}";

(async () => {
  try {

    const openapiGeneratorCLIConfiguration = {
      "input-spec": linkToSwagger,
      // folder for files to be created
      "output": "./interfaces",
    };

    await generatorInterfaces({
      openapiGeneratorCLIConfiguration
    });
  } catch (err) {
    console.log(err);
  }
})();

With Auth

const axios = require("axios");
const {generatorInterfaces} = require("openapi_js");

/**
 * @example {https://{{SITE_NAME}}/swagger.json}
 */
const linkToSwagger = "{{LINK_TO_YOUR_SWAGGER}}";
let token;

const getAuthToken = async () => {
  try {
    const res = await axios({
      baseURL: "https://example.com",
      url: "/login",
      method: "POST",
      data: JSON.stringify({
        email: "test@example.com", password: "example"
      }),
      headers: {
        "Content-Type": "application/json;charset=utf-8"
      }
    });

    token = res.data.key;
  } catch (err) {
    console.log(err);
  }
};

(async () => {
  try {
    await getAuthToken();

    const openapiGeneratorCLIConfiguration = {
      "input-spec": linkToSwagger,
      "auth": `"Authorization:Token ${token}"`,
      // folder for files to be created
      "output": "./interfaces",
    };

    await generatorInterfaces({
      openapiGeneratorCLIConfiguration
    });
  } catch (err) {
    console.log(err);
  }
})();

Options

Props

  • filesToRemove - default: ["git_push.sh", ".openapi-generator-ignore", ".npmignore", ".gitignore", ".openapi-generator"]
  • prefixInterfaces - default: { interface: "I", enum: "E", type: "T" }

package.json

Just add this script to your package.json

{
  "scripts": {
    "generate:interfaces": "node interfaces/interface.js"
  }
}

Troubleshot

Type error

if you are using the front of the application without a back, at the time of the script execution you will need to add the following line to your package.json file

{
  "type": "module"
}

Keywords

openapi

FAQs

Package last updated on 06 Sep 2023

Did you know?

Socket

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.

Install

Related posts