-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
$ref doesn't work when ref'ed message also has extends #408
Comments
I don't seem to be able to replicate this at all, when I try the schemas you have provided, I get:
Is it possible your project hasn't been cleaned and that the generated types are out-of-date and don't match your schema? |
Is it possible that BasicMessage is marked final? |
BasicMessage is abstract. public abstract class BasicMessage { ... } Let me try to put together a simple test project so you can replicate. I'll get back to you. |
===UPDATE: SKIP TO THE NEXT COMMENT FOR A SMALLER REPLICATION PROJECT TO USE=== FWIW: here is what BasicMessage looks like: |
Ok, much smaller replication project. git clone [email protected]:jmazzitelli/test.git Look in "target/java-gen/org/abc" and see that AuthMessage.java and SimpleMessage.java both define classes that extend BasicMessage. Here are the schemas used: |
Here's another interesting thing - in my small project, comment out the dependency on the hawkular library (the one that pulls in BasicMessage) and run "mvn clean install" again. BasicMessage.java gets generated for you, but yet still both SimpleMessage and AuthMessage extend BasicMessage. |
I think I see the problem, but don't know how to fix. See org.jsonschema2pojo.rules.ObjectRule.getSuperType():
This in turn calls org.jsonschema2pojo.rules.SchemaRule.apply():
As I step through the code, I see this is parsing the SimpleMessage schema, and when it gets here the $ref is referring to AuthMessage.schema.json. SchemaRule will look it up, store AuthMessage schema in the "schema" variable at which point in time schema.getJavaType() returns "BasicMessage" and that is returned as the super type of SimpleMessage. Which is not right. It should be returning "AuthMessage" as the super type. I am stepping through the source code from version 0.4.14 |
Thanks for the detailed report here, it really helped track down this subtle issue. It's dependent on the order in which schemas are read so was difficult to replicate. |
I have one schema that extends another using $ref like this:
SimpleMessage.schema.json:
AuthMessage.schema.json:
As you see in the AuthMessage schema, I have my own org.abc.BasicMessage class that I want my AuthMessage to extend. I am expecting the generated java class declarations to look like this:
However, what really happens is they both extend BasicMessage:
It is quite possible I misunderstand how $ref is to work inside extends, but on its face, this looks like a bug. I have $ref referring to AuthMessage in my SimpleMessage schema, but SimpleMessage doesn't extend AuthMessage - it extends BasicMessage (which only AuthMessage should - SimpleMessage should extend AuthMessage). As it is generated now, SimpleMessage doesn't get any properties from AuthMessage (that is, SimpleMessage doesn't get setUsername() and setPassword() since it doesn't extend AuthMessage).
Hopefully, that made sense.
The text was updated successfully, but these errors were encountered: