Skip to content

Commit cc49387

Browse files
committed
feat: add json struct tags to PublicCodeV0
Add json struct tags so we can serialize the struct to JSON and use it to pass the data around from the Go code to the various language bindings as a simple char*, instead of wrapping the whole type. Unfortunately the yaml library doesn't allow us to use the same tag, and we end up duplicating them: go-yaml/yaml#424 This duplication should be temporary, as goccy/go-yaml supports the json tags for YAML serialization (italia#221).
1 parent 553449b commit cc49387

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

v0.go

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,106 +7,106 @@ import (
77

88
// PublicCodeV0 defines how a publiccode.yml v0.x is structured
99
type PublicCodeV0 struct {
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"`
10+
PubliccodeYamlVersion string `json:"publiccodeYmlVersion" 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

12-
Name string `validate:"required" yaml:"name"`
13-
ApplicationSuite string `yaml:"applicationSuite,omitempty"`
14-
URL *URL `validate:"required,url_url" yaml:"url"`
15-
LandingURL *URL `validate:"omitnil,url_http_url" yaml:"landingURL,omitempty"`
12+
Name string `json:"name" validate:"required" yaml:"name"`
13+
ApplicationSuite string `json:"applicationSuite,omitempty" yaml:"applicationSuite,omitempty"`
14+
URL *URL `json:"url" validate:"required,url_url" yaml:"url"`
15+
LandingURL *URL `json:"landingURL,omitempty" validate:"omitnil,url_http_url" yaml:"landingURL,omitempty"`
1616

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

23-
InputTypes []string `validate:"omitempty,dive,is_mime_type" yaml:"inputTypes,omitempty"`
24-
OutputTypes []string `validate:"omitempty,dive,is_mime_type" yaml:"outputTypes,omitempty"`
23+
InputTypes []string `json:"inputTypes,omitempty" validate:"omitempty,dive,is_mime_type" yaml:"inputTypes,omitempty"`
24+
OutputTypes []string `json:"outputTypes,omitempty" validate:"omitempty,dive,is_mime_type" yaml:"outputTypes,omitempty"`
2525

26-
Platforms []string `validate:"gt=0" yaml:"platforms"`
26+
Platforms []string `json:"platforms" validate:"gt=0" yaml:"platforms"`
2727

28-
Categories []string `validate:"required,gt=0,dive,is_category_v0" yaml:"categories"`
28+
Categories []string `json:"categories" validate:"required,gt=0,dive,is_category_v0" yaml:"categories"`
2929

30-
UsedBy *[]string `yaml:"usedBy,omitempty"`
30+
UsedBy *[]string `json:"usedBy,omitempty" yaml:"usedBy,omitempty"`
3131

32-
Roadmap *URL `validate:"omitnil,url_http_url" yaml:"roadmap,omitempty"`
32+
Roadmap *URL `json:"roadmap,omitempty" validate:"omitnil,url_http_url" yaml:"roadmap,omitempty"`
3333

34-
DevelopmentStatus string `validate:"required,oneof=concept development beta stable obsolete" yaml:"developmentStatus"`
34+
DevelopmentStatus string `json:"developmentStatus" validate:"required,oneof=concept development beta stable obsolete" yaml:"developmentStatus"`
3535

36-
SoftwareType string `validate:"required,oneof=standalone/mobile standalone/iot standalone/desktop standalone/web standalone/backend standalone/other addon library configurationFiles" yaml:"softwareType"`
36+
SoftwareType string `json:"softwareType" validate:"required,oneof=standalone/mobile standalone/iot standalone/desktop standalone/web standalone/backend standalone/other addon library configurationFiles" yaml:"softwareType"`
3737

3838
IntendedAudience *struct {
39-
Scope *[]string `validate:"omitempty,dive,is_scope_v0" yaml:"scope,omitempty"`
40-
Countries *[]string `validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"countries,omitempty"`
41-
UnsupportedCountries *[]string `validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"unsupportedCountries,omitempty"`
42-
} `yaml:"intendedAudience,omitempty"`
39+
Scope *[]string `json:"scope,omitempty" validate:"omitempty,dive,is_scope_v0" yaml:"scope,omitempty"`
40+
Countries *[]string `json:"countries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"countries,omitempty"`
41+
UnsupportedCountries *[]string `json:"unsupportedCountries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lowercase" yaml:"unsupportedCountries,omitempty"`
42+
} `json:"intendedAudience,omitempty" yaml:"intendedAudience,omitempty"`
4343

44-
Description map[string]DescV0 `validate:"gt=0,bcp47_keys,dive" yaml:"description"`
44+
Description map[string]DescV0 `json:"description" validate:"gt=0,bcp47_keys,dive" yaml:"description"`
4545

4646
Legal struct {
47-
License string `validate:"required,is_spdx_expression" yaml:"license"`
48-
MainCopyrightOwner *string `yaml:"mainCopyrightOwner,omitempty"`
49-
RepoOwner *string `yaml:"repoOwner,omitempty"`
50-
AuthorsFile *string `yaml:"authorsFile,omitempty"`
51-
} `yaml:"legal"`
47+
License string `json:"license" validate:"required,is_spdx_expression" yaml:"license"`
48+
MainCopyrightOwner *string `json:"mainCopyrightOwner,omitempty" yaml:"mainCopyrightOwner,omitempty"`
49+
RepoOwner *string `json:"repoOwner,omitempty" yaml:"repoOwner,omitempty"`
50+
AuthorsFile *string `json:"authorsFile,omitempty" yaml:"authorsFile,omitempty"`
51+
} `yaml:"legal" json:"legal"`
5252

