Week 2: Establishing the Fundamentals

📅 May 24 - June 1
What I Planned to Do
Invoke
getRepresentationDescription()and parse the property object to get detailed info about each attributeCollect those attributes and package them in a basic JSON schema
Try to work on the edge cases that gets missed in some of the resource classes
What I Worked On
This week, I wanted to build upon the foundation I had created with the maven plugin which capsulates getting some kind of property returned from the resource class
I had a 1:1 with Chi Bong and we went in depth about various agendas, and I discussed everything I had proposed in my GSoC proposal and how to move forward with it
For my first major objective, I was asked to invoke the method that decides what representation returns what properties in each class which was
getRepresentationDescription().This class is very tricky in the sense that it calls the
RestConstantsclass which has static initialization inside it and required context that it gets during runtimeBut as this project was supposed to run during build time it isn’t afforded the luxury to have that, so my time went in trying to find a way to make that work
I want to go deeper in how my initial version of my plugin works which I detail below
For the plugin, we start with a URLClassLoader which loads all the classes and resources which are compiled already and kept in the
target/classesdirectory of each omod moduleThis includes all the resource classes, important dependencies and various classes like Representation
And this class loader is hierarchical and isolated from the plugin’s own class loader to avoid conflicts, and can be used independently of it, which is very useful when we want to inspect or load classes compiled in other Maven modules
I use reflection in my plugin to scan a particular resource class, for now I have hardcoded it to find the particular resource for simplicity and making the proof-of-concept work
It then further uses reflection to find the
getRepresentationDescription()method and ready to be invokedHere, we can invoke the no-arg constructor of the resource class and make an instance to invoke the method and get its return values, which proved to be tricky as it depended on context that wasn’t available
I used a method in which we use unsafe allocation to instantiate the resource object without calling the constructor with the
sun.misc.UnsafelibraryBut this approach was very primitive and it didn’t align with the goal to have a robust and proper method to get the properties so I went back from this
I then went back to trying with the no-args constructor method and after lot of trial and errors I got it running, but it still wasn’t able to return proper values for the default representation of the Patient resource
After careful debugging and mentor help, I noticed that the code was trying to invoke
RestUtilsclass which was trying to access a static context which crashed the whole process, and commenting it out and running the plugin worked wonderfully!But the other resource classes like
ConceptResourceandPersonResourcecouldn’t run even with this adjustment and trial and error kept on going on until I find out how to maneuver through this
Challenges Faced
Invoking
getRepresentationDescription()with the resource instance fails and I have to debug and find the cause and solution that solves thisUnsafe allocation proved to be very brittle and (as the name suggests) dangerous and unsafe for production use
What I Learned
Learnt the concept of class loading and how hierarchical class loading works , and how the class loader interacts with it’s parent loaders
Learnt the use of reflection in more detail, in finding out the output directory where the classes and resources are compiled, finding the method, etc
Commits/PRs This Week
PR Title: Initial implementation of OpenAPI Generator Maven Plugin with JavaParser integration
Status:
Draft
Plans for Next Week
Invoke
getRepresentationDescription()using no-args constructor and return proper valuesClean up the class loader for any redundant classes or any old / primitive methods used
Try to find a way to bypass the context needs for the methods we are trying to invoke
Notes/Discussion Points
Want to be more descriptive and clearer in my implementation and experimentation of the maven plugin
I’ll be on a break from June 2 - June 13 owing to my college examinations which I have prior talked to my mentors and agreed on it
Thank you!




