If you've created your own class that extends Codec or MapCodec, Codec2Schema will have no idea what to do with it. To prevent things from not working, you'll need to register a codec handler.
Below is a simplified version of the codec handler for ListCodecs.
java
public class ListCodecHandler implements CodecHandler<ListCodec<?>> {
public static boolean predicate(Codec<?> codec) {
return codec instanceof ListCodec<?>;
}
@Override
public JsonObject toSchema(ListCodec<?> codec, SchemaContext context, SchemaContext.DefinitionContext definitionContext) {
JsonObject json = new JsonObject();
json.addProperty("type", "array");
json.add("items", context.requestDefinition(codec.elementCodec()));
json.addProperty("minItems", codec.minSize());
json.addProperty("maxItems", codec.maxSize());
return json;
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Don't worry about definitionContext, even I only used it, like, twice to prevent infinite loops caused by recursive nonsene. You'll probably never use it.
This would be registered like so, in the registerHandlers method of your Codec2SchemaPlugin:
java
CodecHandlerRegistry.register(ListCodecHandler::predicate, ListCodecHandler::new);1
TIP
Handlers registered first have higher priority. If you need to override behaviour from Codec2Schema or another mod, implement the earlyRegisterHandlers method instead.
INFO
MapCodecHandlers should be registered using MapCodecHandlerRegistry.