OpenApi: Add missing required elements to JSON 35/106635/3
authorPeter Suna <peter.suna@pantheon.tech>
Fri, 23 Jun 2023 06:12:45 +0000 (08:12 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 23 Jun 2023 12:30:12 +0000 (12:30 +0000)
commit1bc8dd109531bee9b98495c2ca91c086a8c292d4
treed4edf51be5e6ce0e1f5dcceb5466f8e44be9ccdd
parent7802f61128acc20b87026cae66b44c06dad2684d
OpenApi: Add missing required elements to JSON

This commit adds missing mandatory nodes to the required
field of the JSON OpenApi data. According to RFC-7950, a node
is mandatory if it is:
A leaf, choice, anydata, or anyxml node with a "mandatory"
statement with the value "true".

See:
https://www.rfc-editor.org/rfc/rfc7950#page-14

The only exception for this patch is the 'choice' node.
If the 'choice' node is mandatory, we cannot require the
'choice' or 'case' name in the body.

Additionally, nodes inside the 'case' should only be required
if they are mandatory.

JIRA: NETCONF-976
Change-Id: I3d1220737a582b27163a9ff8f33ceee1edb94c87
Signed-off-by: Peter Suna <peter.suna@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
(cherry picked from commit 08d93cab539d7abbe045a87ba415a8a1b81637e7)
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/netconf/sal/rest/doc/impl/ApiDocGeneratorRFC8040Test.java
restconf/sal-rest-docgen/src/test/resources/yang/mandatory-test.yang [new file with mode: 0644]