Skip to content

Commit d24f552

Browse files
committed
feat: use pure ISO 3166-1 alpha-2 and deprecate lowercase
See publiccodeyml/publiccode.yml#227
1 parent a17ccbd commit d24f552

File tree

6 files changed

+249
-8
lines changed

6 files changed

+249
-8
lines changed

parser_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ func TestValidWithWarningsTestcasesV0(t *testing.T) {
687687
"valid_with_it_conforme.yml": ValidationResults{
688688
ValidationWarning{"it.conforme", "This key is DEPRECATED and will be removed in the future. It's safe to drop it", 120, 3},
689689
},
690+
"valid_with_country_specific_section_downcase.yml": ValidationResults{
691+
ValidationWarning{"inputTypes", "Tis key is DEPRECATED and will be removed in the future. It's safe to drop it", 48, 1},
692+
},
690693
}
691694

692695
dir := "testdata/v0/valid_with_warnings/"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
applicationSuite: MegaProductivitySuite
5+
url: "https://github.com/italia/developers.italia.it.git"
6+
landingURL: "https://developers.italia.it"
7+
8+
isBasedOn: "https://github.com/italia/developers.italia.it.git"
9+
softwareVersion: "1.0"
10+
releaseDate: 2017-04-15
11+
12+
platforms:
13+
- android
14+
- ios
15+
16+
categories:
17+
- cloud-management
18+
19+
usedBy:
20+
- Comune di Firenze
21+
- Comune di Roma
22+
23+
roadmap: "https://designers.italia.it/roadmap/"
24+
25+
developmentStatus: development
26+
27+
softwareType: "standalone/other"
28+
29+
intendedAudience:
30+
countries:
31+
- it
32+
- de
33+
unsupportedCountries:
34+
- us
35+
36+
description:
37+
en:
38+
localisedName: Medusa
39+
shortDescription: "A really interesting software."
40+
longDescription: >
41+
Very long description of this software, also split
42+
on multiple rows. You should note what the software
43+
is and why one should need it. This is 158 characters.
44+
Very long description of this software, also split
45+
on multiple rows. You should note what the software
46+
is and why one should need it. This is 316 characters.
47+
Very long description of this software, also split
48+
on multiple rows. You should note what the software
49+
is and why one should need it. This is 474 characters.
50+
Very long description of this software, also split
51+
on multiple rows. You should note what the software
52+
is and why one should need it. This is 632 characters.
53+
54+
documentation: "https://docs.italia.it"
55+
apiDocumentation: "https://developers.italia.it/it/api"
56+
57+
features:
58+
- Very important feature
59+
- Will run without a problem
60+
- Has zero bugs
61+
- Solves all the problems of the world
62+
videos:
63+
- https://www.youtube.com/watch?v=RaHmGbBOP84
64+
awards:
65+
- 1st Price Software of the year
66+
67+
legal:
68+
license: AGPL-3.0-or-later
69+
mainCopyrightOwner: City of Chicago
70+
repoOwner: City of Chicago
71+
72+
maintenance:
73+
type: "community"
74+
contacts:
75+
76+
name: Mario Rossi
77+
phone: "+390412501953"
78+
79+
localisation:
80+
localisationReady: true
81+
availableLanguages:
82+
- en
83+
- ita
84+
- fra
85+
- deu
86+
87+
dependsOn:
88+
open:
89+
- name: MySQL
90+
versionMin: "1.1"
91+
versionMax: "1.3"
92+
optional: true
93+
- name: PostgreSQL
94+
version: "3.2"
95+
optional: true
96+
proprietary:
97+
- name: Oracle
98+
versionMin: "11.4"
99+
hardware:
100+
- name: NFC Reader
101+
optional: true
102+
- name: NFC Reader1
103+
optional: true
104+
- name: NFC Reader2
105+
optional: true
106+
107+
IT:
108+
countryExtensionVersion: "1.0"
109+
110+
riuso:
111+
codiceIPA: c_h501
112+
113+
piattaforme:
114+
spid: false
115+
pagopa: false
116+
cie: false
117+
anpr: false
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
publiccodeYmlVersion: "0.4"
2+
3+
name: Medusa
4+
applicationSuite: MegaProductivitySuite
5+
url: "https://github.com/italia/developers.italia.it.git"
6+
landingURL: "https://developers.italia.it"
7+
8+
isBasedOn: "https://github.com/italia/developers.italia.it.git"
9+
softwareVersion: "1.0"
10+
releaseDate: 2017-04-15
11+
12+
platforms:
13+
- android
14+
- ios
15+
16+
categories:
17+
- cloud-management
18+
19+
usedBy:
20+
- Comune di Firenze
21+
- Comune di Roma
22+
23+
roadmap: "https://designers.italia.it/roadmap/"
24+
25+
developmentStatus: development
26+
27+
softwareType: "standalone/other"
28+
29+
intendedAudience:
30+
countries:
31+
- it
32+
- de
33+
unsupportedCountries:
34+
- us
35+
36+
description:
37+
en:
38+
localisedName: Medusa
39+
shortDescription: "A really interesting software."
40+
longDescription: >
41+
Very long description of this software, also split
42+
on multiple rows. You should note what the software
43+
is and why one should need it. This is 158 characters.
44+
Very long description of this software, also split
45+
on multiple rows. You should note what the software
46+
is and why one should need it. This is 316 characters.
47+
Very long description of this software, also split
48+
on multiple rows. You should note what the software
49+
is and why one should need it. This is 474 characters.
50+
Very long description of this software, also split
51+
on multiple rows. You should note what the software
52+
is and why one should need it. This is 632 characters.
53+
54+
documentation: "https://docs.italia.it"
55+
apiDocumentation: "https://developers.italia.it/it/api"
56+
57+
features:
58+
- Very important feature
59+
- Will run without a problem
60+
- Has zero bugs
61+
- Solves all the problems of the world
62+
videos:
63+
- https://www.youtube.com/watch?v=RaHmGbBOP84
64+
awards:
65+
- 1st Price Software of the year
66+
67+
legal:
68+
license: AGPL-3.0-or-later
69+
mainCopyrightOwner: City of Chicago
70+
repoOwner: City of Chicago
71+
72+
maintenance:
73+
type: "community"
74+
contacts:
75+
76+
name: Mario Rossi
77+
phone: "+390412501953"
78+
79+
localisation:
80+
localisationReady: true
81+
availableLanguages:
82+
- en
83+
- ita
84+
- fra
85+
- deu
86+
87+
dependsOn:
88+
open:
89+
- name: MySQL
90+
versionMin: "1.1"
91+
versionMax: "1.3"
92+
optional: true
93+
- name: PostgreSQL
94+
version: "3.2"
95+
optional: true
96+
proprietary:
97+
- name: Oracle
98+
versionMin: "11.4"
99+
hardware:
100+
- name: NFC Reader
101+
optional: true
102+
- name: NFC Reader1
103+
optional: true
104+
- name: NFC Reader2
105+
optional: true
106+
107+
# Should have a warning here, downcase is deprecated:
108+
it:
109+
countryExtensionVersion: "1.0"
110+
111+
riuso:
112+
codiceIPA: c_h501
113+
114+
piattaforme:
115+
spid: false
116+
pagopa: false
117+
cie: false
118+
anpr: false

