Easy to check type for json api response. Auto generate TypeScript schema file by request info ( path, method and response ) at first time, then check json response according to the associated TypeScript schema next request. Of course, the TypeScript schema files can be rewritten.
npm install jsonapi-check -D
See example/node for more details.
import { jsonapiCheck } from "jsonapi-check"
axios.interceptors.response.use((response) => {
const { request, data } = response
const { path, method } = requset
const options = {
schemaDir: "schema",
hasSubdirs: false,
}
// dev-mode check
jsonapiCheck(path, method, data, options)
return response
})
See example/brower for more details.
- GET /authors --> schema/authors-GET.ts --> interface Author
- GET /authors/12 --> schema/author-GET.ts --> interface Author
- Type:
string
- Default:
schema
The name of directory for generate json schema type.
- Type:
boolean
- Default:
false
The schema directory has subdirectory or not. If true, will mkdir like next directory.
- GET /authors --> schema/authors/authors-GET.ts --> interface Author
- GET /web/…/authors --> schema/web/author-GET.ts --> interface Author
✨ Happy hacking!
MIT License © 2023-Present Efrice.