Skip to content

Commit

Permalink
Add Protobuf Serializer
Browse files Browse the repository at this point in the history
This adds the ability to serialize `voluptuous` schemas to `.proto`
files which can be used in many other contexts such as API client generation or
docs generation.

This could be used to auto-generate home-assistant documentation
reference pages for all yaml schemas as suggested in [this post](home-assistant/core#86050).

See the addition in the readme for an example.
  • Loading branch information
jonnylangefeld committed Jan 17, 2023
1 parent 25a346e commit 9b1b481
Show file tree
Hide file tree
Showing 7 changed files with 691 additions and 2 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,30 @@ def custom_convert(value):

convert(value, custom_serializer=custom_convert)
```

## Proto File Generation

[Protocol Buffers](https://developers.google.com/protocol-buffers/docs/proto) are a powerful tool
to describe structured data. In addition to the undocument json serialization it is useful to add
a proto serialization which can be used in many other contexts such as API client generation or
docs generation.

You can try it out via

```python
python3 example.py > sample.proto
```

> A prerequisite is to install []() and [`protoc`](). This is an example install command for mac:
> ```shell
> brew install protobuf
> go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
> ```
And then generate the docs via
```shell
protoc --doc_out=./docs --doc_opt=html,docs.html sample.proto  ✔  voluptuous-serialize 🐍  16:11:17 
protoc --doc_out=./docs --doc_opt=markdown,docs.md sample.proto
```
Check out the docs in the [`/docs`](/docs) directory.
Loading

0 comments on commit 9b1b481

Please sign in to comment.