All Projects β†’ wix-incubator β†’ as-typed

wix-incubator / as-typed

Licence: MIT license
Ambient mapping from JSON schema to typescript

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to as-typed

Activerecord json validator
πŸ”© ActiveRecord::JSONValidator makes it easy to validate JSON attributes against a JSON schema.
Stars: ✭ 220 (+126.8%)
Mutual labels:  json-schema
Rxdb
πŸ”„ A client side, offline-first, reactive database for JavaScript Applications
Stars: ✭ 16,670 (+17085.57%)
Mutual labels:  json-schema
angular-schema-form-bootstrap
Bootstrap decorator for Angular Schema Form
Stars: ✭ 50 (-48.45%)
Mutual labels:  json-schema
Spot
Spot is a concise, developer-friendly way to describe your API contract.
Stars: ✭ 230 (+137.11%)
Mutual labels:  json-schema
Full Stack Fastapi Couchbase
Full stack, modern web application generator. Using FastAPI, Couchbase as database, Docker, automatic HTTPS and more.
Stars: ✭ 243 (+150.52%)
Mutual labels:  json-schema
json-kotlin-schema-codegen
Code generation for JSON Schema (Draft 07)
Stars: ✭ 52 (-46.39%)
Mutual labels:  json-schema
Type O Rama
πŸ‘Ύ JS type systems interportability
Stars: ✭ 217 (+123.71%)
Mutual labels:  json-schema
django-jsonform
A better, user-friendly JSON editing form field for Django admin. Also supports Postgres ArrayField.
Stars: ✭ 151 (+55.67%)
Mutual labels:  json-schema
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (+160.82%)
Mutual labels:  json-schema
another-json-schema
Another JSON Schema validator, simple & flexible & intuitive.
Stars: ✭ 48 (-50.52%)
Mutual labels:  json-schema
Json Schema Tools
Packages for working with JSON Schema and JSON Hyper-Schema
Stars: ✭ 232 (+139.18%)
Mutual labels:  json-schema
Form Render
πŸš΄β€β™€οΈ ι˜Ώι‡Œι£žηŒͺ - εΎˆζ˜“η”¨ηš„δΈ­εŽε°γ€Œθ‘¨ε• / 葨格 / ε›Ύθ‘¨γ€θ§£ε†³ζ–Ήζ‘ˆ
Stars: ✭ 3,881 (+3901.03%)
Mutual labels:  json-schema
json matcher
Library for simplifying data verification in functional tests for your JSON-based APIs
Stars: ✭ 24 (-75.26%)
Mutual labels:  json-schema
Jsonon
A json online view
Stars: ✭ 228 (+135.05%)
Mutual labels:  json-schema
restish
Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
Stars: ✭ 453 (+367.01%)
Mutual labels:  json-schema
Angular Schema Form
Generate forms from a JSON schema, with AngularJS!
Stars: ✭ 2,456 (+2431.96%)
Mutual labels:  json-schema
OpenAPI-Delphi
The Delphi-OpenAPI library is an OpenAPI 3.0 document generator and parser for Delphi
Stars: ✭ 79 (-18.56%)
Mutual labels:  json-schema
magnet
A JSON/BSON schema generator
Stars: ✭ 16 (-83.51%)
Mutual labels:  json-schema
json-schema
JSON schema validation
Stars: ✭ 20 (-79.38%)
Mutual labels:  json-schema
openshift-json-schema
A set of JSON schemas for various OpenShift versions, extracted from the OpenAPI definitions
Stars: ✭ 23 (-76.29%)
Mutual labels:  json-schema

as-typed

Ambient mapping from JSON schema to typescript, without transpilation. Use JSON schemas as a first-class citizen in Typescript.

Overview

There are many tools that convert between Typescript and JSON schema. Howewever, all of them do that with a transpilation step. Ambison uses the deep inference options in typescript 3 to infer the types directly from the JSON schema.

This is not a runtime library - it contains only a single generic type, AsTyped. AsTyped can take any Json schema and AsTypeds it to a typescript type.

