pyang-json-schema-plugin icon indicating copy to clipboard operation
pyang-json-schema-plugin copied to clipboard

Stricter schema?

Open andreasjakobik opened this issue 6 years ago • 0 comments

Hello,

The generated JSON schema is allowing additional properties from what is defined in the Yang module and key leafs are not required. How about making the schema more strict to catch these things? See example below.

Thanks, Andreas

The following yang

container container-a { list list-a { key "key"; leaf "key" { type string; } leaf "message" { type string; } } }

translates to: "hello2:container-a": { "type": "object", "properties": { "list-a": { "items": [ { "key": { "type": "string" } }, { "message": { "type": "string" } } ], "type": "array" } } } }

However, something like the following seems more appropriate:

"container-a": { "$id": "/properties/hello2:container-a", "type": "object", "properties": { "list-a": { "$id": "/properties/hello2:container-a/properties/list-a", "type": "array", "items": { "$id": "/properties/hello2:container-a/properties/list-a/items", "type": "object", "properties": { "key": { "$id": "/properties/hello2:container-a/properties/list-a/items/properties/key", "type": "string" }, "message": { "$id": "/properties/hello2:container-a/properties/list-a/items/properties/message", "type": "string" } }, "required": ["key"], "additionalProperties": false } } } }

Note also that the contents of list is mapped to one object instead of several objects with one statement each.

andreasjakobik avatar Mar 19 '18 15:03 andreasjakobik