Skip to content

How to handle "one of" validation checks for headers? #25

@kosack

Description

@kosack

in JSONSchema you can specify oneOf: to mix two possible classes in a schema. This would be useful e.g for reference positions in the FITS v4 standard, where tthe keywords change depending on if you choose TREFPOS=TOPOCENTER vs GEOCENTER, HELIOCENTER, etc.

If we want to make a schema that allows multiple possibilites, we would need a way to validate those.

One option would be the more brute-force method, but easiest: just set all possible keywords as required=false, and also add a extra_validation() abstract method to HeaderSchema that sub-classes can override and do final complex checks. That would run after the normal validation, and the user could e.g. check for the correct sets of keywords.

Or maybe making some sort of compound-patterned HeaderSchema class that checks that one of the immediate parent classes is valid, and only raises an error if none pass, e.g.:

class OneOf(HeaderSchema):
    """Like HeaderSchema, but only checks if one of the base classes is valid"""
    ...


class MyTable(BinaryTable):

   class __headers__(TimeHeaders, CreatorHeaders, OneOf(TopoReferenceHeaders, GeoReferenceHeaders)):
       pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions