{"action":"closed","issue":{"url":"https://api.github.com/repos/ict-strauss/COP/issues/1","labels_url":"https://api.github.com/repos/ict-strauss/COP/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/ict-strauss/COP/issues/1/comments","events_url":"https://api.github.com/repos/ict-strauss/COP/issues/1/events","html_url":"https://github.com/ict-strauss/COP/issues/1","id":113579266,"number":1,"title":"Swagger pyang plugin fails when \"uses\" statement is invoked inside a \"grouping\" statement","user":{"login":"grigio60","id":12816404,"avatar_url":"https://avatars.githubusercontent.com/u/12816404?v=3","gravatar_id":"","url":"https://api.github.com/users/grigio60","html_url":"https://github.com/grigio60","followers_url":"https://api.github.com/users/grigio60/followers","following_url":"https://api.github.com/users/grigio60/following{/other_user}","gists_url":"https://api.github.com/users/grigio60/gists{/gist_id}","starred_url":"https://api.github.com/users/grigio60/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grigio60/subscriptions","organizations_url":"https://api.github.com/users/grigio60/orgs","repos_url":"https://api.github.com/users/grigio60/repos","events_url":"https://api.github.com/users/grigio60/events{/privacy}","received_events_url":"https://api.github.com/users/grigio60/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-27T13:06:19Z","updated_at":"2015-11-06T08:07:03Z","closed_at":"2015-11-06T08:07:03Z","body":"Hello\r\n\r\nI have a set of yang modules where some basic and commonly used information is defined centrally as a grouping. This grouping is then recalled by other yang definitions through the \"uses\" statement.\r\n\r\nAccording to RFC6020, the \"uses\" statement can be used a sub-statement also inside a \"grouping\" statement, so allowing a flexible reuse. However, the swagger plugin aborts with an error when this is applied, although pyang validates the code without any errors nor warnings.\r\n\r\nThe sample code to reproduce the issue is split into different files:\r\n1. basic.yang includes the definition of the basic grouping\r\n2. complex.yang includes the \"uses\" of the basic grouping inside another \"container\"\r\n3. complex2.yang includes the \"uses\" of the basic grouping inside another \"groupin\".\r\n\r\nPyang validates successfully all three source files without error.\r\n1. *pyang basic.yang -f swagger -o basic.json*   executes successfully without errors\r\n2. *pyang complex.yang -f swagger -o complex.json*  executes successfully without errors\r\n3. *pyang complex2.yang .f swagger -o complex2.json* fails with the following messages:\r\n\r\n> Traceback (most recent call last):\r\n>  File \"c:/Python34/Scripts/pyang\", line 403, in <module> run\r\n  File \"c:/Python34/Scripts/pyang\", line 377, in run emit_obj.emit(ctx, modules, fd)\r\n  File \"c:\\Python34\\lib\\site-packages\\pyang/plugins\\swagger.py\", line 71, in emit \r\n    emit_swagger_spec(ctx, modules, fd, ctx.opts.path)\r\n  File \"c:\\Python34\\lib\\site-packages\\pyang/plugins\\swagger.py\", line 126, in emit_swagger_spec\r\n    gen_model(pending_models, definitions)\r\n  File \"c:\\Python34\\lib\\site-packages\\pyang/plugins\\swagger.py\", line 126, in gen_model\r\n    PARENT_MODELS[ref]['models'].append(child.arg)\r\nKeyError: 'CommonAttributes'\r\n\r\nNotice that \"commonAttributes\" is exactly the name of the grouping invoked inside another grouping (I tested the same sequence using a different name and the KeyError always returned consistently that name).\r\n\r\nRemoving all the \"uses\" statements inside all \"grouping\" definitions is not a viable work-around for real projects, especially as long as IETF- or other standard-based yang modules are involved.\r\n\r\nAdditional information:\r\nPython version (python -V): Python 3.4.3\r\nPyang version (pyang -v): pyang 1.5\r\n\r\nAttached the contents of the files used to reproduce the issue.\r\n\r\nbasic.yang:\r\n```yang\r\nmodule basic {\r\n\tnamespace \"urn:acme:yang:basic\";\r\n\tprefix \"basic\";\r\n\t\r\n\tgrouping commonAttributes {\r\n\t\tleaf my-id {\r\n\t\t\ttype uint8;\r\n\t\t}\r\n\t\tleaf my-name {\r\n\t\t\ttype string;\r\n\t\t}\r\n\t\tleaf my-status {\r\n\t\t\ttype boolean;\r\n\t\t\tconfig false;\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\ncomplex.yang:\r\n```yang\r\nmodule complex {\r\n\tnamespace \"urn:acme:yang:complex\";\r\n\tprefix \"complex\";\r\n\t\r\n\timport basic {\r\n\t\tprefix \"basic\";\r\n\t}\r\n\t\r\n\tgrouping myClass {\r\n\t\tleaf alpha {\r\n\t\t\ttype string;\r\n\t\t}\r\n\t\tleaf beta {\r\n\t\t\ttype uint8;\r\n\t\t}\r\n\t}\r\n\t\r\n\tcontainer myNode {\r\n\t\tlist subNodes {\r\n\t\t\tkey \"id\";\r\n\t\t\tleaf id {\r\n\t\t\t\ttype uint8;\r\n\t\t\t}\r\n\t\t\tuses myClass;\r\n\t\t}\r\n\t\tcontainer myChild {\r\n\t\t\tuses basic:commonAttributes;\r\n\t\t\tleaf gamma {\r\n\t\t\t\ttype boolean;\r\n\t\t\t}\r\n\t\t\tleaf delta {\r\n\t\t\t\ttype string;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\ncomplex2.yang:\r\n```yang\r\n    module complex2 {\r\n\t\tnamespace \"urn:acme:yang:complex2\";\r\n\t\tprefix \"complex\";\r\n\t\t\r\n\t\timport basic {\r\n\t\t\tprefix \"basic\";\r\n\t\t}\r\n\t\t\r\n\t\tgrouping myClass {\r\n\t\t\tuses basic:commonAttributes;       // OFFENDING STATEMENT\r\n\t\t\tleaf alpha {\r\n\t\t\t\ttype string;\r\n\t\t\t}\r\n\t\t\tleaf beta {\r\n\t\t\t\ttype uint8;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tcontainer myNode {\r\n\t\t\tlist subNodes {\r\n\t\t\t\tkey \"id\";\r\n\t\t\t\tleaf id {\r\n\t\t\t\t\ttype uint8;\r\n\t\t\t\t}\r\n\t\t\t\tuses myClass;\r\n\t\t\t}\r\n\t\t\tcontainer myChild {\r\n\t\t\t\tleaf gamma {\r\n\t\t\t\t\ttype boolean;\r\n\t\t\t\t}\r\n\t\t\t\tleaf delta {\r\n\t\t\t\t\ttype string;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n```\r\n\r\n\r\n"}}