Closed yt-ms closed 3 years ago
To make it simpler to work with workspaces outside the Structurizr API, Workspace should be extended to allow loading and saving from/to files and strings. Mirroring the JSON api, we should support something like:
Workspace
@classmethod Workspace.load(cls, file: Union[str, Path]) -> Workspace # Already supported, handles zipped and unzipped @classmethod Workspace.loads(json_string: str) -> Workspace Workspace.dump(file: Union[str, Path], *, zip: bool = False, indent: int = None) -> None Workspace.dumps(*, indent: int = None) -> str
We should consider adding a **kwargs which gets passed through to the json method to allow finer-grained control of (de)serialisatoin.
**kwargs
json
Currently to write to file, you have to do something along the lines of:
with open("my-workspace.json", "w") as f: f.write(WorkspaceIO.from_orm(workspace).json(indent=2))
which is a bit of a faff.
It'd also be good to show saving and loading to/from file in an example.
Checklist
Describe the solution you would like.
To make it simpler to work with workspaces outside the Structurizr API,
Workspace
should be extended to allow loading and saving from/to files and strings. Mirroring the JSON api, we should support something like:We should consider adding a
**kwargs
which gets passed through to thejson
method to allow finer-grained control of (de)serialisatoin.Additional context
Currently to write to file, you have to do something along the lines of:
which is a bit of a faff.
It'd also be good to show saving and loading to/from file in an example.