Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@malditogeek/openapi-to-joi

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@malditogeek/openapi-to-joi

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

openapi-to-joi

NPM version

Installation

$ npm install @marcduez/openapi-to-joi

$ yarn add @marcduez/openapi-to-joi

General Usage

Generates a file with Joi schemas from an OpenAPI 3 document.

For example, starting with this document:

{
  "openapi": "3.0.0",
  ...
  "paths": {
    "/": {
      "get": {
        "operationId": "operation1",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 5
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Operation1Response"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Operation1Response": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "age": {
            "type": "integer",
            "format": "int32",
            "minimum": 18,
            "maximum": 99
          }
        }
      }
    }
  }
}

And running this command:

$ openapi-to-joi openapi.json --output generated.ts

Produces this generated.ts:

/* eslint-disable */
/* prettier-ignore */
import Joi from "joi"

export const schemas = {
  parameters: {
    operation1: { id: Joi.string().required().min(5) },
  },
  components: {
    Operation1Response: Joi.object({
      email: Joi.string().email({}),
      age: Joi.number().integer().max(99).min(18),
    }).unknown(),
  },
}

Using the CLI

To view usage instructions for the CLI, use the --help command:

$ npm run openapi-to-joi --help

$ yarn openapi-to-joi --help

Keywords

FAQs

Package last updated on 28 Sep 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc