Browse Source

Add schema generator

tags/v0.3.5-fix4
haixuanTao 1 year ago
parent
commit
83779045e6
4 changed files with 46 additions and 2 deletions
  1. +1
    -2
      Cargo.lock
  2. +1
    -0
      libraries/core/Cargo.toml
  3. +7
    -0
      libraries/core/README.md
  4. +37
    -0
      libraries/core/src/bin/generate_schema.rs

+ 1
- 2
Cargo.lock View File

@@ -2306,6 +2306,7 @@ dependencies = [
"schemars",
"serde",
"serde-with-expand-env",
"serde_json",
"serde_yaml 0.9.30",
"tokio",
"tracing",
@@ -2523,8 +2524,6 @@ dependencies = [
"dora-tracing",
"eyre",
"parquet",
"schemars",
"serde_json",
"tokio",
]



+ 1
- 0
libraries/core/Cargo.toml View File

@@ -21,3 +21,4 @@ serde-with-expand-env = "1.1.0"
tokio = { version = "1.24.1", features = ["fs", "process", "sync"] }
aligned-vec = { version = "0.5.0", features = ["serde"] }
schemars = "0.8.19"
serde_json = "1.0.117"

+ 7
- 0
libraries/core/README.md View File

@@ -0,0 +1,7 @@
# Core library for dora

## Generating dora schema

```bash
cargo run -p dora-core generate_schemas
```

+ 37
- 0
libraries/core/src/bin/generate_schema.rs View File

@@ -0,0 +1,37 @@
use std::{env, path::Path};

use dora_core::descriptor::Descriptor;
use schemars::schema_for;

fn main() -> () {
let schema = schema_for!(Descriptor);
let raw_schema =
serde_json::to_string_pretty(&schema).expect("Could not serialize schema to json");
let raw_schema = raw_schema.replace(
"\"additionalProperties\": false",
"\"additionalProperties\": true",
);

// Remove `serde(from=` nested field as they are not handled properly by `schemars`
let raw_schema = raw_schema.replace(
"\"python\": {
\"$ref\": \"#/definitions/PythonSource\"
}",
"",
);
let raw_schema = raw_schema.replace(
"{
\"$ref\": \"#/definitions/Input\"
}",
"true",
);

// Get the Cargo root manifest directory
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not set");

// Create the path for the new file next to Cargo.toml
let new_file_path = Path::new(&manifest_dir).join("dora-schema.json");

// write to file
std::fs::write(new_file_path, raw_schema).expect("Could not write schema to file");
}

Loading…
Cancel
Save