flexiblepower/s2-ws-json

JSON Schema Validation Issue

Closed this issue · 2 comments

Hello,
Thanks for developing this flexibility standard!

I've been using s2 protocol jsonschema description to validate some entities/messages but I've encountered an issue when validating referenced schemas. Apparently, this tiny example for a FRBC.OperationModeElement passes validation when It shouldn't:

    {
        "fill_level_range": [0.1, 0.2, 0.3],
        "fill_rate":  {
            "start_of_range": 0,
            "end_of_range": 0.1
        },
        "power_ranges": [
            {
                "start_of_range": 5725,
                "end_of_range": 5725,
                "commodity_quantity": "ELECTRIC.POWER.L1"
            }
        ],
        "running_costs": {
            "start_of_range": 0,
            "end_of_range": 0
        }
    }

fill_level_range should be of type NumberRange but passing a list just works. If I use a dict instead of the list, validation works (checks key and values).

I've tried this with python-jsonschema validator and a web validator to check if It was a bug in the implementation of validator but both yield the same result. Not sure if this is an expected behavior of jsonschema or the definition of s2-protocol in jsonschema but I'm not sure how to figure it out so I'm reaching you for some enlightenment.

Thanks a lot in advanced.

Regards,
Víctor

Hi Víctor,

Thanks for reaching out! That JSON message shouldn't successfully validate against the schema. It seems most validators don't follow the reference (e.g. "$ref": "../schemas/NumberRange.schema.json",) without any warnings or errors whatsoever. If you replace the reference with the actual definition the JSON doesn't validate. I'm not sure yet if this is a problem with the mentioned validators or that we do something wrong with defining these references. I'll look into it...

Cheers,
Wilco

Hi Wilco,

Thank for the response!

I'm not really experienced with jsonschema, but the references look good for me. I think I've tried the same with the asyncapi validator and It didn't validate (as expected).

For now, we're using pydantic models that generated with the tool datamodel-codegen, but we are refactoring the models manually to a better file structure. With pydantic, the inner types are constrained and we get the benefit of being used in frameworks such as FastAPI. So far, we have generated / revised the code for the FRBC operation mode, but we are looking forward to do the others, also in collaboration with other parties using the protocol 😄.

The python module is in here. Feel free to check it out and/or propose any change.

Thanks,
Víctor