php-kafka / php-avro-schema-generator

PHP avro subschema merger and experimental PHP Class avro schema generator
BSD 3-Clause "New" or "Revised" License
5 stars 5 forks source link

Exclude namespace in type and items #10

Closed bajdzun closed 2 years ago

bajdzun commented 2 years ago

When we parse schema that has the embedded schema and their namespaces are the same, currently namespace will exist in type when schema is merged, but if you parse that merged schema and send it to the schema registry, AvroSchema::parse($definition) will exclude that namespace from type.

Example:

Root root.level.entity.schema-value.avsc

{
  "type": "record",
  "name": "schema",
  "namespace": "root.level.entity",
  "schema_level": "root",
  "fields": [
    {
      "name": "rootField1",
      "type": "root.level.entity.embeddedSchema"
    },
    {
      "name": "rootField2",
      "type": ["null","root.level.entity.embeddedSchema"],
      "default": null
    }
  ]
}

Embedded root.level.entity.embeddedSchema.avsc

{
  "type": "record",
  "name": "embeddedSchema",
  "namespace": "root.level.entity",
  "fields": [
    {
      "name": "embeddedField",
      "type": ["null","string"],
      "default": null
    }
  ]
}

When this kind of schema is merged it will result in having "type": "root.level.entity.embeddedSchema" but when parsed and sent to the registry it will have "type": "embeddedSchema"

I guess that this should be a part of --optimizeSubSchemaNamespaces option since it also excludes namespaces

@nick-zh what do you think?

nick-zh commented 2 years ago

sounds good to me, thx for this addition :v: