it wooorks
This commit is contained in:
parent
77b6475974
commit
f97c4c841a
225
pocs/json_schema/Cargo.lock
generated
Normal file
225
pocs/json_schema/Cargo.lock
generated
Normal file
@ -0,0 +1,225 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.62"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
|
||||
|
||||
[[package]]
|
||||
name = "json_schema"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.132"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.143"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.143"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.9.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f50845f68d5c693aac7d72a25415ddd21cb8182c04eafe447b73af55a05f9e1b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
|
||||
|
||||
[[package]]
|
||||
name = "unsafe-libyaml"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "931179334a56395bcf64ba5e0ff56781381c1a5832178280c7d7f91d1679aeb0"
|
12
pocs/json_schema/Cargo.toml
Normal file
12
pocs/json_schema/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "json_schema"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = { version = "1.0.62", features = ["backtrace"] }
|
||||
serde = { version = "1.0.143", features = ["derive"] }
|
||||
serde_json = "1.0.83"
|
||||
serde_yaml = "0.9.9"
|
12
pocs/json_schema/actions.schema.json
Normal file
12
pocs/json_schema/actions.schema.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string"
|
||||
},
|
||||
"dependsOn": {
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
8
pocs/json_schema/base.schema.json
Normal file
8
pocs/json_schema/base.schema.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
56
pocs/json_schema/ruddle.yaml
Normal file
56
pocs/json_schema/ruddle.yaml
Normal file
@ -0,0 +1,56 @@
|
||||
# yaml-language-server: $schema=schema.json
|
||||
|
||||
version: "some-upstream-repo-for-ruddle@some-api-version"
|
||||
name: "ruddle_base_plan"
|
||||
implicitProvider: git.front.kjuulh.io
|
||||
|
||||
plugins:
|
||||
ruddle/global@latest:
|
||||
file: ruddle.yaml # is default, can be omitted
|
||||
path: org
|
||||
orgSettings:
|
||||
- key: "name"
|
||||
required: true # required is default and can be omitted
|
||||
- key: "squad"
|
||||
required: true
|
||||
- key: "domain"
|
||||
required: false
|
||||
ruddle/vars@latest:
|
||||
path: vars
|
||||
vars:
|
||||
- when: dev
|
||||
vars:
|
||||
SOME_VARIABLE: SOME_VALUE
|
||||
- when: prod
|
||||
vars:
|
||||
SOME_VARIABLE: SOME_OTHER_VALUE
|
||||
|
||||
ruddle/actions@1.0.0:
|
||||
path: actions
|
||||
dependsOn:
|
||||
- ruddle/shell@1.0.0
|
||||
- ruddle/dagger@1.0.0
|
||||
basePath: scripts/
|
||||
scripts:
|
||||
notify_team:
|
||||
description: |
|
||||
will send notification on slack
|
||||
args:
|
||||
- arg: "text"
|
||||
- env: "env"
|
||||
- env: "slack_secret"
|
||||
actions:
|
||||
- shell: "send_notification"
|
||||
build_service:
|
||||
description: |
|
||||
some quite long
|
||||
description
|
||||
args:
|
||||
- arg: "version"
|
||||
actions:
|
||||
- shell: get_cache.sh
|
||||
- dagger: download_dependencies
|
||||
- dagger: build_service
|
||||
- shell: upload_service
|
||||
- ruddle: notify_team
|
||||
|
31
pocs/json_schema/schema.json
Normal file
31
pocs/json_schema/schema.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$defs": {
|
||||
"actions": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"dependsOn": {
|
||||
"type": "array"
|
||||
},
|
||||
"path": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"properties": {
|
||||
"plugins": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"ruddle/actions@1.0.0": {
|
||||
"$ref": "#/$defs/actions"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
45
pocs/json_schema/src/main.rs
Normal file
45
pocs/json_schema/src/main.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
println!("Hello, json_schemas!");
|
||||
|
||||
let mut base_schema: serde_json::Value = load_json("base.schema.json")?;
|
||||
let actions_schema: serde_json::Value = load_json("actions.schema.json")?;
|
||||
|
||||
let mut defs: HashMap<String, serde_json::Value> = HashMap::new();
|
||||
|
||||
defs.insert("actions".to_string(), actions_schema);
|
||||
base_schema["$defs"] = serde_json::to_value(defs)?;
|
||||
|
||||
let mut plugins: HashMap<String, serde_json::Value> = HashMap::new();
|
||||
plugins.insert("ruddle/actions@1.0.0".into(), refs("#/$defs/actions")?);
|
||||
base_schema["properties"]["plugins"]["type"] = serde_json::to_value("object")?;
|
||||
base_schema["properties"]["plugins"]["properties"] = serde_json::to_value(plugins)?;
|
||||
base_schema["properties"]["plugins"]["additionalProperties"] = serde_json::to_value(false)?;
|
||||
|
||||
let schema = std::fs::File::create("schema.json")?;
|
||||
let file_writer = std::io::BufWriter::new(schema);
|
||||
|
||||
serde_json::to_writer(file_writer, &base_schema)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn refs(content: &str) -> anyhow::Result<serde_json::Value> {
|
||||
let mut refs = serde_json::Value::default();
|
||||
refs["$ref"] = serde_json::to_value(content)?;
|
||||
|
||||
Ok(refs)
|
||||
}
|
||||
|
||||
fn load_json(file_name: &str) -> anyhow::Result<serde_json::Value> {
|
||||
let file = std::fs::File::open(file_name)?;
|
||||
let file_reader = std::io::BufReader::new(file);
|
||||
|
||||
let schema: serde_json::Value = serde_json::from_reader(file_reader)?;
|
||||
|
||||
println!("printing schema: {}", file_name);
|
||||
println!("{:#?}", schema);
|
||||
|
||||
Ok(schema)
|
||||
}
|
Loading…
Reference in New Issue
Block a user