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 target_keys property schema #108

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Conversation

annakrystalli
Copy link
Member

Use additionalProperties to enforce that target_keys properties are strings, not arrays.

Resolves #97

@annakrystalli annakrystalli changed the base branch from main to br-v4.0.0 October 16, 2024 12:11
@hubverse-org hubverse-org deleted a comment from github-actions bot Oct 16, 2024
@annakrystalli annakrystalli self-assigned this Oct 16, 2024
@annakrystalli
Copy link
Member Author

annakrystalli commented Oct 16, 2024

Adding the experimentation test results below, with plans to add specific tests for this in hubAdmin hubverse-org/hubAdmin#54

text_invalid <- '{
    "target_keys": {
        "target": [
            "wk flu hosp rate change"
        ]
    }
}'
text_valid <- '{
    "target_keys": {
        "target": "wk flu hosp rate change"
    }
}'
text_valid_null <- '{
    "target_keys": null
}'

schema_text_vague <- '
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v3.0.1/tasks-schema.json",
    "type": "object",
    "properties": {
        "target_keys": {
            "type": [
                "object",
                "null"
                ]

        }

    }
}
'
schema_vague <- jsonvalidate::json_schema$new(schema_text_vague)
schema_vague$validate(text_invalid) # FALSE NEGATIVE
#> [1] TRUE
schema_vague$validate(text_valid)
#> [1] TRUE
schema_vague$validate(text_valid_null)
#> [1] TRUE


schema_text_specific <- '
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://raw.githubusercontent.com/hubverse-org/schemas/main/v3.0.1/tasks-schema.json",
    "title": "Schema for Modeling Hub model task definitions",
    "description": "This is the schema of the tasks.json configuration file that defines the tasks within a modeling hub.",
    "type": "object",
    "properties": {
        "target_keys": {
            "type": [
                "object",
                "null"
                ],
            "additionalProperties": {
                "type": "string"

            }
        }
    }
}
'

schema <- jsonvalidate::json_schema$new(schema_text_specific)
schema$validate(text_invalid)
#> [1] FALSE
schema$validate(text_valid)
#> [1] TRUE
schema$validate(text_valid_null)
#> [1] TRUE

Copy link

@matthewcornell matthewcornell left a comment

Choose a reason for hiding this comment

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

looks good!

@elray1
Copy link
Contributor

elray1 commented Oct 16, 2024

agreed, looks good, thanks!

@annakrystalli annakrystalli merged commit 392cfdc into br-v4.0.0 Oct 16, 2024
3 checks passed
@annakrystalli annakrystalli deleted the ak/target_keys-schema/97 branch October 16, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

double check setup for target_metadata.target_keys
3 participants