Skip to content

Commit 1f802c8

Browse files
authored
fix: allow "0" as publiccodeYmlVersion (#224)
This is basically what specifying the version does: it refers to the major version and the validator acts on it. Make it explicitly supported.
1 parent 5032e83 commit 1f802c8

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (p *Parser) ParseStream(in io.Reader) (PublicCode, error) {
135135

136136
var ve ValidationResults
137137

138-
if slices.Contains(SupportedVersions, version.Value) && !strings.HasPrefix(version.Value, "0.4") {
138+
if slices.Contains(SupportedVersions, version.Value) && version.Value != "0" && !strings.HasPrefix(version.Value, "0.4") {
139139
latestVersion := SupportedVersions[len(SupportedVersions)-1]
140140
line, column := getPositionInFile("publiccodeYmlVersion", node)
141141

parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestInvalidTestcasesV0(t *testing.T) {
151151
"publiccodeYmlVersion_invalid.yml": ValidationResults{
152152
ValidationError{
153153
"publiccodeYmlVersion",
154-
"unsupported version: '1'. Supported versions: 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0",
154+
"unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0",
155155
0,
156156
0,
157157
},

publiccode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package publiccode
22

33
// SupportedVersions lists the publiccode.yml versions this parser supports.
4-
var SupportedVersions = []string{"0.2", "0.2.0", "0.2.1", "0.2.2", "0.3", "0.3.0", "0.4", "0.4.0"}
4+
var SupportedVersions = []string{"0", "0.2", "0.2.0", "0.2.1", "0.2.2", "0.3", "0.3.0", "0.4", "0.4.0"}
55

66
type PublicCode interface {
77
Version() uint
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Should validate with just 0 as the major version
2+
publiccodeYmlVersion: "0"
3+
4+
name: Medusa
5+
url: "https://github.com/italia/developers.italia.it.git"
6+
7+
platforms:
8+
- web
9+
10+
categories:
11+
- cloud-management
12+
13+
developmentStatus: development
14+
15+
softwareType: "standalone/other"
16+
17+
description:
18+
en_GB:
19+
localisedName: Medusa
20+
shortDescription: >
21+
A rather short description which
22+
is probably useless
23+
longDescription: >
24+
Very long description of this software, also split
25+
on multiple rows. You should note what the software
26+
is and why one should need it. This is 158 characters.
27+
Very long description of this software, also split
28+
on multiple rows. You should note what the software
29+
is and why one should need it. This is 316 characters.
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 474 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 632 characters.
36+
features:
37+
- Just one feature
38+
39+
legal:
40+
license: AGPL-3.0-or-later
41+
42+
maintenance:
43+
type: "community"
44+
45+
contacts:
46+
- name: Francesco Rossi
47+
48+
localisation:
49+
localisationReady: true
50+
availableLanguages:
51+
- en

v0.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// PublicCodeV0 defines how a publiccode.yml v0.x is structured
99
type PublicCodeV0 struct {
10-
PubliccodeYamlVersion string `validate:"required,oneof=0.2 0.2.0 0.2.1 0.2.2 0.3 0.3.0 0.4 0.4.0" yaml:"publiccodeYmlVersion"`
10+
PubliccodeYamlVersion string `validate:"required,oneof=0 0.2 0.2.0 0.2.1 0.2.2 0.3 0.3.0 0.4 0.4.0" yaml:"publiccodeYmlVersion"`
1111

1212
Name string `validate:"required" yaml:"name"`
1313
ApplicationSuite string `yaml:"applicationSuite,omitempty"`

0 commit comments

Comments
 (0)