-
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
Please create objects in the definition section to be used #1123
Comments
it's not really because of The additional problem is classes are moved around more likely chaotically rather than under your guidance, see #1107 for this. |
I suspect you're right and the "definitions" section is not being processed. However, I haven't dug into the code to confirm that. I will say, what you call a messy work around is actually my preferred organization. I've always defined one class, one struct, one schema per file and it just feels more natural to me than defining an entire data model in a single file (although I concede XML kind of endorsed that kind of behavior). That said, there are a few things I noticed about your schema:
|
When jsonschema2pojo was created, 'definitions' was not part of the standard. Many people started using 'definitions' to hold extra schemas but we didn't add support here because it was just a common pattern but not part of the standard. Now it has been brought into the standard I don't have a problem with adding support for it. Over the years a lot of people have expected it to work (and it appears that many people have a schema document with only definitions, and no root schema to reference them). I'd probably just bump to 1.1.x for this change. |
I'll take a look at it this weekend and try to get an implementation. I haven't tinkered in those parts of the code before, so I'm not sure what the LOE will be, but don't mind getting my hands dirty. That said, where do we envision the generated classes being generated?
I feel like inner class is the way to go because you could have multiple schema with definitions using the same name, defined in the same package. I'm not sure how the JSON schema treats that behavior, or whether it's allowed. I'm not sure the JSON schema even discusses how schemas should relate to one another when not referencing one another. If I generate them as inner classes, which makes the most sense to me, or in their own classes within the same package what should their visibility be?
I guess I'm putting forward the following suggesting and looking for input:
becomes
|
I don't think we should use inner classes, this pattern isn't used anywhere else. It also creates a more serious breaking change. I think these should go into whatever package is currently in context when we're processing the enclosing schema. |
I'll implement them as classes inside the current context, and make the assumption that they will not conflict with the "definitions" of another schema in that same context. IE I'm going to expect it to throw an exception if two schemas in the same context have competing definitions. |
@joelittlejohn I took a stab at implementing this on #1124 however the ExtendsIT unit test fails after my implementation because it looks like there's already a sub-implementation for definitions when the definition is referenced directly by an extends call from within the actual schema. Specifically, ExtendsIT has the following schema which processes with the current unit test.
My first stab at an implementation used the I'm hoping you can provide some insight as to the specifics of why the child identifies it's extension as For reference, the following PR is where my existing changes live: #1124 |
Hello everyody, is there a chance to get this done for 1.1.0 ? |
Any news on this, I have a file that looks like: {
"allOf": [
{
"$ref": "#/definitions/Check"
}
],
"definitions": {
"Check": {
"description": "The model for a Check",
"type": "object",
"required": [
"header"
],
"properties": {
}
EDIT: |
Is there any plan to implement the feature to force generation of unreferenced parts declared in the #definitions using a configuration? |
This would be useful for us, as it would allow us to generate Java classes from the definitions in a swagger/OAS2 specification (which I don't believe is possible otherwise, without moving all those definitions into separate files...) |
I would have thought the following would work:
But the MessageAttribute class is not created so the existingJavaType fails. I can work around this problem today in an ugly way but it would be nice for the above syntax to work. The ugly way is to move everything in the definitions section to another file as below:
message-attribute.json
message.json
The text was updated successfully, but these errors were encountered: