Skip to content

Conversation

michaeltlombardi
Copy link
Collaborator

@michaeltlombardi michaeltlombardi commented Oct 9, 2025

PR Summary

This change begins the schema canonicalization process by adding a new library crate to contain the helpers for defining canonical and enhanced schemas ergonomically.

In this initial phase, the new crate defines:

  • The VSCODE_KEYWORDS constant, enumerating the keywords that VS Code's JSON language server recognizes.
  • The idiomaticize_string_enum transformer for munging the generated schemas for string enums with annotation keywords.
  • The idiomaticize_externally_tagged_enum transformer for munging the generated schemas for externally tagged enums to a more idiomatic and readable representation.

This change uses the new idiomaticize_* transformers from the dsc-lib-jsonschema crate in the dsc-lib crate to ensure that the generated schemas are idiomatic.

PR Context

@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/initial-canonicalization branch 4 times, most recently from 567daae to 2d9b276 Compare October 11, 2025 17:28
@michaeltlombardi michaeltlombardi marked this pull request as ready for review October 12, 2025 14:25
@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/initial-canonicalization branch from d3c21ef to 09a7538 Compare October 13, 2025 16:11
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Unit tests for [`dsc-lib-jsonschema::transforms`]
Copy link
Member

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?

Copy link
Collaborator Author

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.


/// Defines an enum where each variant maps to a string value. This enum includes every
/// supported documentation keyword for the enum and each variant.
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to have this in a scope that is #[cfg(test)] so it's conditionally compiled

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the code in lib/dsc-lib-jsonschema/tests is #[cfg(test)] scoped. This folder is only compiled for cargo's integration tests, but I also applied the attribute on every module declaration, e.g.

#[cfg(test)] mod string_variants;

pretty_assertions = { workspace = true }

[lints.clippy]
pedantic ={ level = "deny" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific pedantic rule(s) you are suppressing?

Suggested change
pedantic ={ level = "deny" }
pedantic = { level = "deny" }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is functionally hoisting the deny flag from the CLI to the configuration file. I was trying to get rust analyzer to flag pedantic lints for me without having to separately run clippy.

This change begins the schema canonicalization process by
adding a new library crate to contain the helpers for
defining canonical and enhanced schemas ergonomically.

In this initial phase, the new crate defines:

- The `VSCODE_KEYWORDS` constant, enumerating the keywords
  that VS Code's JSON language server recognizes.
- The `idiomaticize_string_enum` transformer for munging the
  generated schemas for string enums with annotation keywords.
- The `idiomaticize_externally_tagged_enum` transformer for
  munging the generated schemas for externally tagged enums
  to a more idiomatic and readable representation.
This change uses the new `idiomaticize_*` transformers from the
`dsc-lib-jsonschema` crate in the `dsc-lib` crate to ensure that
the generated schemas are idiomatic.
This change updates the i18n Pester tests to account for:

- Usage of the `t!` macro when the translation key is defined on the next line.
- Usage of the convenience `panic_t!` macro, which simplifies sending translated
  strings to the `panic!` macro.
- Usage of the convenience `assert_t!` macro, which simplifies sending translated
  strings to the panic when an `assert!` macro fails.

These use cases were required for the `dsc-lib-jsonschema` crate, which uses both
`panic_t!` and `assert_t!` to raise translated panic messages when a transform is
invalidly applied.

While this change doesn't modify the behavior for any other crates, it does lay the
groundwork for translating panic messages and assertions throughout the crates.
@michaeltlombardi michaeltlombardi force-pushed the gh-538/main/initial-canonicalization branch from 09a7538 to 393d6a2 Compare October 14, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants