Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smikhalevski/doubter-json-schema
🤔 Converts Doubter shapes from and to JSON schemas.
https://github.com/smikhalevski/doubter-json-schema
doubter json-schema
Last synced: about 2 months ago
JSON representation
🤔 Converts Doubter shapes from and to JSON schemas.
- Host: GitHub
- URL: https://github.com/smikhalevski/doubter-json-schema
- Owner: smikhalevski
- License: mit
- Created: 2023-01-12T13:44:35.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-31T12:04:51.000Z (11 months ago)
- Last Synced: 2024-10-05T04:43:13.236Z (3 months ago)
- Topics: doubter, json-schema
- Language: TypeScript
- Homepage: https://smikhalevski.github.io/doubter-json-schema/
- Size: 329 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Doubter × JSON Schema
Converts [Doubter](https://github.com/smikhalevski/doubter) shapes from and to JSON schemas.
> [!WARNING]\
> This project is at the early development stage.```shell
npm install --save-prod @doubter/json-schema
```Define a shape:
```ts
import * as d from 'doubter';
import { toJSONSchema } from '@doubter/json-schema';const shape = d.object({
name: d.string(),
age: d.number().gt(10).optional()
});
// ⮕ Shape<{ name: string, age?: number | undefined }>const schema = toJSONSchema(shape);
```The `schema` is a JSON schema object:
```json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "number",
"exclusiveMinimum": 10
}
},
"required": ["name"]
}
```