-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add RFC7951JSONConfig.PrependModuleNameNonRootTopLevel
flag
#648
Open
wenovus
wants to merge
1
commit into
master
Choose a base branch
from
prepend-nonroot-toplevel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,6 +916,14 @@ type RFC7951JSONConfig struct { | |
// elements that are defined within a different YANG module than their | ||
// parent. | ||
AppendModuleName bool | ||
// PrependModuleNameNonRootTopLevel specifies that the top-level field | ||
// names of a non-root ValidatedGoStruct being marshalled should always | ||
// have their belonging-module names prepended in the JSON output, | ||
// instead of only being present when its namespace differs from the | ||
// namespace of its parent. | ||
// NOTE: This flag is used to preserve [email protected] behaviour in | ||
// code that depends on it. This will be deprecated in the future. | ||
PrependModuleNameNonRootTopLevel bool | ||
// PrependModuleNameIdentityref determines whether the module name is | ||
// prepended to identityref values. AppendModuleName (should be named | ||
// PrependModuleName) subsumes and overrides this flag. | ||
|
@@ -951,7 +959,11 @@ func (*RFC7951JSONConfig) IsMarshal7951Arg() {} | |
// to JSON described by RFC7951. The supplied args control options corresponding | ||
// to the method by which JSON is marshalled. | ||
func ConstructIETFJSON(s ValidatedGoStruct, args *RFC7951JSONConfig) (map[string]interface{}, error) { | ||
return structJSON(s, s.ΛBelongingModule(), jsonOutputConfig{ | ||
var parentMod string | ||
if args == nil || !args.PrependModuleNameNonRootTopLevel { | ||
parentMod = s.ΛBelongingModule() | ||
} | ||
return structJSON(s, parentMod, jsonOutputConfig{ | ||
jType: RFC7951, | ||
rfc7951Config: args, | ||
}) | ||
|
@@ -1001,8 +1013,10 @@ func Marshal7951(d interface{}, args ...Marshal7951Arg) ([]byte, error) { | |
} | ||
} | ||
var parentMod string | ||
if s, ok := d.(ValidatedGoStruct); ok { | ||
parentMod = s.ΛBelongingModule() | ||
if rfcCfg == nil || !rfcCfg.PrependModuleNameNonRootTopLevel { | ||
if s, ok := d.(ValidatedGoStruct); ok { | ||
parentMod = s.ΛBelongingModule() | ||
} | ||
} | ||
j, err := jsonValue(reflect.ValueOf(d), parentMod, jsonOutputConfig{ | ||
jType: RFC7951, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be
SkipPrependModNameAtRoot
or something - since I think by default we want to have the fixed behaviour (I think?). That being said, I'm OK with leaving it this way which is 'safer' but means that users need to do something to avoid the bug (which seems undesirable).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.
Since the flag is by default false I'm interpreting the "default" to be not prepending, which is the standard behaviour. Sorry is the naming a bit confusing?
I agree that since the default ygot behaviour is nonstandard, I see this closer to a bug fix rather than an API improvement. So I also support putting the nonstandard behaviour behind the flag.
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.
Yes -- sorry, I misinterpreted the naming of the flag.
PrependXXX
with a defaultfalse
makes sense to me. I'm OK with this change -- and just add to the release notes that we resolved this bug.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.
So - sorry - we need to change the name here to
SkipXXX
rather thanPrependXXX
I believe.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.
Ok, so if it's
SkipXXX
doesn't that mean by default we don't skip, and that means the module name is still there as before?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.
Hah - we're tying ourselves in knots here.
Explicitly:
SkipPrependModuleNameNonRootTopLevel
- default false - means don't skip prepending it, which means we do add it (i.e., default is fixed behaviour).PrependModuleNameNonRootTopLevel
- default false - means don't prepend it, which means we leave the output unchanged.The 2nd option is the "safe" one whereby users do not see a default change. We agreed (I think) that this is not preferable because this is a bug, not a feature being added.
The former option is one where users that want the buggy behaviour need to explicitly opt-in, which seems to be what we agree on. Hence my preference for the 'Skip' option.
That being said - let's make the flag really clear - and we can just say
OmitModuleNameForTopLevelEntity
. In this case,Omit...
being false means that it is not omitted (i.e., it is added).I suggest a comment like:
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.
Ok, so the fixed behaviour to me is when we DON'T prepend the module name. The output is changed. Currently, we prepend module names for non-root top-level names unconditionally, the fixed behaviour is to only prepend when the name resides in a different namespace than the parent.
So, I'm still thinking it should be
PrependModuleNameNonRootTopLevel
.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.
Hmm...
So this made me go back and look at the specification again. In RFC7951 section 4:
So, in this case, my interpretation is that the top-level object does have to contain all the namespace qualification, because this says "do it at the top-level AND then only append the module if the node is in the same namespace as the parent".
This makes me think we should just revert the previous change. For some reason I was misremembering what the defect was originally.
What was the context for originally opening #637 -- since it seems the user in that bug here has the opposite problem.
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.
I think the crux of the issue is what is meant by
all members of a top-level JSON object
, and specifically what is atop-level JSON object
.We have two competing interpretations:
Now, if 1. were the correct interpretation, then I am confused by how
top-level JSON object
refers to any JSON object.Now, if 2. were the correct interpretation, then "top-level" means the top-level of the YANG hierarchy, which while not crystal clear, is acceptable IMO; also, by "members", it means the top-level, or immediate members of a JSON object, which also while not crystal clear, is also acceptable IMO.
Thus, I think 2. makes more sense than 1, and so I'm thinking the fix was correct.
I agree that the user's bug comment was confusing, I did try to clarify to the user in my subsequent comment. The reason this bug was filed was actually from somebody else complaining about too much prepending, I've sent you the link to that offline.
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.
Thanks for the explanation here -- I actually think the original bug report is wrong :-), and that (1) in your example is correct.
I dug around and looked at rfc8040 (restconf) which has some examples of a
GET
being done at a non-root path in its appendix here.In this case, the resource being requested is
GET /restconf/data/ietf-yang-library:modules-state
--modules-state
is a non-root-level container defined mode here: https://github.com/YangModels/yang/blob/main/vendor/cisco/xe/1681/ietf-yang-library.yang#L205 which does have its name prepended, some of the other examples (e.g., thisPOST
example also uses the module name for a non-root level entity.My view is that we should revert the change that was made to changes this functionality. Somehow I interpreted this incorrectly before - apologies.