Closed chan-vince closed 2 years ago
Hi,
What this seems to request is a way to constrain the str
data type, something that pydantic does: https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
But, we have the schema that does the validation later on, so pydantic can be skipped.
Anyway, according to the spec and the schema IdToken is a str Type, so that is what we should use. Thanks for your analysis ;)
Fi
When making an Authorize request from the Charge Point to the Central System, the request is an instance of
call.AuthorizePayload
:Note that the
id_tag
is of typestr
, and the OCPP-J v1.6 spec says it should be anIdToken
type. Since this is basically the same as a string but constrained to a 20 character case-insensitive string, this is fine.The response must be an instance of
call_result.AuthorizePayload
:Where there is a dataclass for
id_tag_info
(though not yet added to the above dataclass) defined indatatypes.py
:The spec says that
parent_id_tag
is also anIdToken
. However in thisIdTagInfo
dataclass it's anIdToken
dataclass, with anid_token
str attribute inside. Therefore, in acall_result.AuthorizePayload
it gets serialised to json like this:When this is received back at the Charge Point, it then fails the json schema validation because it's expecting the idToken to be a
str
as defined in the json schema. If schema validation is skpped, only then do you get a helpful exception:I'm not sure why this only gets raised when
skip_schema_validation
is enabled on theon
decorator - unfotunately it seems to not be surfaced as otherwise the websocket disconnects instantly:I think the fix here is to remove the dataclass for
IdToken
and make theIdTagInfo
be type annotated like so:I tested this by adding this
id_tag_info
to acall_result.AuthorizePayload
which works, despite it obviously going against the dataclass definition/type hinting.