Socket
Book a DemoInstallSign in
Socket

swagger-to-joi-fork

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-to-joi-fork

Swagger to Joi schema converter

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

swagger-to-joi

Swagger to Joi converter

Generates text for Joi definitions. Definitions could be stored to a file or run using eval.

Example usage:

const swaggerToJoi = require('swagger-to-joi');

const joiTextObject = swaggerToJoi(swaggerRouteParametersInJson, components, version, options);

// process joiTextObject or store joi definitions to a file
// returning object contain separate definitions for path, query and body

Example:

const swaggerToJoi = require('swagger-to-joi');
const swagger = {
    swagger: '2.0',
    schema: {
      body: {
        type: "object",
        required: ["apiVersion", "data"],
        properties: {
          apiVersion: { type: "string", enum: ["1.0"], example: "1.0" },
          data: {
            type: "object",
            required: ["projectId", "organization", "value", "currencyCode"],
            properties: {
              projectId: { type: "string", example: "1234567" },
              organization: { type: "string", example: "My Org" },
              currencyCode: { type: "string", example: "EUR" },
              value: { type: "number", example: 50000 },
            },
          },
        },
      }
    }
const joiTextObject = swaggerToJoi(swaggerRouteParametersInJson);

console.log(joiTextObject);

/*
Outputs:

Joi.object({
  apiVersion: Joi.valid("1.0").required(),
  data: Joi.object({
    projectId: Joi.string().required(),
    organization: Joi.string().required(),
    currencyCode: Joi.string().required(),
    value: Joi.number().required(),
  }),
})
*/

Parameters

Components

Used for openAPI 3.0.0. Components used in schema.

Version

2.0 or 3.0.0. default 3.0.0.

Options

  • singleQuote - boolean - determines if you want to user ' or " quotes. Default: true.
  • overrideKeys - key-value object. E.g. { projectId: 'Project.id' }. Will override all keys in any swagger definition where key in swagger will match keyname from the overide object.

Keywords

swagger

FAQs

Package last updated on 15 Jun 2022

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