Example Usage

As-typed is ambient only. To use, simply use the JSON schema as a type passed to the AsTyped generic type instead of as a value. For example: AsTyped<{type: 'string'}> will resolve to the typescript type string, and AsTyped<{type: 'object' properties: {foo: {type: 'string'}}}> will resolve to {foo: string} in typescript.

Conversion Details

Every JSON schema type casts to a particular typescript type, as far as possible by language limitations. The following is a table of how JSON schema types translate to Typescript types with asTyped

Primitive types

  • AsTyped<{type: 'string'}> === string
  • AsTyped<{type: 'number'}> === number
  • AsTyped<{type: 'boolean'}> === boolean
  • AsTyped<{type: 'null'}> === null
  • AsTyped<{type: 'undefined'}> === undefined

Limitations

  • Patterns are not supported. There is no regex validation in typescript Typescript issue 6579

  • Value validation (min, max etc) is not supported Typescript is not meant for value checking (at least currently).

Defined objects

  • AsTyped<{type: 'object', properties: {foo: {type: 'number'}}> === {foo?: number}

with required properties

  • AsTyped<{type: 'object', properties: {foo: {type: 'number'}, bar: {type: 'string}, required: ['foo']}> === {foo: number, bar?: string}

objects with a specific value type

AsTyped<{type: 'array', items: [{type: 'number'}, {type: 'string'}], additionalItems: {type: 'boolean'}}> === [number, string, ...boolean[]]

Recursive objects and arrays

  • AsTyped<{type: 'array', items: {type: 'array', items: {type: 'string'}}}> === string[][]
  • AsTyped<{type: 'object', properties: {arr: {type: 'array', items: {type: 'object', additionalProperties: {type: 'string'}}}}} === {arr: {[name: string]: string}[]}

Simple array

  • AsTyped<{type: 'array', items: {type: 'string}}>===string[]`

Tuple

  • AsTyped<{type: 'array', items: [{type: 'string'}, {type: 'number'}]}> === [string, number]

Limitations

Due to typescript's missing variadic features, the max number of items in a tuple needs to be hardcoded, currently to 10. Typescript issue 5453

Tuple with additional items

  • AsTyped<{type: 'array', items: [{type: 'string'}, {type: 'number'}], additionalItems: {type: 'string'}}}> === [string, number, ...string[]]

Recursive reference by $id

Simple references:

  • AsTyped<{definitions: {foo: {$id: 'foo', type: 'number'}}, $ref: 'foo'}> === number

Deep references:

  • AsTyped<{definitions: {str1: {$id: 'str1', $ref: 'str2'}, str2: {$id: 'str2', type: 'string'}}, $ref: 'str1'}> === string

Limitations

Reference by URL ('#/definitions/foo', 'other.json/foo') are not supported. Typescript doesn't allow inference by partial strings Typescript Issue 12754

not

Not works mainly on primitive types, e.g. AsTyped<{not: {type: 'string'}}> will resolve to number | object | any[] | boolean

oneOf

  • AsTyped<{oneOf: [{type: 'string'}, {type: 'number'}]}> === string | number

Currently doesn't work as expected, and resolves the same as anyOf. See Typescript issue 20863

allOf

  • AsTyped<{allOf: [{type: 'object', properties: {a: {type: 'number'}}}, {type: 'object', properties: {b: {type: 'string'}}}]}> === {a?: number, b?: string}

anyOf

  • AsTyped<{allOf: [{type: 'object', properties: {a: {type: 'number'}}}, {type: 'object', properties: {b: {type: 'string'}}, required: ['b']}]}> === {a?: number, b: string} | {a?: number} | {b: string}

If/Then/Else

If/Then/Else acts exactly like {oneOf: [{allOf: [If, Then]}, Else]}. It's strange to have this sugar in the schema which doesn't reduce the verbosity. Currently doesn't work as expected, for the same reasons as oneOf. Resolves to (If & Then) | Else, which is not an accurate translation. See Typescript issue 20863

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].