yupgen
v0.1.56
Published
This package generates schema from REST endpoint to Yup schema definition for object validation.
Downloads
6
Maintainers
Readme
yupgen
Schemas generation utils for Yup
How to use:
# install (npm/yarn) from npm registry
npm install yupgen
# init config
yupgen init
# run
yupgen
Example config:
Config file name: yupgen.json:
{
schemas: Array<{
name?: string,
source: string,
method?: string,
body: string
}>,
options: {
outDir?: string
}
}
- default outDir if not specified will be on the root and schemas/ folder
- will detect if there's tsconfig.json file, and hence generate .ts output file with extra type definition.
{
"schemas": [
{
"name": "todo",
"source": "https://jsonplaceholder.typicode.com/todos/1",
"method": "GET"
},
{
"name": "todos",
"source": "https://jsonplaceholder.typicode.com/todos"
}
],
"options": {
"outDir": "src/schemas"
}
}
Example output:
example on todo.js
import { object, number, string, boolean } from "yup";
export const todo = object()
.shape({
userId: number().required(),
id: number().required(),
title: string().required(),
completed: boolean().required()
})
.defined();