To generate JSON schemas for your own codecs, you should override the generateSchemas method in your Codec2SchemaPlugin.
The Generation
Here, I will use the Bean example from the Fabric Documentation, specifically the one from the registry dispatch example.
Actually exporting the schema is very simple:
@Override
public void generateSchemas(SchemaExporter exporter) {
exporter.accept(Bean.BEAN_CODEC, "example/bean.json");
}2
3
4
The generated schema should show up at codec2schema/example/bean.json in your game directory along with the vanilla codecs that Codec2Schema already generates, and it should look like this:
codec2schema/example/bean.json
{
"$ref": "#/definitions/def",
"$schema": "https://json-schema.org/draft-07/schema",
"definitions": {
"def": {
"type": "object",
"properties": {
"type": {
"enum": [
"example:stringy_bean",
"example:counting_bean"
]
}
},
"required": [
"type"
],
"allOf": [
{
"if": {
"properties": {
"type": {
"const": "example:stringy_bean"
}
}
},
"then": {
"$ref": "#/definitions/def_1"
}
},
{
"if": {
"properties": {
"type": {
"const": "example:counting_bean"
}
}
},
"then": {
"$ref": "#/definitions/def_2"
}
}
]
},
"def_1": {
"type": "object",
"properties": {
"stringy_bean": {
"type": "string"
}
},
"required": [
"stringy_bean"
]
},
"def_2": {
"type": "object",
"properties": {
"counting_number": {
"type": "integer",
"minimum": -2147483648,
"maximum": 2147483647
}
},
"required": [
"counting_number"
]
}
}
}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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Using Schemas with IDEs
What you need to do depends on the software you are using.
With everything set up correctly, autocomplete will kick in and make things much easier. Once you get used to this, you will never be able to go back to looking up the JSON format every single time you want to change something.