Skip to content

Commit

Permalink
✨ Error when unknown key is present (fixes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixr-codes committed May 20, 2024
1 parent f3daebf commit 218853b
Showing 1 changed file with 27 additions and 66 deletions.
93 changes: 27 additions & 66 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ pub type Filter = String;

/// The overall configuration for an Allay project.
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Config {
/// Optional reference to JSON schema.
#[serde(rename = "$schema")]
Expand Down Expand Up @@ -84,12 +81,9 @@ impl Config {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Build {
/// Directories to watch besides from `src` when using the `watch` command.
#[serde(default)]
Expand All @@ -98,12 +92,9 @@ pub struct Build {

/// Metadata of the Allay project.
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Project {
/// The name of the project.
///
Expand Down Expand Up @@ -143,12 +134,9 @@ pub struct Project {
}

#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Localization {
/// The primary language used to the add-ons.
///
Expand All @@ -161,11 +149,8 @@ pub struct Localization {

/// A plugin that transforms the pack.
#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Plugin {
/// An optional name used to identify the plugin.
pub name: Option<String>,
Expand Down Expand Up @@ -219,12 +204,9 @@ fn any(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {

/// Arguements passed to the executable.
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub enum PluginArgs {
/// Passes data as a JSON object to the executable.
///
Expand Down Expand Up @@ -262,24 +244,18 @@ impl Default for PluginArgs {
}

#[derive(Copy, Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub enum BehaviorPackType {
#[default]
Data,
Script,
}

#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct Dependency {
#[serde(flatten)]
pub id: Identifier,
Expand All @@ -289,12 +265,9 @@ pub struct Dependency {
}

#[derive(Clone, Debug, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub enum Identifier {
/// The name of the dependency to use (e.g. `@minecraft/server`).
ModuleName(String),
Expand All @@ -304,12 +277,9 @@ pub enum Identifier {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct BP {
/// Whether to use the `manifest.json` file in the `BP` directory instead of generating one.
#[serde(default)]
Expand Down Expand Up @@ -341,12 +311,9 @@ pub struct BP {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct RP {
/// Whether to use the `manifest.json` file in the `RP` directory instead of generating one.
#[serde(default)]
Expand All @@ -373,12 +340,9 @@ pub struct RP {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct SP {
/// Whether to use the `manifest.json` file in the `SP` directory instead of generating one.
#[serde(default)]
Expand All @@ -405,12 +369,9 @@ pub struct SP {
}

#[derive(Clone, Debug, Default, Deserialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct WT {
/// Whether to use the `manifest.json` file in the `WT` directory instead of generating one.
#[serde(default)]
Expand Down

0 comments on commit 218853b

Please sign in to comment.