Schema Providers
Another provider that can be widely used is the Schema
provider.
This provider is a bit different from the others, as it doesn’t interact with the request or reply directly. Instead, it gets all type exports from the providers/schemas.ts
file and injects it into a
ts
export type Something = {
something: boolean;
name: string;
};
export interface Another {
another: boolean;
age: number;
}
// { test: string; test2: number }
export type { MyExportedTypeSomewhere } from '../types';
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Which can later be used by importing the KitaSchemas
constant from the @kitajs/runtime
package.
ts
import { KitaSchemas } from '@kitajs/runtime';
console.log(KitaSchemas);
1
2
3
2
3
json
{
"Another": {
"additionalProperties": false,
"properties": {
"age": { "type": "number" },
"another": { "type": "boolean" }
},
"required": ["another", "age"],
"type": "object"
},
"MyExportedTypeSomewhere": {
"additionalProperties": false,
"properties": {
"test": { "type": "string" },
"test2": { "type": "number" }
},
"required": ["test", "test2"],
"type": "object"
},
"Something": {
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"something": { "type": "boolean" }
},
"required": ["something", "name"],
"type": "object"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
This is pretty useful for when you need json schemas of your types at runtime.
Example
A good example to demonstrate how the provider schema can be used is using type checked environment variables.