diff --git a/index.d.ts b/index.d.ts index cd7534b..b408716 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,6 +7,7 @@ // } declare const crawlerUserAgents: { + id: string pattern: string addition_date?: string url?: string diff --git a/validate.go b/validate.go index 41ab9d1..e42c7ed 100644 --- a/validate.go +++ b/validate.go @@ -13,6 +13,9 @@ var crawlersJson []byte // Crawler contains information about one crawler. type Crawler struct { + // An identifier for the crawler. + Id string `json:"id"` + // Regexp of User Agent of the crawler. Pattern string `json:"pattern"` @@ -28,6 +31,7 @@ type Crawler struct { // Private time needed to convert addition_date from/to the format used in JSON. type jsonCrawler struct { + Id string `json:"id"` Pattern string `json:"pattern"` AdditionDate string `json:"addition_date"` URL string `json:"url"` @@ -52,10 +56,15 @@ func (c *Crawler) UnmarshalJSON(b []byte) error { return err } + c.Id = jc.Id c.Pattern = jc.Pattern c.URL = jc.URL c.Instances = jc.Instances + if c.Id == "" { + return fmt.Errorf("empty id in record %s", string(b)) + } + if c.Pattern == "" { return fmt.Errorf("empty pattern in record %s", string(b)) } diff --git a/validate.py b/validate.py index 8f9c134..21c89eb 100644 --- a/validate.py +++ b/validate.py @@ -16,6 +16,7 @@ "items": { "type": "object", "properties": { + "id": {"type": "string"}, # required "pattern": {"type": "string"}, # required "instances": {"type": "array"}, # required "url": {"type": "string"}, # optional @@ -23,7 +24,7 @@ "addition_date": {"type": "string"}, # optional "depends_on": {"type": "array"} # allows an instance to match twice }, - "required": ["pattern", "instances"] + "required": ["id", "pattern", "instances"] } }