Skip to content

Commit 6d78840

Browse files
committed
fix: properly validate isBasedOn
isBasedOn must be a URL: https://yml.publiccode.tools/schema.core.html?highlight=isbasedon#key-isbasedon
1 parent 1f802c8 commit 6d78840

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func TestInvalidTestcasesV0(t *testing.T) {
201201
ValidationError{"isBasedOn.foobar", "wrong type for this field", 10, 1},
202202
},
203203
"isBasedOn_bad_url_array.yml": ValidationResults{
204-
ValidationError{"isBasedOn", "wrong type for this field", 8, 1},
204+
ValidationError{"isBasedOn[1]", "isBasedOn[1] must be a valid URL", 1, 1},
205205
},
206206
"isBasedOn_bad_url_string.yml": ValidationResults{
207-
ValidationError{"isBasedOn", "'???' not reachable: missing URL scheme", 8, 1},
207+
ValidationError{"isBasedOn[0]", "isBasedOn[0] must be a valid URL", 1, 1},
208208
},
209209

210210
// softwareVersion
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
url: "https://github.com/italia/developers.italia.it.git"
5+
softwareVersion: "dev"
6+
releaseDate: "2017-04-15"
7+
8+
isBasedOn:
9+
- https://github.com/italia/developers.git
10+
# Should NOT validate: must a URL
11+
- string
12+
13+
platforms:
14+
- web
15+
16+
categories:
17+
- cloud-management
18+
19+
developmentStatus: development
20+
21+
softwareType: "standalone/other"
22+
23+
description:
24+
en:
25+
localisedName: Medusa
26+
shortDescription: >
27+
A rather short description which
28+
is probably useless
29+
longDescription: >
30+
Very long description of this software, also split
31+
on multiple rows. You should note what the software
32+
is and why one should need it. This is 158 characters.
33+
Very long description of this software, also split
34+
on multiple rows. You should note what the software
35+
is and why one should need it. This is 316 characters.
36+
Very long description of this software, also split
37+
on multiple rows. You should note what the software
38+
is and why one should need it. This is 474 characters.
39+
Very long description of this software, also split
40+
on multiple rows. You should note what the software
41+
is and why one should need it. This is 632 characters.
42+
features:
43+
- Just one feature
44+
45+
legal:
46+
license: AGPL-3.0-or-later
47+
48+
maintenance:
49+
type: "community"
50+
51+
contacts:
52+
- name: Francesco Rossi
53+
54+
localisation:
55+
localisationReady: true
56+
availableLanguages:
57+
- en
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
url: "https://github.com/italia/developers.italia.it.git"
5+
softwareVersion: "dev"
6+
releaseDate: "2017-04-15"
7+
8+
# Should NOT validate: must a URL
9+
isBasedOn: foobar
10+
11+
platforms:
12+
- web
13+
14+
categories:
15+
- cloud-management
16+
17+
developmentStatus: development
18+
19+
softwareType: "standalone/other"
20+
21+
description:
22+
en:
23+
localisedName: Medusa
24+
shortDescription: >
25+
A rather short description which
26+
is probably useless
27+
longDescription: >
28+
Very long description of this software, also split
29+
on multiple rows. You should note what the software
30+
is and why one should need it. This is 158 characters.
31+
Very long description of this software, also split
32+
on multiple rows. You should note what the software
33+
is and why one should need it. This is 316 characters.
34+
Very long description of this software, also split
35+
on multiple rows. You should note what the software
36+
is and why one should need it. This is 474 characters.
37+
Very long description of this software, also split
38+
on multiple rows. You should note what the software
39+
is and why one should need it. This is 632 characters.
40+
features:
41+
- Just one feature
42+
43+
legal:
44+
license: AGPL-3.0-or-later
45+
46+
maintenance:
47+
type: "community"
48+
49+
contacts:
50+
- name: Francesco Rossi
51+
52+
localisation:
53+
localisationReady: true
54+
availableLanguages:
55+
- en

v0.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ type PublicCodeV0 struct {
1414
URL *URL `validate:"required,url_url" yaml:"url"`
1515
LandingURL *URL `validate:"omitnil,url_http_url" yaml:"landingURL,omitempty"`
1616

17-
IsBasedOn UrlOrUrlArray `yaml:"isBasedOn,omitempty"`
17+
IsBasedOn UrlOrUrlArray `validate:"omitempty,dive,url_url" yaml:"isBasedOn,omitempty"`
1818
SoftwareVersion string `yaml:"softwareVersion,omitempty"`
19-
ReleaseDate *string `validate:"omitnil,date" yaml:"releaseDate"`
19+
ReleaseDate *string `validate:"omitnil,date" yaml:"releaseDate"`
2020
Logo string `yaml:"logo,omitempty"`
2121
MonochromeLogo string `yaml:"monochromeLogo,omitempty"`
2222

0 commit comments

Comments
 (0)