pydantify / pydantify

Transform YANG models into pydantic datastructures
https://pydantify.github.io/pydantify/
MIT License
72 stars 6 forks source link

YANG `choice` statements not working as expected #60

Open troymanchester opened 1 month ago

troymanchester commented 1 month ago

I am using pydantify via pydantic-srlinux.

What I'm seeing is that a choice statement in YANG is not being correctly reflected in the pydantic model. The YANG choice statement is resulting in a nested container field.

Here is JSON representation of what an SRLinux device wants:

"action": {
    "accept": {}
}

Here is what the pydantic model wants (in JSON representation):

"action": {
    "action": {
        "accept": {}
    }
}

Generated pydantic classes that illustrate this issue - there is an "action" field of type ActionContainer, and ActionContainer itself has an "action" field which has the choices. I'd expect that the model would not have nested "action" fields like this.

Apologies if this is the wrong place raise this - I am not 100% certain this is pydantify, this could be a problem w/ pyang or it could be an issue w/ the YANG files I'm using, but I'm not familiar enough w/ all the different pieces yet to determine where something is going wrong.

Breadcrumbs:

troymanchester commented 1 month ago

cc @hellt

hellt commented 1 month ago

paging also @dpeachey if he came across choices in his work. I think a YANG choice would/should be oneOf in JSON schema intermediary

ubaumann commented 1 month ago

Thanks for reporting this issue. I will try to reproduce the mistake and fix it.