Calling JsonSchemaData#toConnectSchema() on a JSON schema that does not contain allOf still results in the error message Unsupported criterion allOf for {"description":"We'll assume it's a money if it has 'amount' and 'currency' by default; but you can specify this property should you wish to.","const":"money","type":"string"}.
To reproduce:
Put the schema into Schema Registry:
curl -L https://app.logary.tech/schemas/logary-message.merged.schema.json --silent >schema.json
echo "{}" | jq --arg schema "$(cat schema.json)" '{ schema: $schema, schemaType: "JSON" }' >tmp.json
curl -H "Accept: application/vnd.schemaregistry.v1+json, application/vnd.schemaregistry+json, application/json" -i http://localhost:8081/subjects/messages-value/versions -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data @tmp.json
Run the following on the latest Schema Registry version:
import com.google.common.collect.ImmutableList;
import io.confluent.connect.json.JsonSchemaData;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider;
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
import io.confluent.kafka.schemaregistry.client.rest.RestService;
import io.confluent.kafka.schemaregistry.json.JsonSchema;
import io.confluent.kafka.schemaregistry.json.JsonSchemaProvider;
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider;
import java.util.Collections;
public class JsonSchemaTest {
public static void main(final String[] args) throws Exception {
final SchemaRegistryClient srClient = new CachedSchemaRegistryClient(
new RestService("http://localhost:8081"),
1000,
ImmutableList.of(
new AvroSchemaProvider(), new ProtobufSchemaProvider(), new JsonSchemaProvider()),
Collections.emptyMap(),
Collections.emptyMap()
);
final ParsedSchema schema = srClient.getSchemaBySubjectAndId("messages-value", 1);
final JsonSchemaData jsonData = new JsonSchemaData();
jsonData.toConnectSchema((JsonSchema) schema);
}
}
Observe the error message:
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported criterion allOf for {"description":"We'll assume it's a money if it has 'amount' and 'currency' by default; but you can specify this property should you wish to.","const":"money","type":"string"}
at io.confluent.connect.json.JsonSchemaData.allOfToConnectSchema(JsonSchemaData.java:1005)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:870)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:805)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:801)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:937)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:805)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:942)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:895)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:805)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:942)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:805)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:801)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:937)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:805)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:942)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:895)
at io.confluent.connect.json.JsonSchemaData.toConnectSchema(JsonSchemaData.java:794)
(This issue was reported by a ksqlDB user in https://github.com/confluentinc/ksql/issues/6522.)
The JSON Schema library that we're using treats {"const":"money","type":"string"} as an implicit allOf.
Hi @rayokota , thanks for explaining this behavior. Are there any workarounds at this time for users to be able to parse these types of JSON schemas with the Schema Registry JSON converter, or is the only option to remove the use of const strings in the schema itself?
@vcrfxia This is now fixed via #1675
Whoa, awesome! Thanks for super quick fix, @rayokota :)
Most helpful comment
@vcrfxia This is now fixed via #1675