Guaranteeing NewDefinition() initialization of Definitions
@@ -78,3 +78,17 @@ func (r *FileSystemRepository) parseDefinition(apiDef []byte) definitionList {
func (d *definitionList) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &d.defs)
}
+
+// UnmarshalJSON api.Definition JSON.Unmarshaller Implementation
+func (d *Definition) UnmarshalJSON(b []byte) error {
+ //Aliasing Definition to avoid recursive call of this method
+ type DefinitionAlias Definition
+ defAlias := DefinitionAlias(*NewDefinition())
+
+ if err := json.Unmarshal(b, &defAlias); err != nil {
+ return err
+ }
+
+ *d = Definition(defAlias)
+ return nil
+}
