a little DSL that outputs JSON schema

Overview

kontur

NPM Version Build Status Node.js Version

a little DSL that outputs JSON schema

instruction on validating request body in koa using ajv and kontur

overview

import { compile, bool, int, str } from 'kontur'

compile({
  gender: str,
  age: int,
  nickname: str,
  verified: bool
})

will generate

{
  type: 'object',
  properties: {
     gender: { type: 'string' },
     age: { type: 'integer' },
     nickname: { type: 'string' },
     verified: { type: 'boolean' }
  },
  required: [ 'gender', 'age', 'nickname', 'verified' ]
}
compile({
  gender: str.in('male', 'female').optional,
  age: int.between(0, 200),
  nickname: str.minlen(3).match(/^[a-zA-Z]/),
  verified: bool.optional.default(false)
})

will generate

{
  type: 'object',
  properties: {
    gender: {
      enum: ['male', 'female'],
      type: 'string'
    },
    age: {
      minimum: 0,
      maximum: 200,
      type: 'integer'
    },
    nickname: {
      minLength: 3,
      pattern: '^[a-zA-Z]',
      type: 'string'
    },
    verified: {
      default: false,
      type: 'boolean'
    }
  },
  required: [ 'age', 'nickname' ]
}

nested schema

compile({
  assignment: {
    assignees: array.len(3).uniq.items(str.len(16)),
    assigner: object.strict.properties({
      id: str.len(16)
    }),
    assigned_at: str.datetime
  }
})

the output can be found here

types

object

strict, no extra properties should be included

size(num), maxsize(num), minsize(num), limit the number of properties

properties(schema), specify schema of children

array

strict, no extra items should be included

len(num), minlen(num), maxlen(num), limit the length of the array

items(schema), all element should match

uniq

contains(schema), at least one element should match

string

match(regexp), match a regular expression

email, ipv4, ipv6, uri, datetime, built-in formats

number/int

min(num), max(num), between(num, num),

min(num).exclusive, max(num).exclusive

null

nil just null

boolean

bool

tuple(direived from array)

use plain array

[str, int.between(1,5)]

enum

str.in('created', 'suspended', 'deleted')
any('male', 'female')

miscs

optional used in context of object, by default all keys are required

depends(keys) used in context of object

default(value) add default value

desc(text) add description

title(text) add title

combining schemas

all

all(int.min(0), int.max(1))

any

any(int.min(1).exclusive, int.max(0).exclusive)

one

one(int.min(0), int.max(1))

not

not.nil
not.object.array
You might also like...

A CLI progam show teminal outputs as gradients.

A CLI progam show teminal outputs as gradients.

GRADIENT-TERMINAL A CLI progam to display teminal outputs as gradients. Requirements For Installation, you will only need Node.js. Install $ git clone

Jan 3, 2023

Input a list of Handshake top-level domains, outputs names sorted into 4 arrays: available, registered, reserved, or invalid.

name-check A simple NodeJS package that, given a flat list of top-level domain names, queries the Handshake (HNS) blockchain in order to classify each

Jan 8, 2022

Leaderboard - An app that outputs the names and the score of the players and it uses API's to get all the informations

leaderboard is an app that outputs the names and the score of the players and it uses API's to get all the informations.

Jul 8, 2022

Github action to parse OWNERS files and outputs random reviewers

Get Owners Github Action Do you want to have all the approvers and reviewers without having strange scripts in your actions? Do you want to have rando

Oct 22, 2022

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

Jun 2, 2022

The backend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The backend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

My first full stack application with the concept of a personal wallet that allows you to create a personal account to keep track of your entire statement by adding incoming and outgoing transactions, as well as calculating the total balance and being able to edit and delete old transactions.

Jun 23, 2022

๐Ÿ“ฆ ๐Ÿฃ Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs

pkgroll Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single command! Features Zero conf

Dec 23, 2022

๐Ÿ“ฆ ๐Ÿฃ Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs. (Forked from pkgroll)

๐Ÿ“ฆ ๐Ÿฃ puild (A fork of pkgroll) Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single com

Sep 6, 2022

JSON-Schema + fake data generators

JSON-Schema + fake data generators

Use JSON Schema along with fake generators to provide consistent and meaningful fake data for your system. What's next? Breaking-changes towards v0.5.

Jan 4, 2023

Create a schema object to encode/decode your JSON in to a compact byte buffer with no overhead.

Create a schema object to encode/decode your JSON in to a compact byte buffer with no overhead.

