Context
We have python manage.py validate_responses, which validates stored SurveyResponse.answers against each survey's generated response schema. We don't have an equivalent check for the survey structure itself — the questions, fields, and sections defined in Survey.survey_config.
data/schemas/survey_config.schema.json already defines the JSON Schema for a valid survey config (sections, field types, required properties, etc.), but nothing currently runs it automatically. The source config files live in data/survey_config/*.json and are also loaded into Survey.survey_config (a JSONField) for surveys already created in the database.
Work required
Add a new management command, python manage.py validate, that runs schema validation for survey configs against data/schemas/survey_config.schema.json. It should:
- Validate every
Survey.survey_config currently stored in the database using jsonschema.validate() (same pattern as survey/management/commands/validate_responses.py).
- Also validate the source JSON files under
data/survey_config/*.json, since these are edited directly and used to create/update surveys before they're ever persisted to the DB.
- Report validation errors per survey/file (survey PK or filename + schema error message) and exit non-zero if any are found, mirroring
validate_responses's output/exit-code behaviour.
References
Context
We have
python manage.py validate_responses, which validates storedSurveyResponse.answersagainst each survey's generated response schema. We don't have an equivalent check for the survey structure itself — the questions, fields, and sections defined inSurvey.survey_config.data/schemas/survey_config.schema.jsonalready defines the JSON Schema for a valid survey config (sections, field types, required properties, etc.), but nothing currently runs it automatically. The source config files live indata/survey_config/*.jsonand are also loaded intoSurvey.survey_config(aJSONField) for surveys already created in the database.Work required
Add a new management command,
python manage.py validate, that runs schema validation for survey configs againstdata/schemas/survey_config.schema.json. It should:Survey.survey_configcurrently stored in the database usingjsonschema.validate()(same pattern assurvey/management/commands/validate_responses.py).data/survey_config/*.json, since these are edited directly and used to create/update surveys before they're ever persisted to the DB.validate_responses's output/exit-code behaviour.References
survey/management/commands/validate_responses.pydata/schemas/survey_config.schema.jsondata/survey_config/*.json