Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON schema for top-level config file + use for validation #489

Merged
merged 17 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions schemas/v1/age_range.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/age_range.json",
"type": "array",
"prefixItems": [
{
"type": "integer",
"minimum": 0
},
{
"type": "integer",
"minimum": 0
}
],
"minItems": 2,
"items": false
}
35 changes: 35 additions & 0 deletions schemas/v1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config.json",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"version": {
"const": 2
},
"data": {
"$ref": "config/data.json"
},
"inputs": {
"$ref": "config/inputs.json"
},
"modelling": {
"$ref": "config/modelling.json"
},
"running": {
"$ref": "config/running.json"
},
"output": {
"$ref": "config/output.json"
}
},
"required": [
"inputs",
"modelling",
"running",
"output"
],
"additionalProperties": false
}
17 changes: 17 additions & 0 deletions schemas/v1/config/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config/data.json",
"type": "object",
"properties": {
"source": {
"type": "string"
},
"checksum": {
"type": "string"
}
},
"required": [
"source"
],
"additionalProperties": false
}
70 changes: 70 additions & 0 deletions schemas/v1/config/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config/inputs.json",
"type": "object",
"properties": {
"dataset": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"format": {
"const": "csv"
},
"delimiter": {
"type": "string"
},
"encoding": {
"type": "string"
},
"columns": {
"type": "object",
"additionalProperties": {
"anyOf": [
{
"const": "integer"
},
{
"const": "double"
}
]
}
}
},
"required": [
"name",
"format",
"delimiter",
"encoding",
"columns"
],
"additionalProperties": false
},
"settings": {
"type": "object",
"properties": {
"country_code": {
"type": "string"
},
"size_fraction": {
"type": "number"
},
"age_range": {
"$ref": "../age_range.json"
}
},
"required": [
"country_code",
"size_fraction",
"age_range"
],
"additionalProperties": false
}
},
"required": [
"dataset",
"settings"
],
"additionalProperties": false
}
104 changes: 104 additions & 0 deletions schemas/v1/config/interventions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config/interventions.json",
"type": "object",
"properties": {
"active_type_id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"types": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"active_period": {
"type": "object",
"properties": {
"start_time": {
"type": "integer"
},
"finish_time": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
]
}
},
"required": [
"start_time",
"finish_time"
],
"additionalProperties": false
},
"impacts": {
"type": "array"
},
"impact_type": {
"type": "string"
},
"dynamics": {
"type": "array",
"items": {
"type": "number"
}
},
"coefficients": {
"type": "array",
"items": {
"type": "number"
}
},
"coverage_rates": {
"type": "array",
"items": {
"type": "number"
}
},
"coverage_cutoff_time": {
"type": "integer",
"minimum": 0
},
"child_cutoff_age": {
"type": "integer",
"minimum": 0
},
"adjustments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"risk_factor": {
"type": "string"
},
"value": {
"type": "number"
}
}
}
}
},
"required": [
"active_period",
"impacts"
],
"additionalProperties": false
}
}
},
"required": [
"active_type_id",
"types"
],
"additionalProperties": false
}
112 changes: 112 additions & 0 deletions schemas/v1/config/modelling.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any of the string types here require a minLength to ensure they are not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. I don't know whether I can be bothered to put minLengths all over the place though, but maybe I'm just being lazy 😆.

What do you think @jamesturner246? How pedantic do we want to be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't push you -- one would hope users know not to put empty string fields... Certainly won't hurt though.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config/modelling.json",
"type": "object",
"properties": {
"ses_model": {
"type": "object",
"properties": {
"function_name": {
"type": "string"
},
"function_parameters": {
"type": "array",
"items": {
"type": "number"
}
Comment on lines +12 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking this array doesn't require a minimum number of values? Same applies for other arrays in this schema I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure... @jamesturner246?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these depend on the SES model -- e.g. normal has mean, std. Maybe there are other models that have none? Never uses the SES module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... ok. I'll leave as is for now. We can always add extra constraints in future if needed.

}
},
"required": [
"function_name",
"function_parameters"
],
"additionalProperties": false
},
"risk_factors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"level": {
"type": "integer"
},
"range": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"name",
"level",
"range"
],
"additionalProperties": false
}
},
"risk_factor_models": {
"type": "object",
"properties": {
"static": {
"type": "string"
},
"dynamic": {
"type": "string"
}
},
"required": [
"static",
"dynamic"
],
"additionalProperties": false
},
"baseline_adjustments": {
"type": "object",
"properties": {
"format": {
"const": "csv"
},
"delimiter": {
"type": "string"
},
"encoding": {
"type": "string"
},
"file_names": {
"type": "object",
"properties": {
"factorsmean_male": {
"type": "string"
},
"factorsmean_female": {
"type": "string"
}
},
"required": [
"factorsmean_male",
"factorsmean_female"
],
"additionalProperties": false
}
},
"required": [
"format",
"delimiter",
"encoding",
"file_names"
],
"additionalProperties": false
}
},
"required": [
"ses_model",
"risk_factors",
"risk_factor_models",
"baseline_adjustments"
],
"additionalProperties": false
}
22 changes: 22 additions & 0 deletions schemas/v1/config/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/imperialCHEPI/healthgps/main/schemas/v1/config.json",
"type": "object",
"properties": {
"comorbidities": {
"type": "integer"
},
"folder": {
"type": "string"
},
"file_name": {
"type": "string"
}
},
"required": [
"comorbidities",
"folder",
"file_name"
],
"additionalProperties": false
}
Loading
Loading