How to use the pydantic.root_validator function in pydantic

To help you get started, we’ve selected a few pydantic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelcolvin / pydantic / tests / mypy / modules / success.py View on Github external
    @root_validator
    def root_check(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        return values
github nazrulworld / fhir.resources / fhir / resources / STU3 / questionnaire.py View on Github external
    @root_validator(pre=True)
    def validate_one_of_many(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """https://www.hl7.org/fhir/formats.html#choice
        A few elements have a choice of more than one data type for their content.
        All such elements have a name that takes the form nnn[x].
        The "nnn" part of the name is constant, and the "[x]" is replaced with
        the title-cased name of the type that is actually used.
        The table view shows each of these names explicitly.

        Elements that have a choice of data type cannot repeat - they must have a
        maximum cardinality of 1. When constructing an instance of an element with a
        choice of types, the authoring system must create a single element with a
        data type chosen from among the list of permitted data types.
        """
        one_of_many_fields = {
            "answer": [
                "answerAttachment",
github nazrulworld / fhir.resources / fhir / resources / careplan.py View on Github external
    @root_validator(pre=True)
    def validate_one_of_many(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """https://www.hl7.org/fhir/formats.html#choice
        A few elements have a choice of more than one data type for their content.
        All such elements have a name that takes the form nnn[x].
        The "nnn" part of the name is constant, and the "[x]" is replaced with
        the title-cased name of the type that is actually used.
        The table view shows each of these names explicitly.

        Elements that have a choice of data type cannot repeat - they must have a
        maximum cardinality of 1. When constructing an instance of an element with a
        choice of types, the authoring system must create a single element with a
        data type chosen from among the list of permitted data types.
        """
        one_of_many_fields = {
            "product": ["productCodeableConcept", "productReference"],
            "scheduled": ["scheduledPeriod", "scheduledString", "scheduledTiming"],
github QwantResearch / idunn / idunn / api / places_list.py View on Github external
    @root_validator(skip_on_failure=True)
    def categories_or_raw_filters(cls, values):
        if values.get("raw_filter") and values.get("category"):
            raise HTTPException(
                status_code=400,
                detail="Both 'raw_filter' and 'category' parameters cannot be provided together",
            )
        return values
github balsam-alcf / balsam / balsam / api / models.py View on Github external
    @root_validator(pre=False)
    def validate_source_dest(cls, values):
        """
        Validate `source` and `destination` URL/Path and make the other fields consistent.
        """
        direction = values.get("direction")
        source = values["source"]
        dest = values["destination"]
        if direction == "in":
            cls.validate_remote_url(source, values)
            cls.validate_rel_path(dest, values)
            values["source_path"] = source.path
            values["destination_path"] = dest
        else:
            cls.validate_remote_url(dest, values)
            cls.validate_rel_path(source, values)
            values["source_path"] = source
github checktheroads / hyperglass / hyperglass / parsing / models / juniper.py View on Github external
    @root_validator(pre=True)
    def validate_optional_flags(cls, values):
        """Flatten & rename keys prior to validation."""
        next_hop = values.pop("nh")
        selected_next_hop = ""

        for hop in next_hop:
            if "selected-next-hop" in hop:
                selected_next_hop = hop.get("to", "")
                break

        values["next-hop"] = selected_next_hop

        _path_attr = values.get("bgp-path-attributes", {})
        _path_attr_agg = _path_attr.get("attr-aggregator", {}).get("attr-value", {})
        values["as-path"] = _path_attr.get("attr-as-path-effective", {}).get(
            "attr-value", ""
github peopledoc / ml-versioning-tools / mlvtools / conf / conf.py View on Github external
    @root_validator
    def set_docstring_conf_path(cls, values):
        if values["docstring_conf"]:
            values["docstring_conf"] = join(values["top_directory"], values["docstring_conf"])
        return values
github nazrulworld / fhir.resources / fhir / resources / DSTU2 / valueset.py View on Github external
    @root_validator(pre=True)
    def validate_one_of_many(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """https://www.hl7.org/fhir/formats.html#choice
        A few elements have a choice of more than one data type for their content.
        All such elements have a name that takes the form nnn[x].
        The "nnn" part of the name is constant, and the "[x]" is replaced with
        the title-cased name of the type that is actually used.
        The table view shows each of these names explicitly.

        Elements that have a choice of data type cannot repeat - they must have a
        maximum cardinality of 1. When constructing an instance of an element with a
        choice of types, the authoring system must create a single element with a
        data type chosen from among the list of permitted data types.
        """
        one_of_many_fields = {
            "value": [
                "valueBoolean",
github nazrulworld / fhir.resources / fhir / resources / library.py View on Github external
    @root_validator(pre=True)
    def validate_one_of_many(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """https://www.hl7.org/fhir/formats.html#choice
        A few elements have a choice of more than one data type for their content.
        All such elements have a name that takes the form nnn[x].
        The "nnn" part of the name is constant, and the "[x]" is replaced with
        the title-cased name of the type that is actually used.
        The table view shows each of these names explicitly.

        Elements that have a choice of data type cannot repeat - they must have a
        maximum cardinality of 1. When constructing an instance of an element with a
        choice of types, the authoring system must create a single element with a
        data type chosen from among the list of permitted data types.
        """
        one_of_many_fields = {"subject": ["subjectCodeableConcept", "subjectReference"]}
        for prefix, fields in one_of_many_fields.items():
            assert cls.__fields__[fields[0]].field_info.extra["one_of_many"] == prefix
github nazrulworld / fhir.resources / fhir / resources / valueset.py View on Github external
    @root_validator(pre=True)
    def validate_one_of_many(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        """https://www.hl7.org/fhir/formats.html#choice
        A few elements have a choice of more than one data type for their content.
        All such elements have a name that takes the form nnn[x].
        The "nnn" part of the name is constant, and the "[x]" is replaced with
        the title-cased name of the type that is actually used.
        The table view shows each of these names explicitly.

        Elements that have a choice of data type cannot repeat - they must have a
        maximum cardinality of 1. When constructing an instance of an element with a
        choice of types, the authoring system must create a single element with a
        data type chosen from among the list of permitted data types.
        """
        one_of_many_fields = {
            "value": [
                "valueBoolean",