diff --git a/source/dub/dependency.d b/source/dub/dependency.d index 2c3a3d9..315ff52 100644 --- a/source/dub/dependency.d +++ b/source/dub/dependency.d @@ -259,8 +259,11 @@ json = Json(this.versionSpec); } else { json = Json.emptyObject; - json["version"] = this.versionSpec; - if (!path.empty) json["path"] = path.toString(); + if (!path.empty) { + json["path"] = path.toString(); + } else { + json["version"] = this.versionSpec; + } if (!repository.empty) json["repository"] = repository.toString; if (!selections && optional) json["optional"] = true; if (!selections && default_) json["default"] = true; @@ -285,6 +288,12 @@ assert(dependency.toJson() == expected, "Failed: " ~ dependency.toJson().toPrettyString()); } + @trusted unittest { + Dependency d = Dependency(NativePath("dir")); + Json expected = Json([ "path": Json("dir") ]); + assert(d.toJson() == expected, "Failed: " ~ d.toJson().toPrettyString()); + } + /** Constructs a new `Dependency` from its JSON representation. See `toJson` for a description of the JSON format.