Skip to content

Commit

Permalink
More Netkan validation for any_of
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 13, 2021
1 parent 241741f commit 3a8404e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Netkan/Validators/LicensesValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Validate(Metadata metadata)
{
if (licenses == null || licenses.Count < 1)
{
throw new Kraken("License should match spec. Set `x_netkan_license_ok` to suppress");
throw new Kraken("License should match spec");
}
else foreach (var lic in licenses)
{
Expand All @@ -48,7 +48,7 @@ public void Validate(Metadata metadata)
}
catch
{
throw new Kraken($"License {lic} should match spec. Set `x_netkan_license_ok` to suppress");
throw new Kraken($"License {lic} should match spec");
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion Netkan/Validators/RelationshipsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ public void Validate(Metadata metadata)
{
throw new Kraken("spec_version v1.26+ required for 'any_of'");
}
foreach (string forbiddenPropertyName in AnyOfRelationshipDescriptor.ForbiddenPropertyNames)
{
if (rel.ContainsKey(forbiddenPropertyName))
{
throw new Kraken($"{forbiddenPropertyName} is not valid in the same relationship as 'any_of'");
}
}
if (rel.ContainsKey("choice_help_text") && metadata.SpecVersion < v1p31)
{
throw new Kraken("spec_version v1.31+ required for choice_help_text in same relationship as 'any_of'");
}
foreach (JObject opt in rel["any_of"])
{
string name = (string)opt["name"];
if (!Identifier.ValidIdentifierPattern.IsMatch(name))
{
throw new Kraken($"{name} in {relName} any_of is not a valid CKAN identifier");
throw new Kraken($"{name} in {relName} 'any_of' is not a valid CKAN identifier");
}
}
}
Expand All @@ -54,5 +65,6 @@ public void Validate(Metadata metadata)
"supports"
};
private static readonly ModuleVersion v1p26 = new ModuleVersion("v1.26");
private static readonly ModuleVersion v1p31 = new ModuleVersion("v1.31");
}
}
14 changes: 14 additions & 0 deletions Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,20 @@ which are not in themselves mutually compatible enough to use the `"provides"` p
]
```

(**v1.31**) Clients implementing version `v1.31` or later of the spec *must* support
the `choice_help_text` property in a relationship. This string is presented to the user
if they must be prompted to choose between two or more mods to satisfy the relationship.

```yaml
depends:
- name: VirtualIdentifier1
choice_help_text: Choose the HR option for high resolution
- any_of:
- name: ModA
- name: ModB
choice_help_text: Pick ModA if you prefer polka dots, ModB otherwise
```
##### depends
A list of mods which are *required* for the current mod to operate.
Expand Down

0 comments on commit 3a8404e

Please sign in to comment.