-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fixing bugs related to avro model processing: #582
Fixing bugs related to avro model processing: #582
Conversation
- Nested models - Schemas without definitions - Small documentation fixes
✅ Deploy Preview for springwolf-ui canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to Springwolf. Thanks a lot for creating your first pull request. Please check out our contributors guide and feel free to join us on discord.
springwolf-examples/springwolf-kafka-example/src/main/avro/ExamplePayloadAvroDto.avsc
Outdated
Show resolved
Hide resolved
Hi @raphaeldelio, thanks for your PR. Could you provide a test case in core (ideally a unit test) that illustrates the problem? It is unclear for me, which problem the reversing resolves. Where does the error happen when the schemas "do not find themselves"? |
Hey @sam0r040, I'm not sure how I can test it without the Avro dependency. Maybe you can help me if I elaborate better on the issue. I changed the Avro message to be a nested message. Before, we had only an If you remove the reversing part of the code and run the tests, you will see two tests fail: This is because, the registerSchema function will start by reading all the schemas. In this case, it will start by reading first After that, we preProcess the schemas and put them all in The problem starts during the postProcessor. In the post processing part, we will process each schema at a time, starting from the first in the LinkedHashMap (AnotherPayload). First, we run the AvroPostProcessor. That's fine. It will work on the AnotherPayload and will remove the avro properties from that schema and also remove all schemas coming from Now, it comes to the second post processor, ExampleGeneratorPostProcessor. Bear in mind that we're processing the first object from the LinkedHashMap (AnotherPayload). During the ExampleJsonGenerator, it will eventually fall into:
This will find the And now it becomes a problem because
This exception is thrown and it won't finish building the example for This can be tested by removing the reversing part. You will see that tests will fail because the example part will be missing from the result JSON: And this error will be thrown:
You can see that the error above occurred while generating the example for AnotherPayloadAvroDto. AnotherPayloadAvroDto doesn't have the property So, if we invert the order, ExamplePayload will be processed first and its Schema and SpecificData will be removed. Then, the post-processor will run on the outer object, which is AnotherPayload and so on in case there were multiple nested objects. From inside out. |
…emoved the current schema Example: an avro schema is removed. Then the next post-processor (example generator) does not need to be called. Also, it avoids the error message due to unresolvable avro schemas
Hi @raphaeldelio , thank you for the detailed explanation. I fixed the issue that already removed (avro) schemas are still being processed in #593 Still, I like to keep your adjustment of the example project (avro, dto + asyncapi.json) as this provides a better test case and avoids regressions. I opened raphaeldelio#1. |
…ling Feat/improve post processor handling
@timonback looks good! I merged your changes into this PR. Thank you. I hope my analysis was helpful. |
@raphaeldelio Yes indeed, the analysis was very helpful. |
When a custom record references another custom record, we need to reverse the order so that we post-process the inner records first.
Even though the schemas are removed from the definitions, they are still processed and throw an error when they don't find themselves in the definitions.
I added comments to the code to make it easier to spot the changes. They can be removed. I'm not sure if I'm following the correct coding styles or if this operation of reversing the LinkedHashMap would be ideal here. Let me know if I can enhance it further.