Add support for nested schema objects

Fix a bug when using type reference in nested schemas. 

Add a test for such scenario.

Including distribution changes for this and previous merge.