-
Notifications
You must be signed in to change notification settings - Fork 52
(GH-538) Add dsc-lib-jsonschema
crate
#1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michaeltlombardi
wants to merge
3
commits into
PowerShell:main
Choose a base branch
from
michaeltlombardi:gh-538/main/initial-canonicalization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "dsc-lib-jsonschema" | ||
version = "0.0.0" # version stays 0.0.0 until we're ready to publish - should pin to dsc-lib. | ||
edition = "2024" | ||
|
||
[lib] | ||
doctest = false # Disable doc tests for compilation speed | ||
|
||
[dependencies] | ||
regex = { workspace = true } | ||
rust-i18n = { workspace = true } | ||
schemars = { workspace = true } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
tracing = { workspace = true } | ||
|
||
[dev-dependencies] | ||
# Helps review complex comparisons, like schemas | ||
pretty_assertions = { workspace = true } | ||
|
||
[lints.clippy] | ||
pedantic = { level = "deny" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
_version = 1 | ||
|
||
[transforms.idiomaticize_externally_tagged_enum] | ||
applies_to = "invalid application of idiomaticize_externally_tagged_enum; missing 'oneOf' keyword in transforming schema: %{transforming_schema}" | ||
oneOf_array = "invalid application of idiomaticize_externally_tagged_enum; 'oneOf' isn't an array in transforming schema: %{transforming_schema}" | ||
oneOf_item_as_object = """ | ||
invalid application of idiomaticize_externally_tagged_enum; items in 'oneOf' should always be objects, but encountered an invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_define_type = """ | ||
invalid application of idiomaticize_externally_tagged_enum; every entry in oneOf should define the 'type' keyword, but encountered an invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_type_string = """ | ||
invalid application of idiomaticize_externally_tagged_enum; the value for the 'type' keyword should be a string, but was invalid in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_not_object_type = """ | ||
invalid application of idiomaticize_externally_tagged_enum; expected type for 'oneOf' entry to be 'object' but was '%{item_data_type}' in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_properties_missing = """ | ||
invalid application of idiomaticize_externally_tagged_enum; expected each item in oneOf to define an object with properties, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_properties_not_object = """ | ||
invalid application of idiomaticize_externally_tagged_enum; the 'properties' keyword should always be an object, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_properties_entry_not_object = """ | ||
invalid application of idiomaticize_externally_tagged_enum; the property '%{name}' in the 'oneOf' item's 'properties' keyword should always be an object, but was something else in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
|
||
[transforms.idiomaticize_string_enum] | ||
applies_to = "invalid application of idiomaticize_string_enum; missing 'oneOf' keyword in transforming schema: %{transforming_schema}" | ||
oneOf_array = "invalid application of idiomaticize_string_enum; 'oneOf' isn't an array in transforming schema: %{transforming_schema}" | ||
oneOf_item_as_object = """ | ||
invalid application of idiomaticize_string_enum; items in 'oneOf' should always be objects, but encountered an invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_define_type = """ | ||
invalid application of idiomaticize_string_enum; every entry in oneOf should define the 'type' keyword, but encountered an invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_type_string = """ | ||
invalid application of idiomaticize_string_enum; the value for the 'type' keyword should be a string, but was invalid in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_not_string_type = """ | ||
invalid application of idiomaticize_string_enum; expected type for 'oneOf' entry to be 'string' but was '%{invalid_type}' in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_enum_not_array = """ | ||
invalid application of idiomaticize_string_enum; the 'enum' keyword should always be an array, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_enum_item_not_string = """ | ||
invalid application of idiomaticize_string_enum; every item in the 'enum' keyword should always be an array of strings, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_const_missing = """ | ||
invalid application of idiomaticize_string_enum; documented items in a string enum are generated as subschemas with the 'const' keyword, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" | ||
oneOf_item_const_not_string = """ | ||
invalid application of idiomaticize_string_enum; the value for the 'const' keyword in a string enum should be a string, but encountered invalid item in transforming schema: | ||
|
||
invalid item: %{invalid_item} | ||
|
||
transforming schema: %{transforming_schema} | ||
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! Helper library for working with DSC and JSON Schemas. | ||
|
||
use rust_i18n::i18n; | ||
|
||
#[macro_use] | ||
pub mod macros; | ||
|
||
pub mod vscode; | ||
pub mod transforms; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
// Enable localization for emitted strings | ||
i18n!("locales", fallback = "en-us"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! Defines macros used by the module. | ||
|
||
/// Panics with a translated message. | ||
macro_rules! panic_t { | ||
($($all:tt)*) => { | ||
panic!("{}", crate::_rust_i18n_t!($($all)*)) | ||
}; | ||
} | ||
|
||
/// Asserts an expression evaluates to true or panics with a translated message. | ||
macro_rules! assert_t { | ||
($expr:expr, $($tail:tt)*) => { | ||
assert!($expr, "{}", crate::_rust_i18n_t!($($tail)*)) | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! Defines unit tests for [`dsc-lib-jsonschema`]. | ||
//! | ||
//! Instead of defining tests in each of the module files for the crate, we | ||
//! define them in this module to improve compilation times. The tests in this | ||
//! module are for internal code. Do not define tests for public items in this | ||
//! module. Instead, define those tests in the `tests/integration` folder, | ||
//! which forces usage of the crate as a public API. | ||
//! | ||
//! When you define tests in this module, ensure that you mirror the structure | ||
//! of the modules from the rest of the source tree. | ||
|
||
#[cfg(test)] mod transforms; | ||
#[cfg(test)] mod vscode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! Unit tests for [`dsc-lib-jsonschema::transforms`] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
//! Unit tests for [`dsc-lib-jsonschema::vscode`] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc examples are run as part of
cargo test
so do we need this placeholder for unittests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not strictly required. The intent here is to add unit tests as they make sense, but these two transforms really only make sense to test at an integration level, which is why I left this file empty.