Redocly / json-to-json-schema

Convert JSON examples into JSON schema (supports Swagger 2, OpenAPI 3 and 3.1)

Home Page:https://redocly.com/tools/json-to-json-schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

json-to-json-schema

npm version bundle size dependency size Coverage Status

Convert JSON examples into JSON schema.

Supports JSON Schema draft-05 used in Swagger 2.0 and OpenAPI 3.0 and new draft draft-2020-12 used in OpenAPI 3.1.

Usage

import { convert, format } from '@redocly/json-to-json-schema';

const example = { firstname: 'John', surname: 'Doe', birthday: '1990-02-23' };

const schema = convert(example, {
  target: 'draft-05-oas', // or draft-2020-12
  includeExamples: false,
  disableAdditionalProperties: false,
  inferRequired: false,
});

Output:

firstname:
  type: string
surname:
  type: string
birthday:
  type: string
  format: date

Similar tools

https://github.com/mohsen1/json-to-json-schema

About

Convert JSON examples into JSON schema (supports Swagger 2, OpenAPI 3 and 3.1)

https://redocly.com/tools/json-to-json-schema


Languages

Language:TypeScript 97.9%Language:JavaScript 1.8%Language:Shell 0.3%