5353
Maintenance struct {
54-
Type string `validate:"required,oneof=internal contract community none" yaml:"type"`
55-
Contractors []ContractorV0 `validate:"required_if=Type contract,excluded_unless=Type contract,dive" yaml:"contractors,omitempty"`
56-
Contacts []ContactV0 `validate:"required_if=Type community,required_if=Type internal,dive" yaml:"contacts,omitempty"`
57-
} `yaml:"maintenance"`
54+
Type string `json:"type" validate:"required,oneof=internal contract community none" yaml:"type"`
55+
Contractors []ContractorV0 `json:"contractors,omitempty" validate:"required_if=Type contract,excluded_unless=Type contract,dive" yaml:"contractors,omitempty"`
56+
Contacts []ContactV0 `json:"contacts,omitempty" validate:"required_if=Type community,required_if=Type internal,dive" yaml:"contacts,omitempty"`
57+
} `yaml:"maintenance" json:"maintenance"`
5858

5959
Localisation struct {
60-
LocalisationReady *bool `validate:"required" yaml:"localisationReady"`
61-
AvailableLanguages []string `validate:"required,gt=0,dive,bcp47_language_tag" yaml:"availableLanguages"`
62-
} `yaml:"localisation"`
60+
LocalisationReady *bool `json:"localisationReady" validate:"required" yaml:"localisationReady"`
61+
AvailableLanguages []string `json:"availableLanguages" validate:"required,gt=0,dive,bcp47_language_tag" yaml:"availableLanguages"`
62+
} `yaml:"localisation" json:"localisation"`
6363

6464
DependsOn *struct {
65-
Open *[]DependencyV0 `validate:"omitempty,dive" yaml:"open,omitempty"`
66-
Proprietary *[]DependencyV0 `validate:"omitempty,dive" yaml:"proprietary,omitempty"`
67-
Hardware *[]DependencyV0 `validate:"omitempty,dive" yaml:"hardware,omitempty"`
68-
} `yaml:"dependsOn,omitempty"`
65+
Open *[]DependencyV0 `json:"open,omitempty" validate:"omitempty,dive" yaml:"open,omitempty"`
66+
Proprietary *[]DependencyV0 `json:"proprietary,omitempty" validate:"omitempty,dive" yaml:"proprietary,omitempty"`
67+
Hardware *[]DependencyV0 `json:"hardware,omitempty" validate:"omitempty,dive" yaml:"hardware,omitempty"`
68+
} `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
6969

70-
It ITSectionV0 `yaml:"it"`
70+
It ITSectionV0 `json:"it" yaml:"it"`
7171
}
7272

7373
// DescV0 is a general description of the software.
7474
type DescV0 struct {
75-
LocalisedName *string `yaml:"localisedName,omitempty"`
76-
GenericName string `validate:"umax=35" yaml:"genericName"`
77-
ShortDescription string `validate:"required,umax=150" yaml:"shortDescription"`
78-
LongDescription string `validate:"required,umin=150,umax=10000" yaml:"longDescription,omitempty"`
79-
Documentation *URL `validate:"omitnil,url_http_url" yaml:"documentation,omitempty"`
80-
APIDocumentation *URL `validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"`
81-
Features *[]string `validate:"gt=0,dive" yaml:"features,omitempty"`
82-
Screenshots []string `yaml:"screenshots,omitempty"`
83-
Videos []*URL `validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"`
84-
Awards []string `yaml:"awards,omitempty"`
75+
LocalisedName *string `json:"localisedName,omitempty" yaml:"localisedName,omitempty"`
76+
GenericName string `json:"genericName" validate:"umax=35" yaml:"genericName"`
77+
ShortDescription string `json:"shortDescription" validate:"required,umax=150" yaml:"shortDescription"`
78+
LongDescription string `json:"longDescription,omitempty" validate:"required,umin=150,umax=10000" yaml:"longDescription,omitempty"`
79+
Documentation *URL `json:"documentation,omitempty" validate:"omitnil,url_http_url" yaml:"documentation,omitempty"`
80+
APIDocumentation *URL `json:"apiDocumentation,omitempty" validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"`
81+
Features *[]string `json:"features,omitempty" validate:"gt=0,dive" yaml:"features,omitempty"`
82+
Screenshots []string `json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
83+
Videos []*URL `json:"videos,omitempty" validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"`
84+
Awards []string `json:"awards,omitempty" yaml:"awards,omitempty"`
8585
}
8686

