Skip to content

Commit 4df1346

Browse files
committed
cargo fmt, update README, update publish.yml
1 parent 018857a commit 4df1346

File tree

3 files changed

+118
-37
lines changed

3 files changed

+118
-37
lines changed

.github/workflows/publish.yml

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
11
on:
22
push:
3-
branches:
4-
- master
3+
tags:
4+
- v*
5+
56
jobs:
6-
publish:
7+
create_release:
78
runs-on: ubuntu-latest
9+
outputs:
10+
upload_url: ${{ steps.create_release.outputs.upload_url }}
11+
steps:
12+
- id: create_release
13+
uses: actions/create-release@v1
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
with:
17+
tag_name: ${{ github.ref }}
18+
release_name: ${{ github.ref }}
19+
20+
release_binary:
21+
runs-on: ${{ matrix.runs_on }}
22+
needs: create_release
23+
strategy:
24+
matrix:
25+
target:
26+
- x86_64-unknown-linux-gnu
27+
- x86_64-unknown-linux-musl
28+
- x86_64-apple-darwin
29+
- x86_64-pc-windows-gnu
30+
include:
31+
- target: x86_64-unknown-linux-gnu
32+
runs_on: ubuntu-latest
33+
artifact: jtd-infer
34+
- target: x86_64-unknown-linux-musl
35+
runs_on: ubuntu-latest
36+
artifact: jtd-infer
37+
- target: x86_64-apple-darwin
38+
runs_on: macos-latest
39+
artifact: jtd-infer
40+
- target: x86_64-pc-windows-gnu
41+
runs_on: ubuntu-latest
42+
artifact: jtd-infer.exe
843
steps:
944
- uses: actions/checkout@v2
1045
- uses: actions-rs/toolchain@v1
1146
with:
1247
toolchain: stable
13-
- run: cargo publish
48+
- run: cargo install cross
49+
- run: cross build --release --target=$TARGET
1450
env:
15-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
51+
TARGET: ${{ matrix.target }}
52+
- run: zip --junk-paths $TARGET.zip target/$TARGET/release/$ARTIFACT
53+
env:
54+
TARGET: ${{ matrix.target }}
55+
ARTIFACT: ${{ matrix.artifact }}
56+
- uses: actions/upload-release-asset@v1
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
upload_url: ${{ needs.create_release.outputs.upload_url }}
61+
asset_path: ${{ matrix.target }}.zip
62+
asset_name: ${{ matrix.target }}.zip
63+
asset_content_type: application/zip

README.md

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,64 @@
11
# jtd-infer
22

3-
`jtd-infer` generates a JSON Typedef schema from example data.
3+
`jtd-infer` generates ("infers") a JSON Typedef schema from example data.
44

