Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Pydantic field validations should not be stricter than the Structurizr server #40

Open
yt-ms opened this issue Oct 19, 2020 · 3 comments

Comments

@yt-ms
Copy link
Collaborator

yt-ms commented Oct 19, 2020

Problem description

With a new workspace in the Structurizr UI, many fields are optional (may be left blank). The model we have using Pydantic is more strict than this, which means that trying to get the workspace fails on deserialisation.

Code Sample

The stacktrace below is from creating a new workspace with a system context view that has no description. There may well be a host of other fields with the same problem.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\users\xxx\dev\structurizr-python\src\structurizr\api\structurizr_client.py", line 145, in get_workspace
    return Workspace.hydrate(WorkspaceIO.parse_raw(response.text))
  File "pydantic\main.py", line 478, in pydantic.main.BaseModel.parse_raw
  File "pydantic\main.py", line 455, in pydantic.main.BaseModel.parse_obj
  File "pydantic\main.py", line 346, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for WorkspaceIO
views -> systemContextViews -> 0 -> description
  field required (type=value_error.missing)

Context

System Information
==================
OS         Windows
OS-release      10
Python       3.7.5

Package Versions
================
depinfo                       1.5.4
httpx                        0.15.3
importlib_metadata            1.7.0
ordered-set                     3.1
pip                          20.2.4
pydantic                      1.6.1
python-dotenv                0.14.0
setuptools                   41.2.0
structurizr-python 0.1.0+1.g58d76cb
@Midnighter
Copy link
Owner

Best would be a systematic comparison with the OpenAPI schema, I suppose.
https://editor.swagger.io/?url=https://raw.githubusercontent.com/structurizr/json/master/structurizr.yaml

@yt-ms
Copy link
Collaborator Author

yt-ms commented Oct 19, 2020

Best would be a systematic comparison with the OpenAPI schema, I suppose.
https://editor.swagger.io/?url=https://raw.githubusercontent.com/structurizr/json/master/structurizr.yaml

Unless I'm missing something, none of the properties are marked as required in the YAML!

@Midnighter
Copy link
Owner

Hah, fair enough. That's probably because the Java classes can be empty instances. However, for some measure of sanity checking, I chose to add a few required arguments on the classes which means those keys should also be required by pydantic. However, if everything is empty, class instantiation should probably just be ignored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants