apache / rocketmq-schema-registry

Apache RocketMQ Schema Registry
https://rocketmq.apache.org/
31 stars 20 forks source link

Storage should adapt to all schema idl types #57

Closed humkum closed 2 years ago

humkum commented 2 years ago

For example, in org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse.java , the method parse(String schemaIdl) use Schema schema = new Schema.Parser().parse(schemaIdl); to parse schemaIdl, it should adapt to all kind of schema.

private List<Field> parse(String schemaIdl) {
        Schema schema = new Schema.Parser().parse(schemaIdl);
        return schema.getFields().stream().map(field -> {
            String type = field.schema().getType().getName();
            // ["null", "double"] represent this field is nullable
            if (field.schema().isUnion() && field.schema().getTypes().size() == 2) {
                type = field.schema().getTypes().get(1).getName();
            }
            String defaultVal = field.hasDefaultValue() ? field.defaultVal().toString() : "null";
            return Field.builder()
                    .pos(field.pos())
                    .name(field.name())
                    .type(type)
                    .comment(field.doc())
                    .isNullable(field.schema().isNullable())
                    .defaultValue(defaultVal)
                    .sortType(field.order().name())
                    .extra("")
                    .build();
        }).collect(Collectors.toList());
    }