Annotate enums in list with code-names

I was reading up on --allow-enum-conflicts, while trying to resolve the following when emitting c header files:

Warning: the following symbols have been suppressed due to a
conflict with an enum or bit with the same mapped name but a different value:
‘OTHER’, ‘UNKNOWN’.
Use tailf:code-name on the conflicting enums, bits, or nodes
to avoid the conflict.

I cannot modify the original yang module. Do I need to add an annotate for every leaf that uses the conflicting enums?

 module module-d {
     yang-version "1";
 
     namespace "urn:params:xml:ns:yang:project:m-d";
     prefix m-d;
 
     typedef module-d-type {
         type enumeration {
             enum OTHER { value 1; }
             enum UNKNOWN { value 0; }
         }
     }
 
     typedef module-d-type2 {
         type enumeration {
             enum OTHER { value 2; }
             enum UNKNOWN { value 3; }
         }
     }
 
     grouping module-d-grouping {
         container module-d-container {
             list module-d-list {
                 key module-d-leaf;
 
                 leaf module-d-leaf { type uint8; }
                 leaf object-b {  type string;  }
                 leaf object-c {  type module-d-type; }
                 leaf object-d {  type module-d-type2;  }
             }
         }
     }
 
     grouping module-d2-grouping {
         leaf module-d-container {  type uint32;  }
     }
 }
...
pyang tree:
...
 module: module-a
   +--rw container-a
      +--rw container-b
         +--rw object-b?             uint8
         +--rw module-b-container
         |  +--rw module-b-list* [module-b-leaf]
         |  |  +--rw module-b-leaf    uint8
         |  |  +--rw object-b?        string
         |  +--rw module-d-container
         |     +--rw module-d-list* [module-d-leaf]
         |        +--rw module-d-leaf    uint8
         |        +--rw object-b?        string
         |        +--rw object-c?        module-d-type
         |        +--rw object-d?        module-d-type2
         +--rw module-c-container
            +--rw module-c-list* [module-c-leaf]
            |  +--rw module-c-leaf    uint8
            |  +--rw object-b?        string
            |  +--rw object-c?        module-c-type
            +--rw module-d-container?   uint32

This is what I’ve tried in my annotation file, but confdc gives me errors:

module module-d-ann {
    yang-version "1";

    namespace "urn:params:xml:ns:yang:project:m-d-ann";
    prefix m-d-ann;

    import tailf-common {
        prefix tailf;
    }
    import module-a {
        prefix m-a;
    }

    tailf:annotate /m-a:container-a/m-a:container-b/m-a:module-b-container/m-a:module-d-container {
        tailf:callpoint container-d-handler {
            tailf:transaction-hook subtree;
        }
    }

    tailf:annotate /m-a:container-a/m-a:container-b/m-a:module-c-container/m-a:module-d-container {
        tailf:callpoint container-d2-handler {
            tailf:transaction-hook subtree;
        }
    }

    tailf:annotate-module "module-d" {
        tailf:annotate-statement "grouping[name='module-d-grouping']" {
            tailf:annotate-statement "container [name='module-d-container']" {
                tailf:annotate-statement "list[name='module-d-list']" {
                    tailf:annotate-statement "leaf[name='object-d']" {
                        tailf:annotate-statement "enum[name='OTHER']" {
                            tailf:code-name "m-d-type2-OTHER";
                        }
                        tailf:annotate-statement "enum[name='UNKNOWN']" {
                            tailf:code-name "m-d-type2-UNKNOWN";
                        }
                    }
                }
            }
        }
    }
}
confdc -c --include-doc --fail-on-warnings --strict-yang --yangpath ../yang -a ../ann/module-a-ann.yang -a ../ann/module-b-ann.yang -a ../ann/module-c-ann.yang -a ../ann/module-d-ann.yang ../yang/module-d.yang 
../ann/module-d-ann.yang:14: error: node 'module-d-container' not found
../ann/module-d-ann.yang:20: error: node 'module-d-container' not found
../yang/module-b.yang:7: error: circular dependency for module 'module-d'
../yang/module-c.yang:7: error: circular dependency for module 'module-d'

You do not need to import the YANG module that you are annotating from the annotation file. Also, note that the tailf:annotate-module/statement annotates the YANG model, not the resulting schema as tailf:annotate does.

So the tailf:annotate-module part should be something like this:

module module-d-ann {
  namespace "urn:params:xml:ns:yang:project:m-d-ann";
  prefix m-d-ann;

  import tailf-common {
    prefix tailf;
  }

  revision 2022-04-06 {
    description
      "Initial revision";
  }
  tailf:annotate-module "module-d" {
    tailf:annotate-statement "typedef[name='module-d-type2']" {
      tailf:annotate-statement "type[name='enumeration']" {
        tailf:annotate-statement "enum[name='OTHER']" {
          tailf:code-name "m-d-type2-OTHER";
        }
      }
    }
    tailf:annotate-statement "typedef[name='module-d-type2']" {
      tailf:annotate-statement "type[name='enumeration']" {
        tailf:annotate-statement "enum[name='UNKNOWN']" {
          tailf:code-name "m-d-type2-UNKNOWN";
        }
      }
    }
  }
}

Won’t that break my callpoint annotates, that need to know the path?

I think I’ve worked around this by having a “module-a-ann.yang” that contains all my callpoint annotations, and keeping the enum annotations within the “module-d-ann.yang”.