Skip to content

Commit

Permalink
add handling for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbryer committed Jan 24, 2025
1 parent 28eda17 commit fd83670
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 12 deletions.
30 changes: 18 additions & 12 deletions get_schema_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,25 @@ fi
# Convert NEW_FILES to an array
IFS=$'\n' read -r -d '' -a SCHEMA_LIST <<<"${NEW_FILES}"

# Add the schema files to the NEW_SCHEMA_FILEPATHS list if the subdirectory only contains 1 new file, otherwise add the subdirectory to the ERROR_DIRECTORIES list
# Add the schema files to the NEW_SCHEMA_FILEPATHS list if the subdirectory only contains 1 new file
for schema in "${SCHEMA_LIST[@]}"; do
# Get the subdirectory of the schema file
subdirectory=$(dirname "${schema}")
# Get the number of new files in the subdirectory
num_files=$(git diff --name-only --diff-filter=A "${LAST_COMMIT_HASH}" "${LATEST_COMMIT}" "${subdirectory}" | wc -l)
if [[ ${num_files} -eq 1 ]]; then
NEW_SCHEMA_FILEPATHS+=("${schema}")
else
if ! element_in_array "${subdirectory}" "${ERROR_DIRECTORIES[@]}"; then
ERROR_DIRECTORIES+=("${subdirectory}")
fi
fi
# Get the subdirectory of the schema file
subdirectory=$(dirname "${schema}")
# Skip template schemas that are not in a subdirectory
if [[ "${subdirectory}" == "/schemas" ]]; then
echo "Skipping template schema: ${schema}"
continue
fi
# Get the number of new files in the subdirectory
num_files=$(git diff --name-only --diff-filter=A "${LAST_COMMIT_HASH}" "${LATEST_COMMIT}" "${subdirectory}" | wc -l)
if [[ ${num_files} -eq 1 ]]; then
NEW_SCHEMA_FILEPATHS+=("${schema}")
else
# Add the subdirectory to ERROR_DIRECTORIES only if it doesn't already exist
if ! element_in_array "${subdirectory}" "${ERROR_DIRECTORIES[@]}"; then
ERROR_DIRECTORIES+=("${subdirectory}")
fi
fi
done

# Write the lists to environment variable files, ensuring no empty elements are written
Expand Down
108 changes: 108 additions & 0 deletions schemas/survey_1/v54.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "v1.json",
"title": "SDS schema for survey 1",
"type": "object",
"properties": {
"schema_version": {
"const": "v54",
"description": "Version of the schema spec"
},
"survey_id": {
"type": "string",
"description": "The identifier for a particular survey",
"enum": ["1"]
},
"identifier": {
"type": "string",
"description": "The unique top-level identifier. This is the reporting unit reference without the check letter appended.",
"minLength": 11,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["34942807969"]
},
"vat": {
"type": "object",
"description": "The VAT reference number of the business. Split into the 9 digit VAT reference and a 3 digit subsidiary identifier.",
"properties": {
"registration_number": {
"type": "string",
"description": "The 9 digit VAT reference of the business",
"minLength": 9,
"maxLength": 9,
"pattern": "^[0-9]+$",
"examples": ["123456789"]
},
"subsidiary_identifier": {
"type": "string",
"description": "The 3 digit subsidiary identifier. This only exists if the business is part of a VAT group.",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["123"]
}
},
"required": ["registration_number"],
"additionalProperties": false
},
"employer_paye": {
"type": "object",
"description": "The PAYE reference number (or Employer Reference Number) of the business. Split into the 3 digit tax office number and a tax office employer reference.",
"properties": {
"tax_office_number": {
"type": "string",
"description": "The 3 digit tax office number",
"minLength": 3,
"maxLength": 3,
"pattern": "^[0-9]+$",
"examples": ["123"]
},
"reference": {
"type": "string",
"description": "The tax office employer reference. This will be between 1 and 10 characters, which can be letters and numbers.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["AB456"]
}
},
"required": ["tax_office_number", "reference"],
"additionalProperties": false
},
"address": {
"type": "array",
"description": "The fields of the address for the reporting unit. At least 1 address line and Postcode will exist.",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 2,
"maxItems": 6,
"uniqueItems": true,
"examples": [
[
"SOUTH CERNEY WORKS",
"SHAWELL LANE",
"BEENHAM",
"STAFFS",
"BEDFORDSHIRE",
"GL4 5YU"
]
]
},
"business_description": {
"type": "string",
"description": "The business description for the local unit",
"minLength": 1,
"maxLength": 100,
"examples": ["PROVIDER OF CONSTRUCTION MATERIALS AND SUPPLIES"]
}
},
"additionalProperties": false,
"required": [
"schema_version",
"identifier",
"business_description",
"address",
"survey_id"
]
}
108 changes: 108 additions & 0 deletions schemas/template_v3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "v1.json",
"title": "SDS schema for survey 1",
"type": "object",
"properties": {
"schema_version": {
"const": "v3",
"description": "Version of the schema spec"
},
"survey_id": {
"type": "string",
"description": "The identifier for a particular survey",
"enum": ["1"]
},
"identifier": {
"type": "string",
"description": "The unique top-level identifier. This is the reporting unit reference without the check letter appended.",
"minLength": 11,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["34942807969"]
},
"vat": {
"type": "object",
"description": "The VAT reference number of the business. Split into the 9 digit VAT reference and a 3 digit subsidiary identifier.",
"properties": {
"registration_number": {
"type": "string",
"description": "The 9 digit VAT reference of the business",
"minLength": 9,
"maxLength": 9,
"pattern": "^[0-9]+$",
"examples": ["123456789"]
},
"subsidiary_identifier": {
"type": "string",
"description": "The 3 digit subsidiary identifier. This only exists if the business is part of a VAT group.",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["123"]
}
},
"required": ["registration_number"],
"additionalProperties": false
},
"employer_paye": {
"type": "object",
"description": "The PAYE reference number (or Employer Reference Number) of the business. Split into the 3 digit tax office number and a tax office employer reference.",
"properties": {
"tax_office_number": {
"type": "string",
"description": "The 3 digit tax office number",
"minLength": 3,
"maxLength": 3,
"pattern": "^[0-9]+$",
"examples": ["123"]
},
"reference": {
"type": "string",
"description": "The tax office employer reference. This will be between 1 and 10 characters, which can be letters and numbers.",
"minLength": 1,
"maxLength": 10,
"pattern": "^[a-zA-Z0-9]+$",
"examples": ["AB456"]
}
},
"required": ["tax_office_number", "reference"],
"additionalProperties": false
},
"address": {
"type": "array",
"description": "The fields of the address for the reporting unit. At least 1 address line and Postcode will exist.",
"items": {
"type": "string",
"minLength": 1
},
"minItems": 2,
"maxItems": 6,
"uniqueItems": true,
"examples": [
[
"SOUTH CERNEY WORKS",
"SHAWELL LANE",
"BEENHAM",
"STAFFS",
"BEDFORDSHIRE",
"GL4 5YU"
]
]
},
"business_description": {
"type": "string",
"description": "The business description for the local unit",
"minLength": 1,
"maxLength": 100,
"examples": ["PROVIDER OF CONSTRUCTION MATERIALS AND SUPPLIES"]
}
},
"additionalProperties": false,
"required": [
"schema_version",
"identifier",
"business_description",
"address",
"survey_id"
]
}

0 comments on commit fd83670

Please sign in to comment.