8787
// ContractorV0 is an entity or entities, if any, that are currently contracted for maintaining the software.
8888
type ContractorV0 struct {
89-
Name string `validate:"required" yaml:"name"`
90-
Email *string `validate:"omitempty,email" yaml:"email,omitempty"`
91-
Website *URL `validate:"omitnil,url_http_url" yaml:"website,omitempty"`
92-
Until string `validate:"required,date" yaml:"until"`
89+
Name string `json:"name" validate:"required" yaml:"name"`
90+
Email *string `json:"email,omitempty" validate:"omitempty,email" yaml:"email,omitempty"`
91+
Website *URL `json:"website,omitempty" validate:"omitnil,url_http_url" yaml:"website,omitempty"`
92+
Until string `json:"until" validate:"required,date" yaml:"until"`
9393
}
9494

9595
// ContactV0 is a contact info maintaining the software.
9696
type ContactV0 struct {
97-
Name string `validate:"required" yaml:"name"`
98-
Email *string `validate:"omitempty,email" yaml:"email,omitempty"`
99-
Affiliation *string `yaml:"affiliation,omitempty"`
100-
Phone *string `validate:"omitempty" yaml:"phone,omitempty"`
97+
Name string `json:"name" validate:"required" yaml:"name"`
98+
Email *string `json:"email,omitempty" validate:"omitempty,email" yaml:"email,omitempty"`
99+
Affiliation *string `json:"affiliation,omitempty" yaml:"affiliation,omitempty"`
100+
Phone *string `json:"phone,omitempty" validate:"omitempty" yaml:"phone,omitempty"`
101101
}
102102

103103
// DependencyV0 describes system-level dependencies required to install and use this software.
104104
type DependencyV0 struct {
105-
Name string `validate:"required,gt=0" yaml:"name"`
106-
VersionMin *string `yaml:"versionMin,omitempty"`
107-
VersionMax *string `yaml:"versionMax,omitempty"`
108-
Optional *bool `yaml:"optional,omitempty"`
109-
Version *string `yaml:"version,omitempty"`
105+
Name string `json:"name" validate:"required,gt=0" yaml:"name"`
106+
VersionMin *string `json:"versionMin,omitempty" yaml:"versionMin,omitempty"`
107+
VersionMax *string `json:"versionMax,omitempty" yaml:"versionMax,omitempty"`
108+
Optional *bool `json:"optional,omitempty" yaml:"optional,omitempty"`
109+
Version *string `json:"version,omitempty" yaml:"version,omitempty"`
110110
}
111111

112112
// Country-specific sections
@@ -116,26 +116,26 @@ type DependencyV0 struct {
116116
// countries, such as declaring compliance with local laws or regulations.
117117

118118
type ITSectionV0 struct {
119-
CountryExtensionVersion *string `validate:"omitnil,oneof=0.2 1.0" yaml:"countryExtensionVersion"`
119+
CountryExtensionVersion *string `json:"countryExtensionVersion" validate:"omitnil,oneof=0.2 1.0" yaml:"countryExtensionVersion"`
120120

121121
Conforme struct {
122-
LineeGuidaDesign bool `yaml:"lineeGuidaDesign,omitempty"`
123-
ModelloInteroperabilita bool `yaml:"modelloInteroperabilita"`
124-
MisureMinimeSicurezza bool `yaml:"misureMinimeSicurezza"`
125-
GDPR bool `yaml:"gdpr"`
126-
} `yaml:"conforme"`
122+
LineeGuidaDesign bool `json:"lineeGuidaDesign,omitempty" yaml:"lineeGuidaDesign,omitempty"`
123+
ModelloInteroperabilita bool `json:"modelloInteroperabilita" yaml:"modelloInteroperabilita"`
124+
MisureMinimeSicurezza bool `json:"misureMinimeSicurezza" yaml:"misureMinimeSicurezza"`
125+
GDPR bool `json:"gdpr" yaml:"gdpr"`
126+
} `yaml:"conforme" json:"conforme"`
127127

128128
Riuso struct {
129-
CodiceIPA string `validate:"omitempty,is_italian_ipa_code" yaml:"codiceIPA,omitempty"`
130-
} `yaml:"riuso,omitempty"`
129+
CodiceIPA string `json:"codiceIPA,omitempty" validate:"omitempty,is_italian_ipa_code" yaml:"codiceIPA,omitempty"`
130+
} `yaml:"riuso,omitempty" json:"riuso,omitempty"`
131131

132132
Piattaforme struct {
133-
SPID bool `yaml:"spid"`
134-
PagoPa bool `yaml:"pagopa"`
135-
CIE bool `yaml:"cie"`
136-
ANPR bool `yaml:"anpr"`
137-
Io bool `yaml:"io"`
138-
} `yaml:"piattaforme"`
133+
SPID bool `json:"spid" yaml:"spid"`
134+
PagoPa bool `json:"pagopa" yaml:"pagopa"`
135+
CIE bool `json:"cie" yaml:"cie"`
136+
ANPR bool `json:"anpr" yaml:"anpr"`
137+
Io bool `json:"io" yaml:"io"`
138+
} `yaml:"piattaforme" json:"piattaforme"`
139139
}
140140

141141
func (p PublicCodeV0) Version() uint {

0 commit comments

Comments
 (0)