Skip to content

Commit

Permalink
Merge pull request #335 from invopop/org-address-locality
Browse files Browse the repository at this point in the history
Removing address locality requirement
  • Loading branch information
cavalle authored Jul 25, 2024
2 parents 272a838 + c599a04 commit 727d8c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

- Coming soon...
### Added

- `org.Address`: recommended fields added

### Changed

- `org.Address`: `locality` no longer required.

## [v0.111.0] - 2024-07-24

Expand Down
13 changes: 9 additions & 4 deletions data/schemas/org/address.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@
}
},
"type": "object",
"required": [
"locality"
],
"description": "Address defines a globally acceptable set of attributes that describes a postal or fiscal address."
"description": "Address defines a globally acceptable set of attributes that describes a postal or fiscal address.",
"recommended": [
"number",
"street",
"locality",
"region",
"code",
"country"
]
}
}
}
14 changes: 12 additions & 2 deletions org/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (

"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/schema"
"github.com/invopop/gobl/tax"
"github.com/invopop/gobl/uuid"
"github.com/invopop/jsonschema"
"github.com/invopop/validation"
)

Expand All @@ -32,7 +34,7 @@ type Address struct {
// Additional street address details.
StreetExtra string `json:"street_extra,omitempty" jsonschema:"title=Extended Street"`
// Village, town, district, or city, typically inside a region.
Locality string `json:"locality" jsonschema:"title=Locality"`
Locality string `json:"locality,omitempty" jsonschema:"title=Locality"`
// Province, county, or state, inside a country.
Region string `json:"region,omitempty" jsonschema:"title=Region"`
// Post or ZIP code.
Expand All @@ -54,9 +56,17 @@ func (a *Address) Validate() error {
func (a *Address) ValidateWithContext(ctx context.Context) error {
return tax.ValidateStructWithRegime(ctx, a,
validation.Field(&a.UUID),
validation.Field(&a.Locality, validation.Required),
validation.Field(&a.Country),
validation.Field(&a.Coordinates),
validation.Field(&a.Meta),
)
}

// JSONSchemaExtend adds extra details to the Address schema.
func (Address) JSONSchemaExtend(js *jsonschema.Schema) {
js.Extras = map[string]any{
schema.Recommended: []string{
"number", "street", "locality", "region", "code", "country",
},
}
}

0 comments on commit 727d8c8

Please sign in to comment.