Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator: nested record types generated incorrectly #52

Open
Hubbitus opened this issue Jan 9, 2022 · 7 comments
Open

Generator: nested record types generated incorrectly #52

Hubbitus opened this issue Jan 9, 2022 · 7 comments

Comments

@Hubbitus
Copy link
Contributor

Hubbitus commented Jan 9, 2022

Said run your example of generation we got output schema PhpKafka.PhpAvroSchemaGenerator.Example.SomeTestClass.avsc (part):

    {
      "name": "someOtherTestClass",
      "type": "PhpKafka.PhpAvroSchemaGenerator.Example.SomeOtherTestClass"
    },
    {
      "name": "someOtherTestClasses",
      "type": {
        "type": "array",
        "items": "PhpKafka.PhpAvroSchemaGenerator.Example.SomeOtherTestClass"
      }
    },
    {
      "name": "blaaaaaaaa",
      "type": [
        "int",
        "string"
      ]
    },
    {
      "name": "unicorn",
      "type": "PhpKafka.PhpAvroSchemaGenerator.Example.Wonderland"
    }

Which is incorrect!
AVRO does not have types like PhpKafka.PhpAvroSchemaGenerator.Example.Wonderland!

In your example it is not very representative, because no any inner classes have fields, but said if Wonderland will have single field like:

**                                                                                                                                                                                                                                                                           
* Country of miracles
**/
class Wonderland                                                                                                                                                                                                                                                              
{                                                                                                                                                                                                                                                                             
    private string $land;                                                                                                                                                                                                                                                     
}

That generated part instead of

    {
      "name": "unicorn",
      "type": "PhpKafka.PhpAvroSchemaGenerator.Example.Wonderland"
    }

should look like:

{
  "name": "unicorn",
  "type": "record",
  "doc": "Country of miracles",
  "fields": [
    {
      "name": "land",
      "type": "string"
    }
  ]
}
@nick-zh
Copy link
Member

nick-zh commented Jan 9, 2022

This project contains a schema merger, this helps you split up your schema in sub schemas to have a better overview.
So the generator as well will create templates that you can merge which will result in the outcome you posted last ✌️

@Hubbitus
Copy link
Contributor Author

Hubbitus commented Jan 9, 2022

But generated schemas should be correct? An example may show how to create templates and schemes...

Could you please provide an example of what I should call after:

$schemas = $generator->generate();
$generator->exportSchemas($schemas);

To get correct AVRO schemes?

@nick-zh
Copy link
Member

nick-zh commented Jan 9, 2022

Just to elaborate a bit more, let's say you have a class:

class User {
  public Location $location;
}

class Location {
  public string street;
  etc.
}

Then generate will create two templates:

  • a user template with a reference to location
  • a location schema template

Merge will unify that, but this way you will not be overwhelmed if you have complicated schema.
You can find example how to merge your templates here
Basically just pass the output directory of generate, and it will merge your generated templates into proper schema.
Hope this helps ✌️

@Hubbitus
Copy link
Contributor Author

Hubbitus commented Jan 9, 2022

So, essentially $schemas = $generator->generate(); generates templates and not schemas?

@nick-zh
Copy link
Member

nick-zh commented Jan 9, 2022

That is correct
Edit: I updated the readme, to make this a bit more clear

@Hubbitus
Copy link
Contributor Author

Hubbitus commented Jan 9, 2022

Very contr-intuitive on my mind.
I think at least extending examples with comments and full procedure to get correct schemes would be very helpful

@nick-zh
Copy link
Member

nick-zh commented Jan 9, 2022

I totally agree, i should have probably added an example which does both in one go.
The initial generator was not so good, so manual adjustment was needed, but with your input and contributions, the generator has improved a lot. It would be ok, to generate & directly merge now ✌️

I should probably also add cli examples in the examples folder 😄

@nick-zh nick-zh mentioned this issue Jan 9, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants