Skip to content

Commit 863c201

Browse files
authored
feat(docs): generate json schema for config (#206)
* chore(docs): initial commit * feat(docs): poc for codegen * docs: troubleshooting * feat(docs): finish codegen * fix: docs * fix: diagnostics in docs * fix: docs * fix: docs * fix: lint * feat: integrate docs codegen into ci * feat: generate and release schema.json * fix: cleanup * fix: undo lint fix again
1 parent 379ade4 commit 863c201

File tree

14 files changed

+1033
-17
lines changed

14 files changed

+1033
-17
lines changed

.github/workflows/pull_request.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ jobs:
8686
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8787
- name: Run Lints
8888
run: |
89-
cargo clippy --fix
89+
cargo clippy
9090
cargo run -p rules_check
91-
- name: Check for git diff after lint fix
92-
run: |
93-
if [[ $(git status --porcelain) ]]; then
94-
git status
95-
git diff
96-
exit 1
97-
fi
91+
# - name: Check for git diff after lint fix
92+
# run: |
93+
# if [[ $(git status --porcelain) ]]; then
94+
# git status
95+
# git diff
96+
# exit 1
97+
# fi
9898

9999
# check-dependencies:
100100
# name: Check Dependencies

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: 🛠️ Run Build
6464
run: cargo build -p pglt_cli --release --target ${{ matrix.config.target }}
6565

66-
# windows is a special snowflake to, it saves binaries as .exe
66+
# windows is a special snowflake too, it saves binaries as .exe
6767
- name: 👦 Name the Binary
6868
if: matrix.config.os == 'windows-latest'
6969
run: |
@@ -124,7 +124,9 @@ jobs:
124124
token: ${{ secrets.GITHUB_TOKEN }}
125125
body: ${{ steps.create_changelog.outputs.content }}
126126
tag_name: ${{ steps.create_changelog.outputs.version }}
127-
files: pglt_*
127+
files: |
128+
pglt_*
129+
docs/schemas/latest/schema.json
128130
fail_on_unmatched_files: true
129131
draft: true
130132

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pglt_configuration/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ version = "0.0.0"
1212

1313

1414
[dependencies]
15-
biome_deserialize = { workspace = true }
15+
biome_deserialize = { workspace = true, features = ["schema"] }
1616
biome_deserialize_macros = { workspace = true }
1717
bpaf = { workspace = true }
18+
indexmap = { workspace = true }
1819
pglt_analyse = { workspace = true }
1920
pglt_analyser = { workspace = true }
2021
pglt_console = { workspace = true }
@@ -30,4 +31,4 @@ toml = { workspace = true }
3031
doctest = false
3132

3233
[features]
33-
schema = ["dep:schemars"]
34+
schema = ["dep:schemars", "schemars/indexmap"]

crates/pglt_configuration/src/database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
55
/// The configuration of the database connection.
66
#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
77
#[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))]
8+
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
89
#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))]
910
pub struct DatabaseConfiguration {
1011
/// The host of the database.

crates/pglt_configuration/src/files.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub const DEFAULT_FILE_SIZE_LIMIT: NonZeroU64 =
1313
/// The configuration of the filesystem
1414
#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
1515
#[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))]
16+
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
1617
#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))]
1718
pub struct FilesConfiguration {
1819
/// The maximum allowed size for source code files in bytes. Files above

crates/pglt_configuration/src/migrations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
66
#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize, Default)]
77
#[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))]
88
#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))]
9+
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
910
pub struct MigrationsConfiguration {
1011
/// The directory where the migration files are stored
1112
#[partial(bpaf(long("migrations-dir")))]

docs/codegen/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ regex = { workspace = true }
1616
toml = { workspace = true }
1717
anyhow = { workspace = true }
1818
bpaf = { workspace = true, features = ["docgen"] }
19+
schemars = { workspace = true }
20+
serde = { workspace = true }
21+
serde_json = { workspace = true }
22+
pulldown-cmark = "0.12.2"
1923

20-
pglt_configuration = { workspace = true }
24+
pglt_configuration = { workspace = true, features = ["schema"] }
2125
pglt_flags = { workspace = true }
2226
pglt_cli = { workspace = true }
2327
pglt_analyse = { workspace = true }
@@ -28,5 +32,4 @@ pglt_workspace = { workspace = true }
2832
pglt_statement_splitter = { workspace = true }
2933
pglt_console = { workspace = true }
3034
biome_string_case = { workspace = true }
31-
pulldown-cmark = "0.12.2"
3235

docs/codegen/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ pub mod env_variables;
44
pub mod rules_docs;
55
pub mod rules_index;
66
pub mod rules_sources;
7+
pub mod schema;
78

89
mod utils;

docs/codegen/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use docs_codegen::env_variables::generate_env_variables;
77
use docs_codegen::rules_docs::generate_rules_docs;
88
use docs_codegen::rules_index::generate_rules_index;
99
use docs_codegen::rules_sources::generate_rule_sources;
10+
use docs_codegen::schema::generate_schema;
1011

1112
fn docs_root() -> PathBuf {
1213
let dir =
@@ -23,6 +24,7 @@ fn main() -> anyhow::Result<()> {
2324
generate_rules_docs(&docs_root)?;
2425
generate_rules_index(&docs_root)?;
2526
generate_rule_sources(&docs_root)?;
27+
generate_schema(&docs_root)?;
2628

2729
Ok(())
2830
}

0 commit comments

Comments
 (0)