Skip to content

feat: add validate management command for survey_config schema validation #655

Description

@Joe-Heffer-Shef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpythonPull requests that update python code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions