Skip to content

Commit

Permalink
Fixing Dat of Birth: GCP-27
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Meems committed Feb 14, 2019
1 parent 7566b40 commit f3b6150
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/source/explanation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ Date of birth.

**Type**: *string*

**Pattern**: *^[12][0-9]{3}-[01][0-9]-[0-3][0-9]$*
.. raw:: html

<a href="https://regex101.com/r/SIq25G/1" target="_blank">Pattern validator</a>


Best practice is to use 'Year of Birth' as opposed to age. Age has to be updated annually, but year of birth is the same indefinitely, and can be used to calculate age at any point.

Expand Down
4 changes: 2 additions & 2 deletions example-data/testset.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"streetAddress": "1600 Amphitheatre Pkwy",
"countryName": "Mali"
},
"dateOfBirth": "1974-12-10",
"gender": "Male",
"dateOfBirth": "1974-12-31",
"gender": "M",
"thirdPartyIds": [
{
"identifier": "N2786-Q5572-H8123-S9007",
Expand Down
11 changes: 11 additions & 0 deletions generator/GenerateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ private void WriteProperties(string propertyName, JObject objectProperties, int
_sb.AppendLine(MakeBold("Allowed values") + ": " + string.Join(", ", enums) + "\n");
}

if (objectProperties.ContainsKey("pattern"))
_sb.AppendLine(MakeBold("Pattern") + ": " + MakeItalic(objectProperties.GetValue("pattern").ToString()) + "\n");
if (objectProperties.ContainsKey("$pattern-validator"))
_sb.AppendLine(MakeLink("Pattern validator", objectProperties.GetValue("$pattern-validator").ToString()));

// TODO: Write if property is optional or not

if (objectProperties.ContainsKey("description")) AppendMultiLines(objectProperties.GetValue("description").ToString());
Expand Down Expand Up @@ -296,6 +301,12 @@ private string MakeItalic(string text)
return $"*{text}*";
}

private string MakeLink(string label, string url)
{
return $".. raw:: html \n\n <a href=\"{url}\" target=\"_blank\">{label}</a>\n";
}


private struct TitleNumber
{
public int Level1 { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion schema/global-coffee-data-standard.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"1973-05-03"
],
"type": "string",
"pattern": "^[12][0-9]{3}-[01][0-9]-[01][0-9]$",
"pattern": "^[12][0-9]{3}-[01][0-9]-[0-3][0-9]$",
"$pattern-validator": "https://regex101.com/r/SIq25G/1",
"format": "full-date"
},
"gender": {
Expand Down

0 comments on commit f3b6150

Please sign in to comment.