Skip to content

Commit 2a6bf0e

Browse files
authored
feat: add deprecation warning for it.riuso.codiceIPA (#269)
1 parent f4aaf57 commit 2a6bf0e

17 files changed

+163
-56
lines changed

fields.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,45 @@ func validateFieldsV0(publiccode PublicCode, parser Parser, network bool) error
186186
}
187187
}
188188

189-
if (publiccodev0.It != nil && publiccodev0.It.Conforme != nil) ||
190-
(publiccodev0.IT != nil && publiccodev0.IT.Conforme != nil) {
191-
vr = append(vr, ValidationWarning{
192-
"IT.conforme",
193-
"This key is DEPRECATED and will be removed in the future. It's safe to drop it", 0, 0,
194-
})
195-
}
189+
it := publiccodev0.IT
196190

197191
if publiccodev0.It != nil {
198192
vr = append(vr, ValidationWarning{
199193
"it",
200194
"Lowercase country codes are DEPRECATED and will be removed in the future. Use 'IT' instead", 0, 0,
201195
})
196+
197+
it = publiccodev0.It
202198
}
203199

204200
if publiccodev0.IT != nil && publiccodev0.It != nil {
205201
vr = append(vr, newValidationError("it", "'IT' key already present. Remove this key"))
202+
203+
it = publiccodev0.IT
204+
}
205+
206+
if it != nil {
207+
if it.Conforme != nil {
208+
vr = append(vr, ValidationWarning{
209+
"IT.conforme",
210+
"This key is DEPRECATED and will be removed in the future. It's safe to drop it", 0, 0,
211+
})
212+
}
213+
214+
if it.Riuso.CodiceIPA != "" {
215+
validate := publiccodeValidator.New()
216+
217+
if validate.Var(it.Riuso.CodiceIPA, "is_italian_ipa_code") == nil {
218+
vr = append(vr, ValidationWarning{
219+
"IT.riuso.codiceIPA",
220+
fmt.Sprintf(
221+
"This key is DEPRECATED and will be removed in the future. Use 'organisation.uri' and set it to 'urn:x-italian-pa:%s' instead",
222+
it.Riuso.CodiceIPA,
223+
),
224+
0, 0,
225+
})
226+
}
227+
}
206228
}
207229

208230
if len(vr) == 0 {

parser_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ func TestInvalidTestcasesV0(t *testing.T) {
626626
ValidationError{"IT.riuso.codiceIPA", "codiceIPA must be a valid Italian Public Administration Code (iPA) (see https://www.indicepa.gov.it/public-services/opendata-read-service.php?dstype=FS&filename=amministrazioni.txt)", 55, 5},
627627
},
628628
"it_IT_duplicated.yml": ValidationResults{
629-
ValidationWarning{"it", "Lowercase country codes are DEPRECATED and will be removed in the future. Use 'IT' instead", 119, 1},
630-
ValidationError{"it", "'IT' key already present. Remove this key", 119, 1},
629+
ValidationWarning{"it", "Lowercase country codes are DEPRECATED and will be removed in the future. Use 'IT' instead", 116, 1},
630+
ValidationError{"it", "'IT' key already present. Remove this key", 116, 1},
631631
},
632632
"it_wrong_case.yml": ValidationResults{
633633
ValidationError{"It", "field It not found in type publiccode.PublicCodeV0", 107, 1},
@@ -712,6 +712,9 @@ func TestValidWithWarningsTestcasesV0(t *testing.T) {
712712
"valid_with_legal_repoOwner.yml": ValidationResults{
713713
ValidationWarning{"legal.repoOwner", "This key is DEPRECATED and will be removed in the future. Use 'organisation.name' instead", 70, 3},
714714
},
715+
"valid_with_IT_riuso_codiceIPA.yml": ValidationResults{
716+
ValidationWarning{"IT.riuso.codiceIPA", "This key is DEPRECATED and will be removed in the future. Use 'organisation.uri' and set it to 'urn:x-italian-pa:pcm' instead", 119, 5},
717+
},
715718
}
716719

717720
dir := "testdata/v0/valid_with_warnings/"

testdata/v0/invalid/it_IT_duplicated.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ dependsOn:
107107
IT:
108108
countryExtensionVersion: "1.0"
109109

110-
riuso:
111-
codiceIPA: c_h501
112-
113110
piattaforme:
114111
spid: false
115112
pagopa: false
@@ -119,9 +116,6 @@ IT:
119116
it:
120117
countryExtensionVersion: "1.0"
121118

122-
riuso:
123-
codiceIPA: c_h501
124-
125119
piattaforme:
126120
spid: false
127121
pagopa: false

testdata/v0/invalid/it_wrong_case.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ dependsOn:
107107
It:
108108
countryExtensionVersion: "1.0"
109109

110-
riuso:
111-
codiceIPA: c_h501
112-
113110
piattaforme:
114111
spid: false
115112
pagopa: false

testdata/v0/invalid/landingURL_invalid.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ dependsOn:
118118
optional: true
119119

120120
IT:
121-
riuso:
122-
codiceIPA: c_h501
123-
124121
piattaforme:
125122
spid: true
126123
pagopa: true

testdata/v0/invalid/landingURL_wrong_type.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ dependsOn:
114114
optional: true
115115

116116
IT:
117-
riuso:
118-
codiceIPA: c_h501
119-
120117
piattaforme:
121118
spid: true
122119
pagopa: true

testdata/v0/invalid/no-network/landingURL_invalid.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ dependsOn:
118118
optional: true
119119

120120
IT:
121-
riuso:
122-
codiceIPA: c_h501
123-
124121
piattaforme:
125122
spid: true
126123
pagopa: true

testdata/v0/valid/countryExtensionVersion_1.0.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ dependsOn:
106106
IT:
107107
countryExtensionVersion: "1.0"
108108

109-
riuso:
110-
codiceIPA: c_h501
111-
112109
piattaforme:
113110
spid: false
114111
pagopa: false

testdata/v0/valid/dependsOn.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ dependsOn: # List of dependencies. The only mandatory list is the proprietary on
110110
IT:
111111
countryExtensionVersion: "0.2"
112112

113-
riuso:
114-
# Codice IPA della PA che ha pubblicato questo repo (repo-owner)
115-
codiceIPA: c_h501
116-
117113
piattaforme:
118114
spid: false
119115
pagopa: false

testdata/v0/valid/no-network/valid.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ dependsOn:
226226
optional: true
227227

228228
IT:
229-
riuso:
230-
codiceIPA: c_h501
231-
232229
piattaforme:
233230
spid: true
234231
pagopa: true

0 commit comments

Comments
 (0)