https://github.com/extremeheat/protodef-yaml
Transforms YAML-like syntax to ProtoDef JSON schema and HTML documentation
https://github.com/extremeheat/protodef-yaml
json protodef
Last synced: 8 months ago
JSON representation
Transforms YAML-like syntax to ProtoDef JSON schema and HTML documentation
- Host: GitHub
- URL: https://github.com/extremeheat/protodef-yaml
- Owner: extremeheat
- License: mit
- Created: 2021-02-07T07:25:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T22:07:30.000Z (over 1 year ago)
- Last Synced: 2025-03-18T22:11:19.038Z (over 1 year ago)
- Topics: json, protodef
- Language: JavaScript
- Homepage: https://extremeheat.github.io/protodef-yaml/editor/
- Size: 466 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: docs/README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# protodef-yaml
[](http://npmjs.com/package/protodef-yaml)
[](https://github.com/extremeheat/protodef-yaml/actions?query=workflow%3A%22CI%22)
[](https://discord.gg/GsEFRM8)
[](https://gitpod.io/#https://github.com/extremeheat/protodef-yaml)
Transforms YAML-like syntax to ProtoDef JSON schema and HTML documentation. [See a live demo!](https://extremeheat.github.io/protodef-yaml/editor/)
### Usage
```sh
npm install -g protodef-yaml
protodef-yaml # generate json
protodef-yaml # generate docs
```
or through npx,
```
npx protodef-yaml input.yml
npx protodef-yaml input.yml docs.html
```
### API
See [API.md](./API.md)
### Syntax
Refer to [this documentation](https://github.com/PrismarineJS/bedrock-protocol/blob/master/docs/CONTRIBUTING.md#packet-serialization), also see test/ for example files.
Example input:
```yaml
ScoreEntries:
type: u8 =>
0: change
1: remove
entries: []varint
scoreboard_id: zigzag64
objective_name: string
score: li32
optional?: bool
_: type?
if remove:
entry_type: i8 =>
1: player
2: entity
3: fake_player
_: entry_type?
if player or entity:
entity_unique_id: zigzag64
if fake_player:
custom_name: string
```
**Output**
Click to see JSON
```json
{
"ScoreEntries": [
"container",
[
{
"name": "type",
"type": [
"mapper",
{
"type": "u8",
"mappings": {
"0": "change",
"1": "remove"
}
}
]
},
{
"name": "entries",
"type": [
"array",
{
"countType": "varint",
"type": [
"container",
[
{
"name": "scoreboard_id",
"type": "zigzag64"
},
{
"name": "objective_name",
"type": "string"
},
{
"name": "score",
"type": "li32"
},
{
"name": "optional",
"type": [
"option",
"bool"
]
},
{
"anon": true,
"type": [
"switch",
{
"compareTo": "../type",
"fields": {
"remove": [
"container",
[
{
"name": "entry_type",
"type": [
"mapper",
{
"type": "i8",
"mappings": {
"1": "player",
"2": "entity",
"3": "fake_player"
}
}
]
},
{
"anon": true,
"type": [
"switch",
{
"compareTo": "entry_type",
"fields": {
"player": [
"container",
[
{
"name": "entity_unique_id",
"type": "zigzag64"
}
]
],
"entity": [
"container",
[
{
"name": "entity_unique_id",
"type": "zigzag64"
}
]
],
"fake_player": [
"container",
[
{
"name": "custom_name",
"type": "string"
}
]
]
},
"default": "void"
}
]
}
]
]
},
"default": "void"
}
]
}
]
]
}
]
}
]
]
}
```
### Info
The differences to YAML:
* parent nodes with children can have a value
* keys starting with '!' are ignored in the final output
You can also embed JSON for custom ProtoDef types as usual as YAML is a superset of JSON, for example:
```yaml
string: ["pstring", {"countType": "i32"}]
```