You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The models in datamodel are generated by Swagger Editor, using the API definitions in SDX Controller and SDX LC. The parsing and validation code is hand-rolled. A nicer way to do this same thing would be using pydantic.
Consider a simple model, Location, re-written using pydantic:
>>>frompprintimportpprint>>>frompydanticimportValidationError>>>try:
... l2=Location(address=1, latitude="top", longitude="bottom", iso3166_2_lvl4=1)
... exceptValidationErrorase:
... pprint(e.errors())
...
[{'input': 1,
'loc': ('address',),
'msg': 'Input should be a valid string',
'type': 'string_type',
'url': 'https://errors.pydantic.dev/2.8/v/string_type'},
{'input': 'top',
'loc': ('latitude',),
'msg': 'Input should be a valid number, unable to parse string as a number',
'type': 'float_parsing',
'url': 'https://errors.pydantic.dev/2.8/v/float_parsing'},
{'input': 'bottom',
'loc': ('longitude',),
'msg': 'Input should be a valid number, unable to parse string as a number',
'type': 'float_parsing',
'url': 'https://errors.pydantic.dev/2.8/v/float_parsing'},
{'input': 1,
'loc': ('iso3166_2_lvl4',),
'msg': 'Input should be a valid string',
'type': 'string_type',
'url': 'https://errors.pydantic.dev/2.8/v/string_type'}]
The text was updated successfully, but these errors were encountered:
The models in datamodel are generated by Swagger Editor, using the API definitions in SDX Controller and SDX LC. The parsing and validation code is hand-rolled. A nicer way to do this same thing would be using pydantic.
Consider a simple model, Location, re-written using pydantic:
We can now do:
And the validation errors have more information:
The text was updated successfully, but these errors were encountered: