Skip to content

Commit

Permalink
feat: add a command to generate the JSON Schema of the library manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorin committed Apr 12, 2023
1 parent 7f65c57 commit 5f88b6f
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 31 deletions.
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ include = [
name = "plantuml-generator"

[dependencies]
chrono = "0.4"
clap_complete = "4.1"
clap = { version = "4.1", features = ["env", "cargo"] }
env_logger = { version = "0.10.0", default_features = false }
glob = "0.3"
heck = "0.4"
chrono = { version = "0.4" }
clap_complete = { version = "4" }
clap = { version = "4", features = ["env", "cargo"] }
env_logger = { version = "0.10", default_features = false }
glob = { version = "0.3" }
heck = { version = "0.4" }
hyper = { version = "0.14", features = ["client", "http1", "libc"] }
image = { version = "0.24" }
log = "0.4"
log = { version = "0.4" }
openssl = { version = "0.10", optional = true }
raster = "0.2"
raster = { version = "0.2" }
reqwest = { version = "0.11", features = ["blocking"] }
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.9"
tera = "1"
serde_json = { version = "1" }
serde_yaml = { version = "0.9" }
schemars = { version = "0.8", features = ["impl_json_schema"] }
tera = { version = "1" }

[features]
# If compiling on a system without OpenSSL installed, or cross-compiling for a different
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plantuml-generator --help
The tool provides two commands:

- `library generate` generates a PlantUML library based on a provided manifest
- `library schema` Generate the JSON Schema of the library manifest
- `diagram generate` generates `.puml` discovered recursively in the file system

## Release
Expand Down
11 changes: 10 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::str::FromStr;
use log::LevelFilter;

use crate::cli::build_cli;
use crate::cmd::execute_completion;
use crate::cmd::execute_diagram_generate;
use crate::cmd::execute_library_generate;
use crate::cmd::{execute_completion, execute_library_schema};

pub fn start_app<I, T>(args: I) -> i32
where
Expand Down Expand Up @@ -53,6 +53,15 @@ where
}
};
}
Some(("schema", m)) => {
return match execute_library_schema(m) {
Ok(_) => 0,
Err(e) => {
log::error!("the command failed: {}", e);
2
}
};
}
_ => {
log::warn!("the SUBCOMMAND is missing");
app.write_help(&mut io::stderr())
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ pub fn build_cli() -> Command {
.arg(&arg_plantuml_jar)
.arg(&arg_java_binary)
.arg(&arg_inkscape_binary),
)
.subcommand(
Command::new("schema").about("Generate the JSON Schema of the library manifest.")
),

)
.subcommand(
Command::new("diagram")
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/diagram/generate/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ impl Config {
.map(|v| v.to_string())
.unwrap_or_else(|| self.cache_directory.clone());

let plantuml_version = match args.get_one::<String>("plantuml_version").map(|v| v.to_string()) {
let plantuml_version = match args
.get_one::<String>("plantuml_version")
.map(|v| v.to_string())
{
None => self.plantuml_version.clone(),
Some(v) => v,
};
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/library/generate/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ impl Config {
.map(|v| v.to_string())
.unwrap_or_else(|| self.cache_directory.clone());

let plantuml_version = match args.get_one::<String>("plantuml_version").map(|v| v.to_string()) {
let plantuml_version = match args
.get_one::<String>("plantuml_version")
.map(|v| v.to_string())
{
None => self.plantuml_version.clone(),
Some(v) => v,
};
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/library/generate/tasks/item/element_snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;

use heck::{ToTitleCase, ToUpperCamelCase};
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use serde_json::Value;
use tera::{Context, Tera};

use crate::cmd::library::generate::config::Config;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/library/generate/tasks/item/item_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs::{read_to_string, File};
use std::path::Path;

use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use serde_json::Value;
use tera::{Context, Tera};

use crate::cmd::library::generate::config::Config;
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/library/manifest/element.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::collections::HashMap;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use serde_json::Value;

use crate::constants::get_default_group_element_stereotype;
use crate::constants::get_default_icon_card_element_stereotype;
use crate::constants::get_default_icon_element_stereotype;
use crate::constants::get_default_icon_group_element_stereotype;
use crate::urn::Urn;

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(tag = "type")]
pub enum Shape {
Icon {
Expand Down Expand Up @@ -102,7 +103,7 @@ impl Shape {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Element {
/// The shape of the element and its related configuration.
pub shape: Shape,
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/library/manifest/example.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use heck::ToSnakeCase;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::urn::Urn;

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Example {
/// The name of the example.
pub name: String,
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/library/manifest/icon.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use heck::ToUpperCamelCase;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::urn::Urn;

#[derive(Serialize, Deserialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(tag = "type")]
pub enum Icon {
Source {
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/library/manifest/item.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::cmd::library::manifest::element::Element;
Expand All @@ -6,14 +7,15 @@ use crate::cmd::library::manifest::item::templates::ItemTemplates;
use crate::urn::Urn;

mod templates {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::constants::{
get_default_template_item_documentation, get_default_template_item_snippet,
get_default_template_item_source,
};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct ItemTemplates {
/// The template used to generate `<library>/<package>/<module>/<Item>.md`.
#[serde(default = "get_default_template_item_documentation")]
Expand All @@ -37,7 +39,7 @@ mod templates {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Item {
/// The URN of the Item.
pub urn: Urn,
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/library/manifest/library.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::cmd::library::manifest::library::customization::Customization;
use crate::cmd::library::manifest::library::templates::LibraryTemplates;
use crate::cmd::library::manifest::package::Package;

pub mod customization {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::constants::get_default_font_color_light;
Expand All @@ -18,7 +20,7 @@ pub mod customization {
use crate::constants::get_default_text_width_max;
use crate::constants::{get_default_font_color, SPRITE_LG, SPRITE_MD, SPRITE_SM, SPRITE_XS};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Customization {
/// The image format used to generate icons.
#[serde(default = "get_default_icon_format")]
Expand Down Expand Up @@ -82,14 +84,15 @@ pub mod customization {
}

mod templates {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::constants::{
get_default_template_library_bootstrap, get_default_template_library_documentation,
get_default_template_library_summary,
};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct LibraryTemplates {
/// The template name used to generate `<library>/bootstrap.puml`. */
#[serde(default = "get_default_template_library_bootstrap")]
Expand All @@ -113,7 +116,7 @@ mod templates {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Library {
/// The name of the library.
pub name: String,
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/library/manifest/module.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::cmd::library::manifest::item::Item;
use crate::cmd::library::manifest::module::templates::ModuleTemplates;
use crate::urn::Urn;

mod templates {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::constants::get_default_template_module_documentation;

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct ModuleTemplates {
/// The template name used to generate `<library>/<package>/<module>/README.md`.
#[serde(default = "get_default_template_module_documentation")]
Expand All @@ -25,7 +27,7 @@ mod templates {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Module {
/// The URN of the module.
pub urn: Urn,
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/library/manifest/package.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::cmd::library::manifest::example::Example;
Expand All @@ -7,14 +8,15 @@ use crate::cmd::library::manifest::package::templates::PackageTemplates;
use crate::urn::Urn;

mod templates {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::constants::{
get_default_template_package_bootstrap, get_default_template_package_documentation,
get_default_template_package_embedded,
};

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct PackageTemplates {
/// The template used to generate `<library>/<package>/bootstrap.puml`.
#[serde(default = "get_default_template_package_bootstrap")]
Expand All @@ -39,17 +41,18 @@ mod templates {
}

mod rendering {
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, JsonSchema)]
pub struct PackageRendering {
/// When true skip the generation of `<library>/<package>/{single,full}.puml`.
#[serde(default)]
pub skip_embedded: bool,
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
pub struct Package {
/// The URN of the package.
pub urn: Urn,
Expand Down
Loading

0 comments on commit 5f88b6f

Please sign in to comment.