v0.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ type PublicCodeV0 struct {
4747
SoftwareType string `json:"softwareType" validate:"required,oneof=standalone/mobile standalone/iot standalone/desktop standalone/web standalone/backend standalone/other addon library configurationFiles" yaml:"softwareType"`
4848

4949
IntendedAudience *struct {
50-
Scope *[]string `json:"scope,omitempty" validate:"omitempty,dive,is_scope_v0" yaml:"scope,omitempty"`
51-
Countries *[]string `json:"countries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"countries,omitempty"`
52-
UnsupportedCountries *[]string `json:"unsupportedCountries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"unsupportedCountries,omitempty"`
50+
Scope *[]string `json:"scope,omitempty" validate:"omitempty,dive,is_scope_v0" yaml:"scope,omitempty"`
51+
Countries *[]string `json:"countries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lower_or_upper" yaml:"countries,omitempty"`
52+
UnsupportedCountries *[]string `json:"unsupportedCountries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lower_or_upper" yaml:"unsupportedCountries,omitempty"`
5353
} `json:"intendedAudience,omitempty" yaml:"intendedAudience,omitempty"`
5454

5555
Description map[string]DescV0 `json:"description" validate:"gt=0,bcp47_keys,dive" yaml:"description"`
@@ -79,6 +79,9 @@ type PublicCodeV0 struct {
7979
} `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
8080

8181
It *ITSectionV0 `json:"it,omitempty" yaml:"it,omitempty"`
82+
83+
// Keep the deprecated lowercase version
84+
it *ITSectionV0 `yaml:"it,omitempty" yaml:"it,omitempty"`
8285
}
8386

8487
// DescV0 is a general description of the software.

validators/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import (
1313
"github.com/rivo/uniseg"
1414
)
1515

16-
func isIso3166Alpha2Lowercase(fl validator.FieldLevel) bool {
16+
func isIso3166Alpha2LowerOrUpper(fl validator.FieldLevel) bool {
1717
str := fl.Field().String()
1818
validate := validator.New(validator.WithRequiredStructEnabled())
1919

20-
err := validate.Var(str, "lowercase")
21-
if err != nil {
20+
// Either all lower or all upper, don't allow mixed case
21+
if str != strings.ToLower(str) && str != strings.ToUpper(str) {
2222
return false
2323
}
2424

25-
err = validate.Var(strings.ToUpper(str), "iso3166_1_alpha2")
25+
err := validate.Var(strings.ToUpper(str), "iso3166_1_alpha2")
2626

2727
return err == nil
2828
}

validators/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func New() *validator.Validate {
1414
validate := validator.New(validator.WithRequiredStructEnabled())
1515
_ = validate.RegisterValidation("is_mime_type", isMIMEType)
16-
_ = validate.RegisterValidation("iso3166_1_alpha2_lowercase", isIso3166Alpha2Lowercase)
16+
_ = validate.RegisterValidation("iso3166_1_alpha2_lower_or_upper", isIso3166Alpha2LowerOrUpper)
1717
_ = validate.RegisterValidation("umax", uMax)
1818
_ = validate.RegisterValidation("umin", uMin)
1919
_ = validate.RegisterValidation("url_http_url", isHTTPURL)

0 commit comments

Comments
 (0)