schemapack The fastest and smallest JavaScript object serialization library. Efficiently encode your objects in to compact byte buffers and then decod

Nov 26, 2022

Tiny Validator for JSON Schema v4

Tiny Validator (for v4 JSON Schema) Use json-schema draft v4 to validate simple values and complex objects using a rich validation vocabulary (example

Dec 21, 2022

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is an JSON API sanitisation and validation module.

Schema-Inspector is a powerful tool to sanitize and validate JS objects. It's designed to work both client-side and server-side and to be scalable wit

Oct 3, 2022

Validate directory structure and file contents with an extension of JSON schema.

directory-schema-validator Description Validate directory structure and file contents with an extension of JSON schema. Install Install using NPM or s

Nov 1, 2022

Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code

Defines the communication layer between mobile native(iOS/Android) and webview using JSON Schema and automatically generates SDK code.

Dec 8, 2022

typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

fast-typescript-to-jsonschema English | ็ฎ€ไฝ“ไธญๆ–‡ a tool generate json schema from typescript. Feature compile Typescript to get all type information conve

Nov 28, 2022

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

JSON Form The JSON Form library is a JavaScript client-side library that takes a structured data model defined using JSON Schema as input and returns

Dec 28, 2022

Validate your Markdown frontmatter data against a JSON schema โ€” remark-lint rule plugin

Validate your Markdown frontmatter data against a JSON schema โ€” remark-lint rule plugin

remark-lint-frontmatter-schema Validate Markdown frontmatter YAML against an associated JSON schema with this remark-lint rule plugin. Supports: Types

Dec 10, 2022

Json-parser - A parser for json-objects without dependencies

Json Parser This is a experimental tool that I create for educational purposes, it's based in the jq works With this tool you can parse json-like stri

Jan 3, 2022

Pretty-print-json - ๐Ÿฆ‹ Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

Pretty-print-json - ๐Ÿฆ‹ Pretty-print JSON data into HTML to indent and colorize (written in TypeScript)

pretty-print-json Pretty-print JSON data into HTML to indent and colorize (written in TypeScript) 1) Try It Out Interactive online tool to format JSON

Dec 30, 2022
Comments
  • custom properties?

    custom properties?

    Wondering, I have a use case to add .indexable as an option:

    https://github.com/pubkey/rxdb/blob/10ec1d926e45485662fabd402cf1da3655183747/test/helper/schemas.js#L36

    Rather than for kontur, would be nice to have some way to defining props. Not sure how best to do this, I could Proxy the class I guess and then check on compile, but would need access to compile function.

    opened by natew 1
Owner
null
Create a schema object to encode/decode your JSON in to a compact byte buffer with no overhead.

schemapack The fastest and smallest JavaScript object serialization library. Efficiently encode your objects in to compact byte buffers and then decod

null 442 Nov 26, 2022
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

Ajv JSON schema validator The fastest JSON validator for Node.js and browser. Supports JSON Schema draft-06/07/2019-09/2020-12 (draft-04 is supported

Ajv JSON schema validator 12k Jan 4, 2023
Convert JSON examples into JSON schema (supports Swagger 2, OpenAPI 3 and 3.1)

json-to-json-schema 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

Redocly 9 Sep 15, 2022
A simple CLI to generate a starter schema for keystone-6 from a pre-existing prisma schema.

Prisma2Keystone A tool for converting prisma schema to keystone schema typescript This is a proof of concept. More work is needed Usage npx prisma2key

Brook Mezgebu 17 Dec 17, 2022
A friendly reusable charts DSL for D3

D4 D4 is a friendly charting DSL for D3. The goal of D4 is to allow developers to quickly build data-driven charts with little knowledge of the intern

Mark Daggett 429 Dec 5, 2022
The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform.

The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform. Inspired by NUKE. This project is reaching a mature stage, althoug

Aleksej Komarov 33 Oct 16, 2022
A simple query builder, it will helps to develop DSL query for Elasticsearch

Elasticsearch Dynamic Query Builder A simple query builder, it will helps to develop DSL query for elasticsearch Installation You can start it from np

Hashemi Rafsan 4 Nov 20, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (ๆดช ๆฐ‘ๆ†™) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de crรฉer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
JSON Hero is an open-source, beautiful JSON explorer for the web that lets you browse, search and navigate your JSON files at speed. ๐Ÿš€

JSON Hero makes reading and understand JSON files easy by giving you a clean and beautiful UI packed with extra features.

JSON Hero 7.2k Jan 9, 2023