[YANGTOOLS-257] generated builder java file for a leaf containing a union needs documentation for why it's stored in src/main/java Created: 09/Aug/14  Updated: 10/Apr/22  Resolved: 14/Oct/14

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Colin Dixon Assignee: Ladislav Borak
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Mac OS
Platform: PC


External issue ID: 1512

 Description   

This is a shortened example from the TTP repo.

If you have YANG like this:

...
list parameters {
...
leaf default {
type union

{ type string; type uint32; }

}
...
}
...

The DefaultBuilder.java winds up being stored in src/main/java instead of the configured directory.

The same thing happens with PortNumberBuilder.java in controller. Which is generated to opendaylight/md-sal/model/model-flow-base/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/flow/types/port/rev130925/PortNumberBuilder.java

While it's counterparts are generated to opendaylight/md-sal/model/model-flow-base/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/...



 Comments   
Comment by Colin Dixon [ 12/Aug/14 ]

After talking to Devin Avery and Tom Pantelis, I think that this isn't a bug in that it's placed in the wrong location, but rather a bug in that the reason that it's placed here isn't properly conveyed.

Ideally, this generate class's functionality would be automated, but in the meantime a comment needs to be added to explain that the person creating the model needs to add code, what that code needs to do, and what happens if they don't.

Comment by Maros Marsalek [ 14/Aug/14 ]

The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation. In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).

The reason behind putting it under src/main/java is:
This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent loss of user code.

I agree with you, that a comment should be added to such classes.

Comment by Colin Dixon [ 14/Aug/14 ]

(In reply to Maros Marsalek from comment #2)
> The purpose of generated class in src/main/java for Union types is to create
> new instances of unions from a string representation. In some cases it is
> very difficult to automate it since there can be unions such as (uint32 -
> uint16), or (string - uint32).

The YANG spec actually says the correct thing to do here is to use the first listed type in the union for which it can be correctly interpreted.

"When a string representing a union data type is validated, the string is validated against each member type, in the order they are specified in the "type" statement, until a match is found."

From here: http://www.yang-central.org/twiki/pub/Main/YangDocuments/rfc6020.html#rfc.section.9.12

I think we should be able to do this automatically, but I may be wrong.

Comment by Ladislav Borak [ 15/Aug/14 ]

proposed patch: https://git.opendaylight.org/gerrit/#/c/9952/

Please create new enhancement for your last comment.

Generated at Wed Feb 07 20:52:42 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.