5-
For high-level guidance on how to use this package, see ["Inferring a JSON
6-
Typedef Schema from Real Data"][jtd-jtd-infer] in the JSON Typedef docs.
5+
```bash
6+
echo '{ "name": "Joe", "age": 42 }' | jtd-infer | jq
7+
```
8+
9+
```json
10+
{
11+
"properties": {
12+
"age": {
13+
"type": "uint8"
14+
},
15+
"name": {
16+
"type": "string"
17+
}
18+
}
19+
}
20+
```
721

822
## Installation
923

1024
To install `jtd-infer`, you have a few options:
1125

12-
### Install with Homebrew
26+
### Install on macOS
1327

14-
This option is recommended if you're on macOS.
28+
You can install `jtd-infer` via Homebrew:
1529

1630
```bash
1731
brew install jsontypedef/jsontypedef/jtd-infer
1832
```
1933

34+
Alternatively, you can download and extract the binary yourself from
35+
`x86_64-apple-darwin.zip` in [the latest release][latest]. Because of Apple's
36+
quarantine system, you will need to run:
37+
38+
```bash
39+
xattr -d com.apple.quarantine path/to/jtd-infer
40+
```
41+
42+
In order to be able to run the executable.
43+
44+
### Install on Linux
45+
46+
Download and extract the binary from `x86_64-unknown-linux-gnu.zip` in [the
47+
latest release][latest].
48+
49+
### Install on Windows
50+
51+
Download and extract the binary from `x86_64-pc-windows-gnu.zip` in [the latest
52+
release][latest]. Runs on 64-bit MinGW for Windows 7+.
53+
2054
### Install with Docker
2155

22-
This option is recommended on non-Mac platforms, or if you're running
23-
`jtd-infer` in some sort of script and you want to make sure that everyone
24-
running the script uses the same version of `jtd-infer`.
56+
This option is recommended if you're running `jtd-infer` in some sort of script
57+
and you want to make sure that everyone running the script uses the same version
58+
of `jtd-infer`.
2559

2660
```bash
27-
docker pull jsontypedef/jtd-tools
61+
docker pull jsontypedef/jtd-infer
2862
```
2963

3064
If you opt to use the Docker approach, you will need to change all invocations
@@ -37,31 +71,30 @@ jtd-infer [...]
3771
To:
3872

3973
```bash
40-
docker exec -it jsontypedef/jtd-tools /jtd-infer [...]
41-
```
42-
43-
### Install with Cargo
44-
45-
This option is recommended if you already have `cargo` installed, or if you
46-
would prefer to use a version of `jtd-infer` compiled on your machine:
74+
# To have jtd-infer read from STDIN, run it like so:
75+
docker exec -i jsontypedef/jtd-infer [...]
4776

48-
```bash
49-
cargo install jtd-infer
77+
# To have jtd-infer read from a file, run it as:
78+
docker run -v /path/to/file.json:/file.json -i jsontypedef/jtd-infer [...] file.json
79+
# or, if file.json is in your current directory:
80+
docker run -v $(pwd)/file.json:/file.json -i jsontypedef/jtd-infer [...] file.json
5081
```
5182

5283
## Usage
5384

54-
> See the top of this README for links to high-level guidance on how to use
55-
> `jtd-infer`.
85+
For high-level guidance on how to use `jtd-infer`, see ["Inferring a JSON
86+
Typedef Schema from Real Data"][jtd-jtd-infer] in the JSON Typedef website docs.
87+
88+
### Basic Usage
5689

5790
To invoke `jtd-infer`, you can either:
5891

5992
1. Have it read from STDIN. This is the default behavior.
6093
2. Have it read from a file. To do this, pass a file name as the last argument
6194
to `jtd-infer`.
6295

63-
`jtd-infer` can read a _sequence_ of JSON messages. So for example, if you have
64-
a file like this in `data.json`:
96+
`jtd-infer` reads a _sequence_ of JSON messages. So for example, if you have a
97+
file like this in `data.json`:
6598

6699
```json
67100
{ "name": "john doe", "age": 42 }
@@ -82,7 +115,7 @@ In both cases, you'd get this output:
82115
{"properties":{"name":{"type":"string"},"age":{"type":"uint8"}}}
83116
```
84117

85-
## Advanced Usage: Providing Hints
118+
### Advanced Usage: Providing Hints
86119

87120
By default, `jtd-infer` will never output `enum`, `values`, or `discriminator`
88121
schemas. This is by design: by always being consistent with what it outputs,
@@ -102,7 +135,7 @@ As a corner-case, if you want to point to the *root* / top-level of your input,
102135
then use the empty string as the path. See ["Using
103136
`--values-hint`"](##using---values-hint) for an example of this.
104137

105-
### Using `--enum-hint`
138+
#### Using `--enum-hint`
106139

107140
By default, strings are always inferred to be `{ "type": "string" }`:
108141

@@ -126,7 +159,7 @@ echo '["foo", "bar", "baz"]' | jtd-infer --enum-hint=/-
126159
{"elements":{"enum":["bar","baz","foo"]}}
127160
```
128161

129-
### Using `--values-hint`
162+
#### Using `--values-hint`
130163

131164
By default, objects are always assumed to be "structs", and `jtd-infer` will
132165
generate `properties` / `optionalProperties`. For example:
@@ -151,7 +184,7 @@ echo '{"x": [1, 2, 3], "y": [4, 5, 6], "z": [7, 8, 9]}' | jtd-infer --values-hin
151184
{"values":{"elements":{"type":"uint8"}}}
152185
```
153186

154-
### Using `--discriminator-hint`
187+
#### Using `--discriminator-hint`
155188

156189
By default, objects are always assumed to be "structs", and `jtd-infer` will
157190
generate `properties` / `optionalProperties`. For example:
@@ -197,3 +230,4 @@ echo '[{"type": "s", "value": "foo"},{"type": "n", "value": 3.14}]' | jtd-infer
197230
```
198231

199232
[jtd-jtd-infer]: https://jsontypedef.com/docs/tools/jtd-infer
233+
[latest]: https://github.com/jsontypedef/json-typedef-infer/releases/latest

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
mod hint_set;
22

3+
use chrono::DateTime;
34
pub use hint_set::HintSet;
5+
use jtd::form::{self, TypeValue};
6+
use jtd::{Form, Schema};
7+
use serde_json::Value;
8+
use std::collections::HashMap;
49
use std::collections::HashSet;
510

611
#[derive(Debug)]
@@ -40,12 +45,6 @@ impl<'a> Hints<'a> {
4045
}
4146
}
4247

43-
use chrono::DateTime;
44-
use jtd::form::{self, TypeValue};
45-
use jtd::{Form, Schema};
46-
use serde_json::Value;
47-
use std::collections::HashMap;
48-
4948
#[derive(Debug)]
5049
pub enum InferredSchema {
5150
Unknown,

0 commit comments

Comments
 (0)